Class: Surrogate::RSpec::InvocationMatcher
- Inherits:
-
Object
- Object
- Surrogate::RSpec::InvocationMatcher
show all
- Defined in:
- lib/surrogate/rspec/invocation_matcher.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of InvocationMatcher.
11
12
13
14
15
|
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 11
def initialize(method_name)
self.method_name = method_name.to_sym
self.times_predicate = TimesPredicate.new
self.with_filter = WithFilter.new
end
|
Instance Attribute Details
#method_name ⇒ Object
Returns the value of attribute method_name
9
10
11
|
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 9
def method_name
@method_name
end
|
#surrogate ⇒ Object
Returns the value of attribute surrogate
9
10
11
|
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 9
def surrogate
@surrogate
end
|
#times_predicate ⇒ Object
Returns the value of attribute times_predicate
9
10
11
|
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 9
def times_predicate
@times_predicate
end
|
#with_filter ⇒ Object
Returns the value of attribute with_filter
9
10
11
|
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 9
def with_filter
@with_filter
end
|
Instance Method Details
#failure_message ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 41
def failure_message
message_for(
if times_predicate.default? && with_filter.default?
:FailureMessageShouldDefault
elsif times_predicate.default?
:FailureMessageShouldWith
elsif with_filter.default?
:FailureMessageShouldTimes
else
:FailureMessageWithTimes
end
)
end
|
#failure_message_when_negated ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 55
def failure_message_when_negated
message_for(
if times_predicate.default? && with_filter.default?
:FailureMessageShouldNotDefault
elsif times_predicate.default?
:FailureMessageShouldNotWith
elsif with_filter.default?
:FailureMessageShouldNotTimes
else
:FailureMessageShouldNotWithTimes
end
)
end
|
#filtered_args ⇒ Object
22
23
24
|
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 22
def filtered_args
@filtered_args ||= with_filter.filter invocations
end
|
#matches?(surrogate) ⇒ Boolean
17
18
19
20
|
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 17
def matches?(surrogate)
self.surrogate = surrogate
times_predicate.matches? filtered_args
end
|
#message_for(failure_class_name) ⇒ Object
69
70
71
|
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 69
def message_for(failure_class_name)
self.class.const_get(failure_class_name).new(method_name, invocations, with_filter, times_predicate).get_message
end
|
#times(times_invoked) ⇒ Object
30
31
32
33
|
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 30
def times(times_invoked)
@times_predicate = TimesPredicate.new(times_invoked, :==)
self
end
|
#with(*arguments, &expectation_block) ⇒ Object
35
36
37
38
39
|
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 35
def with(*arguments, &expectation_block)
self.with_filter = WithFilter.new arguments, :args_must_match, &expectation_block
arguments << expectation_block if expectation_block
self
end
|