Class: Bogus::HaveReceivedMatcher

Inherits:
Object
  • Object
show all
Extended by:
Takes
Includes:
ProxiesMethodCalls
Defined in:
lib/bogus/stubbing/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



40
41
42
43
# File 'lib/bogus/stubbing/have_received_matcher.rb', line 40

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

#descriptionObject



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

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

#failure_messageObject Also known as: failure_message_for_should



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

def failure_message
  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_when_negatedObject Also known as: failure_message_for_should_not



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

def failure_message_when_negated
  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/stubbing/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



36
37
38
# File 'lib/bogus/stubbing/have_received_matcher.rb', line 36

def method_call
  proxy(:set_method)
end

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



45
46
47
48
49
# File 'lib/bogus/stubbing/have_received_matcher.rb', line 45

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