Class: Crspec::Mock::ReceiveMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/crspec/mock/double.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name) ⇒ ReceiveMatcher

Returns a new instance of ReceiveMatcher.



237
238
239
240
241
242
243
244
245
246
# File 'lib/crspec/mock/double.rb', line 237

def initialize(method_name)
  @method_name = method_name.to_sym
  @expected_args = nil
  @expected_kwargs = nil
  @return_values = nil
  @raise_exception = nil
  @yield_args = nil
  @expected_count = 1
  @count_constraint = :exact
end

Instance Attribute Details

#method_nameObject (readonly)

Returns the value of attribute method_name.



235
236
237
# File 'lib/crspec/mock/double.rb', line 235

def method_name
  @method_name
end

Instance Method Details

#and_call_originalObject



270
271
272
273
# File 'lib/crspec/mock/double.rb', line 270

def and_call_original
  @call_original = true
  self
end

#and_raise(exception = StandardError, message = nil) ⇒ Object



259
260
261
262
263
# File 'lib/crspec/mock/double.rb', line 259

def and_raise(exception = StandardError, message = nil)
  @raise_exception = exception
  @raise_message = message
  self
end

#and_return(*values) ⇒ Object



254
255
256
257
# File 'lib/crspec/mock/double.rb', line 254

def and_return(*values)
  @return_values = values
  self
end

#and_yield(*args) ⇒ Object



265
266
267
268
# File 'lib/crspec/mock/double.rb', line 265

def and_yield(*args)
  @yield_args = args
  self
end

#at_least(n) ⇒ Object



293
294
295
296
297
# File 'lib/crspec/mock/double.rb', line 293

def at_least(n)
  @expected_count = n
  @count_constraint = :at_least
  self
end

#exactly(n) ⇒ Object



287
288
289
290
291
# File 'lib/crspec/mock/double.rb', line 287

def exactly(n)
  @expected_count = n
  @count_constraint = :exact
  self
end

#onceObject



275
276
277
278
279
# File 'lib/crspec/mock/double.rb', line 275

def once
  @expected_count = 1
  @count_constraint = :exact
  self
end

#setup_allow(target) ⇒ Object



299
300
301
302
303
# File 'lib/crspec/mock/double.rb', line 299

def setup_allow(target)
  chain = StubChain.new(target, @method_name)
  apply_chain_options(chain)
  chain
end

#setup_expect(target) ⇒ Object



305
306
307
308
309
310
311
# File 'lib/crspec/mock/double.rb', line 305

def setup_expect(target)
  chain = ExpectationChain.new(target, @method_name)
  chain.instance_variable_set(:@expected_count, @expected_count)
  chain.instance_variable_set(:@count_constraint, @count_constraint)
  apply_chain_options(chain)
  chain
end

#twiceObject



281
282
283
284
285
# File 'lib/crspec/mock/double.rb', line 281

def twice
  @expected_count = 2
  @count_constraint = :exact
  self
end

#with(*args, **kwargs) ⇒ Object



248
249
250
251
252
# File 'lib/crspec/mock/double.rb', line 248

def with(*args, **kwargs)
  @expected_args = args
  @expected_kwargs = kwargs
  self
end