diff --git a/lib/rspec/mocks/message_expectation.rb b/lib/rspec/mocks/message_expectation.rb index 01ce7b846..3103d3988 100644 --- a/lib/rspec/mocks/message_expectation.rb +++ b/lib/rspec/mocks/message_expectation.rb @@ -302,6 +302,12 @@ def exactly(n, &block) # # dealer.should_receive(:deal_card).at_least(9).times def at_least(n, &block) + if n == 0 + RSpec::Mocks.warn_deprecation <<-MSG +DEPRECATION: at_least(0) is deprecated. Use #stub instead of #should_receive. Called from #{caller(0)[1]} +MSG + end + @implementation = block if block set_expected_received_count :at_least, n self diff --git a/spec/rspec/mocks/at_least_spec.rb b/spec/rspec/mocks/at_least_spec.rb index 4e5472375..173548f06 100644 --- a/spec/rspec/mocks/at_least_spec.rb +++ b/spec/rspec/mocks/at_least_spec.rb @@ -97,31 +97,35 @@ module Mocks @double.rspec_verify end - it "passes with at_least(0) with no return if called once" do - @double.should_receive(:do_something).at_least(0).times - @double.do_something - end - - it "passes with at_least(0) with return block if called once" do - @double.should_receive(:do_something).at_least(0).times { true } - @double.do_something - end - - it "passes with at_least(0) with and_return if called once" do - @double.should_receive(:do_something).at_least(0).times.and_return true - @double.do_something - end - - it "passes with at_least(0) with no return if never called" do - @double.should_receive(:do_something).at_least(0).times - end - - it "passes with at_least(0) with return block if never called" do - @double.should_receive(:do_something).at_least(0).times { true } - end - - it "passes with at_least(0) with and_return if never called" do - @double.should_receive(:do_something).at_least(0).times.and_return true + context "when sent with 0" do + before { RSpec::Mocks.should_receive(:warn_deprecation) } + + it "passes with at_least(0) with no return if called once" do + @double.should_receive(:do_something).at_least(0).times + @double.do_something + end + + it "passes with at_least(0) with return block if called once" do + @double.should_receive(:do_something).at_least(0).times { true } + @double.do_something + end + + it "passes with at_least(0) with and_return if called once" do + @double.should_receive(:do_something).at_least(0).times.and_return true + @double.do_something + end + + it "passes with at_least(0) with no return if never called" do + @double.should_receive(:do_something).at_least(0).times + end + + it "passes with at_least(0) with return block if never called" do + @double.should_receive(:do_something).at_least(0).times { true } + end + + it "passes with at_least(0) with and_return if never called" do + @double.should_receive(:do_something).at_least(0).times.and_return true + end end it "uses a stub value if no value set" do