Skip to content
This repository
Browse code

Make sure at_least(0) passes even when never called

- Fixes #132 again
  • Loading branch information...
commit 73be258aa0a44caa9f387ab6546f47e8db7a364d 1 parent 6b188a8
David Chelimsky authored May 04, 2012
2  lib/rspec/mocks/message_expectation.rb
@@ -87,7 +87,7 @@ def expected_args
87 87
       #   counter.stub(:count) { 1 }
88 88
       #   counter.count # => 1
89 89
       def and_return(*values, &implementation)
90  
-        @expected_received_count = [@expected_received_count, values.size].max unless ignoring_args?
  90
+        @expected_received_count = [@expected_received_count, values.size].max unless ignoring_args? || (@expected_received_count == 0 and @at_least)
91 91
         @consecutive = true if values.size > 1
92 92
         @implementation = implementation || build_implementation(values)
93 93
       end
18  spec/rspec/mocks/at_least_spec.rb
@@ -97,20 +97,32 @@ module Mocks
97 97
         @double.rspec_verify
98 98
       end
99 99
 
100  
-      it "passes with at_least(0) with no return" do
  100
+      it "passes with at_least(0) with no return if called once" do
101 101
         @double.should_receive(:do_something).at_least(0).times
102 102
         @double.do_something
103 103
       end
104 104
 
105  
-      it "passes with at_least(0) with return block" do
  105
+      it "passes with at_least(0) with return block if called once" do
106 106
         @double.should_receive(:do_something).at_least(0).times { true }
107 107
         @double.do_something
108 108
       end
109 109
 
110  
-      it "passes with at_least(0) with and_return" do
  110
+      it "passes with at_least(0) with and_return if called once" do
111 111
         @double.should_receive(:do_something).at_least(0).times.and_return true
112 112
         @double.do_something
113 113
       end
  114
+
  115
+      it "passes with at_least(0) with no return if never called" do
  116
+        @double.should_receive(:do_something).at_least(0).times
  117
+      end
  118
+
  119
+      it "passes with at_least(0) with return block if never called" do
  120
+        @double.should_receive(:do_something).at_least(0).times { true }
  121
+      end
  122
+
  123
+      it "passes with at_least(0) with and_return if never called" do
  124
+        @double.should_receive(:do_something).at_least(0).times.and_return true
  125
+      end
114 126
     end
115 127
   end
116 128
 end

0 notes on commit 73be258

Please sign in to comment.
Something went wrong with that request. Please try again.