Skip to content


Subversion checkout URL

You can clone with
Download ZIP


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

merged 2 commits into from

2 participants


No description provided.


@dchelimsky I would love to do some work on any feature requests or other stuff that you may have in the pipeline. Having worked on a couple of bugs I feel familiar enough with the rspec-mocks code to try my hand at it. I did follow your earlier suggestion of picking up bugs but am running out of them and have now moved to rspec-core/ rspec-expectations :)


After merging this I see the following warnings:

An expectation of :random_call was set on nil. Called from /Users/david/projects/ruby/rspec2/repos/rspec-mocks/spec/rspec/mocks/stubbed_message_expectations_spec.rb:48:in `block (3 levels) in <top (required)>'. Use allow_message_expectations_on_nil to disable warnings.
An expectation of :random_call was set on nil. Called from /Users/david/projects/ruby/rspec2/repos/rspec-mocks/spec/rspec/mocks/stubbed_message_expectations_spec.rb:49:in `block (3 levels) in <top (required)>'. Use allow_message_expectations_on_nil to disable warnings.

Please fix and I'll look again.


commit 251bf2a should fix this

@dchelimsky dchelimsky merged commit 6e23ca9 into rspec:master
@dchelimsky dchelimsky referenced this pull request from a commit
@dchelimsky dchelimsky Revert "Merge pull request #110 from c42engineering/issue-103"
Turns out this change is significantly backward-incompatible that we're
going to have to wait for rspec-mocks-3 to release it (or similar)

This reverts commit 6e23ca9, reversing
changes made to 117f2cb.

After merging this I explored it a bit more and realize that this is more of a breaking change than is appropriate for a 2.x release. Going to have to wait for 3.0 if we do it at all.


Note that github offers me no option to re-open this :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 20, 2012
  1. @preethiramdev
Commits on Feb 24, 2012
  1. @preethiramdev
This page is out of date. Refresh to see the latest.
4 lib/rspec/mocks/message_expectation.rb
@@ -54,6 +54,10 @@ def expected_args
+ 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)
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?
9 spec/rspec/mocks/stubbed_message_expectations_spec.rb
@@ -43,5 +43,14 @@
expect { double.rspec_verify }.to raise_error(/expected: \(4\)\s+got: \(3\)/)
+ 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
Something went wrong with that request. Please try again.