Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #110 from c42engineering/issue-103

should_receive(:x).at_least_once clears any stubs on :x

- Fixes #103
  • Loading branch information...
commit 6e23ca9fb663e654cc9fc900833b6eb06fcce51b 2 parents 117f2cb + 251bf2a
@dchelimsky dchelimsky authored
View
4 lib/rspec/mocks/message_expectation.rb
@@ -54,6 +54,10 @@ def expected_args
@argument_expectation.args
end
+ def at_least_once?
+ @at_least && @expected_received_count == 1
+ end
+
# @overload and_return(value)
# @overload and_return(first_value, second_value)
# @overload and_return(&block)
View
3  lib/rspec/mocks/proxy.rb
@@ -114,6 +114,9 @@ def record_message_received(message, *args, &block)
def message_received(message, *args, &block)
expectation = find_matching_expectation(message, *args)
stub = find_matching_method_stub(message, *args)
+ if stub && expectation && expectation.at_least_once?
+ method_double[message].stubs.delete(stub)
+ end
if (stub && expectation && expectation.called_max_times?) || (stub && !expectation)
expectation.increase_actual_received_count! if expectation && expectation.actual_received_count_matters?
View
9 spec/rspec/mocks/stubbed_message_expectations_spec.rb
@@ -43,5 +43,14 @@
double.foo(3)
expect { double.rspec_verify }.to raise_error(/expected: \(4\)\s+got: \(3\)/)
end
+
+ it "passes when at least once method is called more than once " do
+ double = double("mock")
+ double.stub(:random_call).with(1).and_return("stub")
+ double.should_receive(:random_call).with(1).at_least(:once).and_return("expectation")
+ double.random_call(1).should eq("expectation")
+ double.random_call(1).should eq("expectation")
+ double.rspec_verify
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.