Class Spec::Mocks::MessageExpectation
In: lib/spec/mocks/message_expectation.rb
Parent: BaseExpectation

Methods

Public Instance methods

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 199
199:       def any_number_of_times(&block)
200:         @method_block = block if block
201:         @expected_received_count = :any
202:         self
203:       end

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 184
184:       def at_least(n)
185:         set_expected_received_count :at_least, n
186:         self
187:       end

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 189
189:       def at_most(n)
190:         set_expected_received_count :at_most, n
191:         self
192:       end

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 179
179:       def exactly(n)
180:         set_expected_received_count :exactly, n
181:         self
182:       end

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 169
169:       def generate_error
170:         @error_generator.raise_expectation_error(@sym, @expected_received_count, @actual_received_count, *@args_expectation.args)
171:       end

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 153
153:       def ignoring_args?
154:         @expected_received_count == :any
155:       end

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 157
157:       def matches_at_least_count?
158:         @at_least && @actual_received_count >= @expected_received_count
159:       end

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 161
161:       def matches_at_most_count?
162:         @at_most && @actual_received_count <= @expected_received_count
163:       end

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 165
165:       def matches_exact_count?
166:         @expected_received_count == @actual_received_count
167:       end

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 139
139:       def matches_name_but_not_args(sym, args)
140:         @sym == sym and not @args_expectation.check_args(args)
141:       end

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 229
229:       def negative_expectation_for?(sym)
230:         return false
231:       end

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 205
205:       def never
206:         @expected_received_count = 0
207:         self
208:       end

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 210
210:       def once(&block)
211:         @method_block = block if block
212:         @expected_received_count = 1
213:         self
214:       end

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 222
222:       def ordered(&block)
223:         @method_block = block if block
224:         @order_group.register(self)
225:         @ordered = true
226:         self
227:       end

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 194
194:       def times(&block)
195:         @method_block = block if block
196:         self
197:       end

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 216
216:       def twice(&block)
217:         @method_block = block if block
218:         @expected_received_count = 2
219:         self
220:       end

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 143
143:       def verify_messages_received        
144:         return if ignoring_args? || matches_exact_count? ||
145:            matches_at_least_count? || matches_at_most_count?
146:     
147:         generate_error
148:       rescue Spec::Mocks::MockExpectationError => error
149:         error.backtrace.insert(0, @expected_from)
150:         Kernel::raise error
151:       end

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 173
173:       def with(*args, &block)
174:         @method_block = block if block
175:         @args_expectation = ArgumentExpectation.new(args)
176:         self
177:       end

Protected Instance methods

[Source]

     # File lib/spec/mocks/message_expectation.rb, line 234
234:         def set_expected_received_count(relativity, n)
235:           @at_least = (relativity == :at_least)
236:           @at_most = (relativity == :at_most)
237:           @expected_received_count = case n
238:             when Numeric
239:               n
240:             when :once
241:               1
242:             when :twice
243:               2
244:           end
245:         end

[Validate]