module Mocha::ParameterMatchers

def responds_with(*options)

Other tags:
    Example: Actual parameter responds with "FOO" when :upcase is invoked and "oof" when :reverse is invoked. -
    Example: Actual parameter does not respond with "FOO" when :upcase is invoked. -
    Example: Actual parameter responds with "FOO" when :upcase is invoked. -

Other tags:
    See: Expectation#with -

Returns:
  • (RespondsWith) - parameter matcher.

Raises:
  • (ArgumentError) - if +messages_vs_results+ does not contain at least one entry.

Parameters:
  • messages_vs_results (Hash) -- +Hash+ of messages vs results.
  • result (Object) -- expected result of sending +message+.
  • message (Symbol) -- method to invoke.

Overloads:
  • def responds_with(messages_vs_results)
  • def responds_with(message, result)
def responds_with(*options)
  case options.length
  when 0
    raise ArgumentError, 'No arguments. Expecting at least one.'
  when 1
    option = options.first
    raise ArgumentError, 'Argument is not a Hash.' unless option.is_a?(Hash)
    raise ArgumentError, 'Argument has no entries.' if option.empty?
    matchers = option.map { |message, result| RespondsWith.new(message, result) }
    AllOf.new(*matchers)
  when 2
    message, result = options
    RespondsWith.new(message, result)
  else
    raise ArgumentError, 'Too many arguments; use either a single argument (must be a Hash) or two arguments (a message and a result).'
  end
end