Permalink
Browse files

Make sure at_least(0) passes even when never called

- Fixes #132 again
  • Loading branch information...
1 parent 6b188a8 commit 73be258aa0a44caa9f387ab6546f47e8db7a364d @dchelimsky dchelimsky committed May 4, 2012
Showing with 16 additions and 4 deletions.
  1. +1 −1 lib/rspec/mocks/message_expectation.rb
  2. +15 −3 spec/rspec/mocks/at_least_spec.rb
@@ -87,7 +87,7 @@ def expected_args
# counter.stub(:count) { 1 }
# counter.count # => 1
def and_return(*values, &implementation)
- @expected_received_count = [@expected_received_count, values.size].max unless ignoring_args?
+ @expected_received_count = [@expected_received_count, values.size].max unless ignoring_args? || (@expected_received_count == 0 and @at_least)
@consecutive = true if values.size > 1
@implementation = implementation || build_implementation(values)
end
@@ -97,20 +97,32 @@ module Mocks
@double.rspec_verify
end
- it "passes with at_least(0) with no return" do
+ 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" do
+ 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" do
+ 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
end
end

0 comments on commit 73be258

Please sign in to comment.