Permalink
Browse files

Realised why that reset was unnecessary and fixed it

  • Loading branch information...
1 parent c2487b8 commit 040137be9ed062f4321ce092298636a1d6c5da65 @kaiwren kaiwren committed Mar 23, 2011
Showing with 15 additions and 2 deletions.
  1. +6 −0 lib/rspec/mocks/any_instance.rb
  2. +9 −2 spec/rspec/mocks/any_instance_spec.rb
View
6 lib/rspec/mocks/any_instance.rb
@@ -186,6 +186,12 @@ def any_instance
__recorder
end
+ def rspec_verify
+ super
+ ensure
+ rspec_reset
+ end
+
def rspec_reset
__recorder.stop_observing_currently_observed_methods!
@__recorder = nil
View
11 spec/rspec/mocks/any_instance_spec.rb
@@ -156,7 +156,6 @@ class RSpec::SampleRspecTestClass;end
klass.any_instance.should_receive(:foo)
klass.new.rspec_verify
end.to raise_error(RSpec::Mocks::MockExpectationError)
- klass.rspec_reset
end
it "does nothing if no instance is created" do
@@ -176,14 +175,22 @@ class RSpec::SampleRspecTestClass;end
instance = klass.new
instance.rspec_verify
end.to raise_error(RSpec::Mocks::MockExpectationError)
- klass.rspec_reset
end
it "does nothing if no instance is created" do
klass.any_instance.should_receive(:ooga).and_return(1)
end
end
+ context "resetting" do
+ it "does not interfere with expectations set on the class" do
+ expect do
+ klass.should_receive(:woot).and_return(3)
+ klass.rspec_verify
+ end.to raise_error(RSpec::Mocks::MockExpectationError)
+ end
+ end
+
context "message count" do
context "the 'once' constraint" do
it "passes for one invocation" do

0 comments on commit 040137b

Please sign in to comment.