Skip to content

Commit

Permalink
Output deprecation warning when at_least(0) is sent
Browse files Browse the repository at this point in the history
  • Loading branch information
Michi Huber committed Feb 26, 2013
1 parent e652a02 commit 21b299a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
6 changes: 6 additions & 0 deletions lib/rspec/mocks/message_expectation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 29 additions & 25 deletions spec/rspec/mocks/at_least_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 21b299a

Please sign in to comment.