Created
March 26, 2012 21:49
-
-
Save tfwright/2210001 to your computer and use it in GitHub Desktop.
Demonstrates unexpected behavior from .any_instance
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/mocks' | |
describe Object do | |
it "should play nicely with dup" do | |
Object.any_instance.stub(:some_method) | |
o = Object.new | |
o.some_method | |
o.dup.some_method | |
end | |
it "should not care how many times a stubbed method is called" do | |
Object.any_instance.stub(:some_method) | |
Object.new.some_method | |
Object.new.some_method | |
end | |
it "should not care if same instance receives multiple calls" do | |
Object.any_instance.stub(:some_method) | |
o = Object.new | |
o.some_method | |
o.some_method | |
end | |
it "should explicitly not care how many times a stubbed method is called" do | |
Object.any_instance.stub(:some_method).any_number_of_times | |
Object.new.some_method | |
pending "doesn't allow second method call" do | |
Object.new.some_method | |
end | |
end | |
it "should allow a method to be called any number of times, at least once" do | |
Object.any_instance.should_receive(:some_method).at_least(:once) | |
Object.new.some_method | |
pending "doesn't allow second method call" do | |
Object.new.some_method | |
end | |
end | |
it "should allow a method to be called twice" do | |
Object.any_instance.should_receive(:some_method).at_least(2).times | |
Object.new.some_method | |
pending "doesn't allow second method call" do | |
Object.new.some_method | |
end | |
end | |
end |
I just ran into this. I didn't dig in far but it seems stub
doesn't allow setting up expectations on the number of times a method is called. should_receive
however does.
open bug is rspec/rspec-mocks#119
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am having these problems right now with rspec 2.10. Are there any open bugs for these issues?