Skip to content

Commit

Permalink
Realised why that reset was unnecessary and fixed it
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiwren committed Mar 23, 2011
1 parent c2487b8 commit 040137b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/rspec/mocks/any_instance.rb
Expand Up @@ -186,6 +186,12 @@ def any_instance
__recorder __recorder
end end


def rspec_verify
super
ensure
rspec_reset
end

def rspec_reset def rspec_reset
__recorder.stop_observing_currently_observed_methods! __recorder.stop_observing_currently_observed_methods!
@__recorder = nil @__recorder = nil
Expand Down
11 changes: 9 additions & 2 deletions spec/rspec/mocks/any_instance_spec.rb
Expand Up @@ -156,7 +156,6 @@ class RSpec::SampleRspecTestClass;end
klass.any_instance.should_receive(:foo) klass.any_instance.should_receive(:foo)
klass.new.rspec_verify klass.new.rspec_verify
end.to raise_error(RSpec::Mocks::MockExpectationError) end.to raise_error(RSpec::Mocks::MockExpectationError)
klass.rspec_reset
end end


it "does nothing if no instance is created" do it "does nothing if no instance is created" do
Expand All @@ -176,14 +175,22 @@ class RSpec::SampleRspecTestClass;end
instance = klass.new instance = klass.new
instance.rspec_verify instance.rspec_verify
end.to raise_error(RSpec::Mocks::MockExpectationError) end.to raise_error(RSpec::Mocks::MockExpectationError)
klass.rspec_reset
end end


it "does nothing if no instance is created" do it "does nothing if no instance is created" do
klass.any_instance.should_receive(:ooga).and_return(1) klass.any_instance.should_receive(:ooga).and_return(1)
end end
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 "message count" do
context "the 'once' constraint" do context "the 'once' constraint" do
it "passes for one invocation" do it "passes for one invocation" do
Expand Down

0 comments on commit 040137b

Please sign in to comment.