Permalink
Browse files

Clear messages received when mocks reset

* Proxy objects for class methods/global objects persist between test runs

Fixes #248.
  • Loading branch information...
1 parent 0c08d6e commit 3cb4ccc79dfdc6523ffc3f70d767a908153c7b55 @jferris jferris committed Mar 27, 2013
Showing with 13 additions and 0 deletions.
  1. +1 −0 lib/rspec/mocks/proxy.rb
  2. +12 −0 spec/rspec/mocks/have_received_spec.rb
@@ -124,6 +124,7 @@ def verify
# @private
def reset
method_doubles.each {|d| d.reset}
+ @messages_received.clear
end
# @private
@@ -48,6 +48,18 @@ module Mocks
}.to raise_error(/method has been mocked instead of stubbed/)
end
+ it 'resets expectations on class methods when mocks are reset' do
+ dbl = Object
+ dbl.stub(:expected_method)
+ dbl.expected_method
+ dbl.__send__(:__mock_proxy).reset
+ dbl.stub(:expected_method)
+
+ expect {
+ expect(dbl).to have_received(:expected_method)
+ }.to raise_error(/0 times/)
+ end
+
context "with" do
it 'passes when the given args match the args used with the message' do
dbl = double_with_met_expectation(:expected_method, :expected, :args)

0 comments on commit 3cb4ccc

Please sign in to comment.