class Bogus::HaveReceivedMatcher

Constants

NO_SHADOW

Public Instance Methods

build(*args) click to toggle source
# File lib/bogus/stubbing/have_received_matcher.rb, line 38
def build(*args)
  return method_call if args.empty?
  set_method(*args)
end
description() click to toggle source
# File lib/bogus/stubbing/have_received_matcher.rb, line 20
def description
  "have received #{call_str(@name, @args)}"
end
failure_message_for_should() click to toggle source
# File lib/bogus/stubbing/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_not() click to toggle source
# File lib/bogus/stubbing/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) click to toggle source
# 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_call() click to toggle source
# File lib/bogus/stubbing/have_received_matcher.rb, line 34
def method_call
  proxy(:set_method)
end
set_method(name, *args, &block) click to toggle source
# File lib/bogus/stubbing/have_received_matcher.rb, line 43
def set_method(name, *args, &block)
  @name = name
  @args = args
  self
end

Private Instance Methods

all_calls_str() click to toggle source
# File lib/bogus/stubbing/have_received_matcher.rb, line 55
def all_calls_str
  shadow = @subject.__shadow__
  calls = shadow.calls.map{|i| call_str(i.method, i.args)}

  if calls.any?
    message = "The recorded interactions were:\n"
    calls.each{|s| message << "  - #{s}\n"}
    message
  else
    "There were no interactions with this object.\n"
  end
end
call_str(method, args) click to toggle source
# File lib/bogus/stubbing/have_received_matcher.rb, line 51
def call_str(method, args)
  "#{method}(#{args.map(&:inspect).join(', ')})"
end