Class: Surrogate::RSpec::InvocationMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/surrogate/rspec/invocation_matcher.rb

Direct Known Subclasses

NounMatcher, PredicateMatcher, VerbMatcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name) ⇒ InvocationMatcher

Returns a new instance of InvocationMatcher.



10
11
12
13
14
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 10

def initialize(method_name)
  self.method_name     = method_name
  self.times_predicate = TimesPredicate.new
  self.with_filter     = WithFilter.new
end

Instance Attribute Details

#method_nameObject

Returns the value of attribute method_name.



8
9
10
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 8

def method_name
  @method_name
end

#surrogateObject

Returns the value of attribute surrogate.



8
9
10
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 8

def surrogate
  @surrogate
end

#times_predicateObject

Returns the value of attribute times_predicate.



8
9
10
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 8

def times_predicate
  @times_predicate
end

#with_filterObject

Returns the value of attribute with_filter.



8
9
10
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 8

def with_filter
  @with_filter
end

Instance Method Details

#failure_message_for_shouldObject



29
30
31
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 29

def failure_message_for_should
  raise "THIS METHOD SHOULD HAVE BEEN OVERRIDDEN"
end

#failure_message_for_should_notObject



33
34
35
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 33

def failure_message_for_should_not
  raise "THIS METHOD SHOULD HAVE BEEN OVERRIDDEN"
end

#filtered_argsObject



21
22
23
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 21

def filtered_args
  @filtered_args ||= with_filter.filter invocations
end

#invocationsObject



25
26
27
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 25

def invocations
  surrogate.invocations(method_name)
end

#matches?(surrogate) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 16

def matches?(surrogate)
  self.surrogate = surrogate
  times_predicate.matches? filtered_args
end

#message_for(failure_class_name) ⇒ Object



76
77
78
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 76

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



37
38
39
40
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 37

def times(times_invoked)
  @times_predicate = TimesPredicate.new(times_invoked, :==)
  self
end

#with(*arguments, &expectation_block) ⇒ Object



42
43
44
45
46
# File 'lib/surrogate/rspec/invocation_matcher.rb', line 42

def with(*arguments, &expectation_block)
  self.with_filter = WithFilter.new arguments, :args_must_match,  &expectation_block
  arguments << expectation_block if expectation_block
  self
end