Class: Bogus::HaveReceivedMatcher

Inherits:
Object
  • Object
show all
Extended by:
Takes
Includes:
ProxiesMethodCalls
Defined in:
lib/bogus/have_received_matcher.rb

Constant Summary collapse

NO_SHADOW =
"Given object is not a fake and nothing was ever stubbed or mocked on it!"

Instance Method Summary collapse

Methods included from Takes

takes

Methods included from ProxiesMethodCalls

#proxy

Instance Method Details

#build(*args) ⇒ Object



38
39
40
41
# File 'lib/bogus/have_received_matcher.rb', line 38

def build(*args)
  return method_call if args.empty?
  set_method(*args)
end

#descriptionObject



20
21
22
# File 'lib/bogus/have_received_matcher.rb', line 20

def description
  "have received #{call_str(@name, @args)}"
end

#failure_message_for_shouldObject



24
25
26
27
# File 'lib/bogus/have_received_matcher.rb', line 24

def failure_message_for_should
  return NO_SHADOW unless Shadow.has_shadow?(@subject)
  %Q{Expected #{@subject.inspect} to #{description}, but it didn't.\n\n} + all_calls_str
end

#failure_message_for_should_notObject



29
30
31
32
# File 'lib/bogus/have_received_matcher.rb', line 29

def failure_message_for_should_not
  return NO_SHADOW unless Shadow.has_shadow?(@subject)
  %Q{Expected #{@subject.inspect} not to #{description}, but it did.}
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
# File 'lib/bogus/have_received_matcher.rb', line 10

def matches?(subject)
  @subject = subject
  return false unless Shadow.has_shadow?(subject)

  verifies_stub_definition.verify!(subject, @name, @args)
  records_double_interactions.record(subject, @name, @args)

  subject.__shadow__.has_received(@name, @args)
end

#method_callObject



34
35
36
# File 'lib/bogus/have_received_matcher.rb', line 34

def method_call
  proxy(:set_method)
end

#set_method(name, *args, &block) ⇒ Object



43
44
45
46
47
# File 'lib/bogus/have_received_matcher.rb', line 43

def set_method(name, *args, &block)
  @name = name
  @args = args
  self
end