should receiving stubbed atleast_once removes matching stub(Issue 103) #110

Merged
merged 2 commits into from Feb 24, 2012
@@ -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)
@@ -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?
@@ -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