Class: InvokeMatcher::Matcher
- Inherits:
-
Object
- Object
- InvokeMatcher::Matcher
show all
- Extended by:
- Forwardable
- Includes:
- RSpec::Matchers::Composable, RSpec::Mocks::ExampleMethods
- Defined in:
- lib/invoke_matcher.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(expected_method) ⇒ Matcher
Returns a new instance of Matcher.
16
17
18
19
|
# File 'lib/invoke_matcher.rb', line 16
def initialize(expected_method)
@expected_method = expected_method
@have_received_matcher = RSpec::Mocks::Matchers::HaveReceived.new(expected_method)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
61
62
63
64
65
66
67
|
# File 'lib/invoke_matcher.rb', line 61
def method_missing(name, ...)
ensure_recipient_is_defined!
return super unless have_received_matcher.respond_to?(name)
@have_received_matcher = have_received_matcher.public_send(name, ...)
self
end
|
Instance Attribute Details
#expected_method ⇒ Object
Returns the value of attribute expected_method.
14
15
16
|
# File 'lib/invoke_matcher.rb', line 14
def expected_method
@expected_method
end
|
#expected_recipient ⇒ Object
Returns the value of attribute expected_recipient.
14
15
16
|
# File 'lib/invoke_matcher.rb', line 14
def expected_recipient
@expected_recipient
end
|
#have_received_matcher ⇒ Object
Returns the value of attribute have_received_matcher.
14
15
16
|
# File 'lib/invoke_matcher.rb', line 14
def have_received_matcher
@have_received_matcher
end
|
Instance Method Details
#and_call_original ⇒ Object
51
52
53
54
|
# File 'lib/invoke_matcher.rb', line 51
def and_call_original
@call_original = true
self
end
|
#and_expect_return(expected_value) ⇒ Object
56
57
58
59
|
# File 'lib/invoke_matcher.rb', line 56
def and_expect_return(expected_value)
@expected_return = expected_value
self
end
|
#description ⇒ Object
21
22
23
|
# File 'lib/invoke_matcher.rb', line 21
def description
"invoke #{expected_method} on #{expected_recipient.inspect}"
end
|
#does_not_match?(event_proc) ⇒ Boolean
34
35
36
37
38
39
|
# File 'lib/invoke_matcher.rb', line 34
def does_not_match?(event_proc)
ensure_recipient_is_defined!
set_method_expectation
event_proc.call
have_received_matcher.does_not_match?(expected_recipient)
end
|
#matches?(event_proc) ⇒ Boolean
25
26
27
28
29
30
31
32
|
# File 'lib/invoke_matcher.rb', line 25
def matches?(event_proc)
ensure_recipient_is_defined!
set_method_expectation
setup_return_value_check if defined?(@expected_return)
event_proc.call
have_received_matcher.matches?(expected_recipient)
end
|
#on(expected_recipient) ⇒ Object
41
42
43
44
|
# File 'lib/invoke_matcher.rb', line 41
def on(expected_recipient)
@expected_recipient = expected_recipient
self
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
69
70
71
|
# File 'lib/invoke_matcher.rb', line 69
def respond_to_missing?(name, include_private = false)
have_received_matcher.respond_to?(name, include_private)
end
|
#supports_block_expectations? ⇒ Boolean
73
74
75
|
# File 'lib/invoke_matcher.rb', line 73
def supports_block_expectations?
true
end
|
#with(*args, **kwargs) ⇒ Object
46
47
48
49
|
# File 'lib/invoke_matcher.rb', line 46
def with(*args, **kwargs)
have_received_matcher.with(*args, **kwargs)
self
end
|