class RSpec::Crispy::CrispyFeatures::CrispyHaveReceived

Public Class Methods

new(method_name, *arguments) click to toggle source
# File lib/rspec/crispy/crispy_features.rb, line 35
def initialize method_name, *arguments
  @method_name = method_name
  @arguments = arguments
end

Public Instance Methods

actually_received_messages_for_failure_message() click to toggle source
# File lib/rspec/crispy/crispy_features.rb, line 79
def actually_received_messages_for_failure_message
  if @spy_of_subject.received_messages.empty?
    "Actually, it has received no messages.\n".freeze
  else
    result = "Actually, it has received these messages:\n"
    @spy_of_subject.received_messages.each do|received_message|
      arguments_for_message = received_message.arguments.map(&:inspect).join(', '.freeze)
      # TODO: which instance actually received the message for ClassSpy
      result << "  it.#{received_message.method_name}(#{arguments_for_message})\n"
    end
    result
  end
end
failure_message() click to toggle source
# File lib/rspec/crispy/crispy_features.rb, line 62
def failure_message
  @spy_of_subject.stop
  result = "Expected #{@subject.inspect} to have received :#@method_name method"
  result << " with #@arguments" unless @arguments.empty?
  result << ".\n"
  result << actually_received_messages_for_failure_message
  result
end
failure_message_when_negated() click to toggle source
# File lib/rspec/crispy/crispy_features.rb, line 71
def failure_message_when_negated
  @spy_of_subject.stop
  result = "Expected #{@subject.inspect} NOT to have received :#@method_name method"
  result << " with #@arguments" unless @arguments.empty?
  result << ". But actually received.\n".freeze
  result
end
matched_spy?(spy) click to toggle source
# File lib/rspec/crispy/crispy_features.rb, line 50
def matched_spy? spy
  spy.received? @method_name, *@arguments
end
matches?(subject) click to toggle source
# File lib/rspec/crispy/crispy_features.rb, line 44
def matches?(subject)
  @subject = subject
  @spy_of_subject = spy_of_subject subject
  matched_spy?(@spy_of_subject)
end
name() click to toggle source
# File lib/rspec/crispy/crispy_features.rb, line 40
def name
  'have_received'.freeze
end
once() click to toggle source
# File lib/rspec/crispy/crispy_features.rb, line 54
def once
  times 1
end
spy_of_subject(subject) click to toggle source
# File lib/rspec/crispy/crispy_features.rb, line 93
def spy_of_subject subject
  # Don't use instance_of? method. it records received_messages.
  if CrispyExpectAnyInstanceOf === subject
    subject.get_spy_of_instances
  else
    ::Crispy.spy(subject)
  end
end
times(n) click to toggle source
# File lib/rspec/crispy/crispy_features.rb, line 58
def times n
  NTimes.new n, @method_name, *@arguments
end