Class: Stirlitz::Matchers::HaveReceived

Inherits:
Object
  • Object
show all
Defined in:
lib/stirlitz/matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ HaveReceived

Returns a new instance of HaveReceived.



21
22
23
# File 'lib/stirlitz/matchers.rb', line 21

def initialize(expected)
  @expected = expected
end

Instance Method Details

#failure_message_for_shouldObject



39
40
41
42
43
44
45
# File 'lib/stirlitz/matchers.rb', line 39

def failure_message_for_should
  if @args
    "#{@expected} should have been called on #{@actual.inspect} with #{@args.inspect}, but #{@actual.received_message?(@expected) ? ' was called with other arguments' : 'wasn\'t'}"
  else
    "#{@expected} should have been called on #{@actual.inspect}. but wasn't"
  end
end

#failure_message_for_should_notObject



47
48
49
50
51
52
53
54
# File 'lib/stirlitz/matchers.rb', line 47

def failure_message_for_should_not
  if @args
    "#{@expected} should not have been called on #{@actual.inspect} with #{@args.inspect}, but was"
  else
    "#{@expected} should not have been called on #{@actual.inspect}. but was"
  end
  "#{@expected} should not have been called on #{@actual.inspect}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
# File 'lib/stirlitz/matchers.rb', line 25

def matches?(actual)
  @actual = actual
  if @args
    actual.received_message?(@expected, *@args)
  else
    actual.received_message?(@expected)
  end
end

#with(*args) ⇒ Object



34
35
36
37
# File 'lib/stirlitz/matchers.rb', line 34

def with(*args)
  @args = args
  self
end