Module: Crspec::Mock::DSL
Instance Method Summary
collapse
#an_instance_of, #anything, args_match?, #array_including, #duck_type, #hash_excluding, #hash_including, #kind_of, kwargs_match?
Instance Method Details
#allow(target) ⇒ Object
486
487
488
|
# File 'lib/crspec/mock/double.rb', line 486
def allow(target)
AllowTarget.new(target)
end
|
#allow_any_instance_of(_klass) ⇒ Object
506
507
508
509
510
511
512
513
|
# File 'lib/crspec/mock/double.rb', line 506
def allow_any_instance_of(_klass)
raise Crspec::MigrationError, <<~MSG
allow_any_instance_of is not supported by Crspec: it mutates shared
class hierarchies at runtime, which is unsafe under concurrent
threads/fibers. Inject a double or stub the specific instance.
Run `crspec-transpile --analyze` to find all occurrences.
MSG
end
|
#double(name = nil, stubs = {}) ⇒ Object
465
466
467
|
# File 'lib/crspec/mock/double.rb', line 465
def double(name = nil, stubs = {})
Double.new(name, stubs)
end
|
#expect_any_instance_of(_klass) ⇒ Object
515
516
517
518
519
520
521
522
|
# File 'lib/crspec/mock/double.rb', line 515
def expect_any_instance_of(_klass)
raise Crspec::MigrationError, <<~MSG
expect_any_instance_of is not supported by Crspec: it mutates shared
class hierarchies at runtime, which is unsafe under concurrent
threads/fibers. Inject a double or stub the specific instance.
Run `crspec-transpile --analyze` to find all occurrences.
MSG
end
|
#have_received(method_name) ⇒ Object
502
503
504
|
# File 'lib/crspec/mock/double.rb', line 502
def have_received(method_name)
HaveReceivedMatcher.new(method_name)
end
|
#instance_double(target_class, name = nil, stubs = {}) ⇒ Object
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
|
# File 'lib/crspec/mock/double.rb', line 469
def instance_double(target_class, name = nil, stubs = {})
if name.is_a?(Hash) && stubs.empty?
stubs = name
name = nil
end
resolved = if target_class.is_a?(String) || target_class.is_a?(Symbol)
begin
Object.const_get(target_class.to_s)
rescue NameError
target_class.to_s
end
else
target_class
end
InstanceDouble.new(resolved, name, stubs)
end
|
#receive(method_name) ⇒ Object
490
491
492
|
# File 'lib/crspec/mock/double.rb', line 490
def receive(method_name)
ReceiveMatcher.new(method_name)
end
|
#receive_messages(messages) ⇒ Object
494
495
496
|
# File 'lib/crspec/mock/double.rb', line 494
def receive_messages(messages)
ReceiveMessagesMatcher.new(messages)
end
|
#spy(name = nil, stubs = {}) ⇒ Object
498
499
500
|
# File 'lib/crspec/mock/double.rb', line 498
def spy(name = nil, stubs = {})
Spy.new(name || "Spy", stubs)
end
|