Skip to content

Instantly share code, notes, and snippets.

@devpuppy
Created November 26, 2012 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devpuppy/4149575 to your computer and use it in GitHub Desktop.
Save devpuppy/4149575 to your computer and use it in GitHub Desktop.
How to stub user.trebuchet to always return true for any feature
# as a one-liner to use in an rspec example
@user.stub(:trebuchet).and_return(double(@user.trebuchet, :launch? => true))
# more verbose example
it "should stub user.trebuchet" do
@user = Factory(:user)
@user.trebuchet.launch?("something ridiculous").should be_false
enthusiastic_trebuchet = double(@user.trebuchet, :launch? => true)
@user.stub(:trebuchet).and_return(enthusiastic_trebuchet)
@user.trebuchet.launch?("something ridiculous").should be_true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment