Created
November 26, 2012 17:40
-
-
Save devpuppy/4149575 to your computer and use it in GitHub Desktop.
How to stub user.trebuchet to always return true for any feature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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