Class: Templater::Spec::Helpers::InvokeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/templater/spec/helpers.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ InvokeMatcher

Returns a new instance of InvokeMatcher.



6
7
8
# File 'lib/templater/spec/helpers.rb', line 6

def initialize(expected)
  @expected = expected
end

Instance Method Details

#failure_messageObject



28
29
30
# File 'lib/templater/spec/helpers.rb', line 28

def failure_message
  "expected #{@actual.inspect} to invoke #{@expected.inspect} with #{@with}, but it didn't"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/templater/spec/helpers.rb', line 10

def matches?(actual)
  @actual = actual
  # Satisfy expectation here. Return false or raise an error if it's not met.
  found = nil
  @actual.invocations.each { |i| found = i if i.class == @expected }

  if @with
    return found && (@with == found.arguments)
  else
    return found
  end
end

#negative_failure_messageObject



32
33
34
# File 'lib/templater/spec/helpers.rb', line 32

def negative_failure_message
  "expected #{@actual.inspect} not to invoke #{@expected.inspect} with #{@with}, but it did"
end

#with(*arguments) ⇒ Object



23
24
25
26
# File 'lib/templater/spec/helpers.rb', line 23

def with(*arguments)
  @with = arguments
  return self
end