class RSpec::Mocks::ErrorGenerator

@private

def self.raise_double_negation_error(wrapped_expression)

def self.raise_double_negation_error(wrapped_expression)
  raise "Isn't life confusing enough? You've already set a " +
        "negative message expectation and now you are trying to " +
        "negate it again with `never`. What does an expression like " +
        "`#{wrapped_expression}.not_to receive(:msg).never` even mean?"
end

def __raise(message)

def __raise(message)
  message = opts[:message] unless opts[:message].nil?
  Kernel::raise(RSpec::Mocks::MockExpectationError, message)
end

def arg_has_valid_description(arg)

def arg_has_valid_description(arg)
  return false unless arg.respond_to?(:description)
  !arg.description.nil? && !arg.description.empty?
end

def arg_list(*args)

def arg_list(*args)
  args.collect {|arg| arg_has_valid_description(arg) ? arg.description : arg.inspect }.join(", ")
end

def arg_message(*args)

def arg_message(*args)
  " with " + format_args(*args)
end

def count_message(count, expectation_count_type=nil)

def count_message(count, expectation_count_type=nil)
  return "at least #{pretty_print(count.abs)}" if count < 0 || expectation_count_type == :at_least
  return "at most #{pretty_print(count)}" if expectation_count_type == :at_most
  return pretty_print(count)
end

def describe_expectation(message, expected_received_count, actual_received_count, *args)

Other tags:
    Private: -
def describe_expectation(message, expected_received_count, actual_received_count, *args)
  "have received #{message}#{format_args(*args)} #{count_message(expected_received_count)}"
end

def expected_part_of_expectation_error(expected_received_count, expectation_count_type, argument_list_matcher)

Other tags:
    Private: -
def expected_part_of_expectation_error(expected_received_count, expectation_count_type, argument_list_matcher)
  "expected: #{count_message(expected_received_count, expectation_count_type)}" +
    method_call_args_description(argument_list_matcher.expected_args)
end

def format_args(*args)

def format_args(*args)
  args.empty? ? "(no args)" : "(" + arg_list(*args) + ")"
end

def format_received_args(*args)

def format_received_args(*args)
  args.empty? ? "(no args)" : "(" + received_arg_list(*args) + ")"
end

def initialize(target, name)

def initialize(target, name)
  @target = target
  @name = name
end

def intro

def intro
  if @name
    "Double #{@name.inspect}"
  elsif TestDouble === @target
    "Double"
  elsif Class === @target
    "<#{@target.inspect} (class)>"
  elsif @target
    @target
  else
    "nil"
  end
end

def method_call_args_description(args)

Other tags:
    Private: -
def method_call_args_description(args)
  case args.first
    when ArgumentMatchers::AnyArgsMatcher
      return " with any arguments"
    when ArgumentMatchers::NoArgsMatcher
      return " with no arguments"
  end
  if args.length > 0
    " with arguments: #{args.inspect.gsub(/\A\[(.+)\]\z/, '(\1)')}"
  else
    ""
  end
end

def opts

Other tags:
    Private: -
def opts
  @opts ||= {}
end

def pretty_print(count)

def pretty_print(count)
  "#{count} time#{count == 1 ? '' : 's'}"
end

def raise_arity_error(calculator, actual)

Other tags:
    Private: -
def raise_arity_error(calculator, actual)
  __raise "Wrong number of arguments. Expected %s, got %s." % [
    calculator.range_description,
    actual
  ]
end

def raise_block_failed_error(message, detail)

Other tags:
    Private: -
def raise_block_failed_error(message, detail)
  __raise "#{intro} received :#{message} but passed block failed with: #{detail}"
end

def raise_expectation_error(message, expected_received_count, argument_list_matcher, actual_received_count, expectation_count_type, *args)

Other tags:
    Private: -
def raise_expectation_error(message, expected_received_count, argument_list_matcher, actual_received_count, expectation_count_type, *args)
  expected_part = expected_part_of_expectation_error(expected_received_count, expectation_count_type, argument_list_matcher)
  received_part = received_part_of_expectation_error(actual_received_count, *args)
  __raise "(#{intro}).#{message}#{format_args(*args)}\n    #{expected_part}\n    #{received_part}"
end

def raise_expectation_on_mocked_method(method)

Other tags:
    Private: -
def raise_expectation_on_mocked_method(method)
  __raise "#{intro} expected to have received #{method}, but that " +
          "method has been mocked instead of stubbed."
end

def raise_expectation_on_unstubbed_method(method)

Other tags:
    Private: -
def raise_expectation_on_unstubbed_method(method)
  __raise "#{intro} expected to have received #{method}, but that " +
          "method has not been stubbed."
end

def raise_missing_block_error(args_to_yield)

Other tags:
    Private: -
def raise_missing_block_error(args_to_yield)
  __raise "#{intro} asked to yield |#{arg_list(*args_to_yield)}| but no block was passed"
end

def raise_missing_default_stub_error(expectation, *args)

Other tags:
    Private: -
def raise_missing_default_stub_error(expectation, *args)
  expected_args = format_args(*expectation.expected_args)
  actual_args = format_received_args(*args)
  __raise "#{intro} received #{expectation.message.inspect} with unexpected arguments\n  expected: #{expected_args}\n       got: #{actual_args}\n Please stub a default value first if message might be received with other args as well. \n"
end

def raise_only_valid_on_a_partial_mock(method)

Other tags:
    Private: -
def raise_only_valid_on_a_partial_mock(method)
  __raise "#{intro} is a pure mock object. `#{method}` is only " +
          "available on a partial mock object."
end

def raise_out_of_order_error(message)

Other tags:
    Private: -
def raise_out_of_order_error(message)
  __raise "#{intro} received :#{message} out of order"
end

def raise_similar_message_args_error(expectation, *args_for_multiple_calls)

Other tags:
    Private: -
def raise_similar_message_args_error(expectation, *args_for_multiple_calls)
  expected_args = format_args(*expectation.expected_args)
  actual_args = args_for_multiple_calls.collect {|a| format_received_args(*a)}.join(", ")
  __raise "#{intro} received #{expectation.message.inspect} with unexpected arguments\n  expected: #{expected_args}\n       got: #{actual_args}"
end

def raise_unexpected_message_args_error(expectation, *args)

Other tags:
    Private: -
def raise_unexpected_message_args_error(expectation, *args)
  expected_args = format_args(*expectation.expected_args)
  actual_args = format_received_args(*args)
  __raise "#{intro} received #{expectation.message.inspect} with unexpected arguments\n  expected: #{expected_args}\n       got: #{actual_args}"
end

def raise_unexpected_message_error(message, *args)

Other tags:
    Private: -
def raise_unexpected_message_error(message, *args)
  __raise "#{intro} received unexpected message :#{message}#{arg_message(*args)}"
end

def raise_unimplemented_error(doubled_module, method_name)

Other tags:
    Private: -
def raise_unimplemented_error(doubled_module, method_name)
  __raise "%s does not implement:\n  %s" % [
    doubled_module.description,
    method_name
  ]
end

def raise_wrong_arity_error(args_to_yield, arity)

Other tags:
    Private: -
def raise_wrong_arity_error(args_to_yield, arity)
  __raise "#{intro} yielded |#{arg_list(*args_to_yield)}| to block with arity of #{arity}"
end

def received_arg_list(*args)

def received_arg_list(*args)
  args.collect(&:inspect).join(", ")
end

def received_part_of_expectation_error(actual_received_count, *args)

Other tags:
    Private: -
def received_part_of_expectation_error(actual_received_count, *args)
  "received: #{count_message(actual_received_count)}" +
    method_call_args_description(args)
end