Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

should receiving stubbed atleast_once removes matching stub

  • Loading branch information...
commit 235c8cc37c1994500de4f5503935d7ea4199f8d2 1 parent 117f2cb
@preethiramdev preethiramdev 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
8 spec/rspec/mocks/stubbed_message_expectations_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.