Permalink
Browse files

should receiving stubbed atleast_once removes matching stub

  • Loading branch information...
1 parent 117f2cb commit 235c8cc37c1994500de4f5503935d7ea4199f8d2 @preethiramdev preethiramdev committed Feb 20, 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,13 @@
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
+ @mock.stub(:random_call).with(1).and_return("stub")
+ @mock.should_receive(:random_call).with(1).at_least(:once).and_return("expectation")
+ @mock.random_call(1).should eq("expectation")
+ @mock.random_call(1).should eq("expectation")
+ @mock.rspec_verify
+ end
end
end

0 comments on commit 235c8cc

Please sign in to comment.