Created
April 20, 2012 16:07
-
-
Save jsl/2429938 to your computer and use it in GitHub Desktop.
Rspec test
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
require 'rspec' | |
module Dog | |
def self.bark | |
"Woof!" | |
end | |
end | |
describe "Rspec re-setting stubs on classes" do | |
it "should return 'Woof!'" do | |
Dog.bark.should == 'Woof!' | |
end | |
it "should return a stubbed value" do | |
Dog.stub(:bark).and_return('Bow wow') | |
Dog.bark.should == 'Bow wow' | |
end | |
it "should not reset the stub since it's not something that will be re-loaded between examples" do | |
Dog.bark.should == 'Woof!' | |
end | |
end |
Here is a test for this behavior in rspec:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works, because the examples clear the stubs by resetting the
stubs
Array which is injected into the stubbed or mocked class at the end of the example.