class RSpec::Mocks::ErrorGenerator

@private

def __raise(message)

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

def arg_list(*args)

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

def arg_message(*args)

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

def count_message(count)

def count_message(count)
  return "at least #{pretty_print(count.abs)}" if count < 0
  return pretty_print(count)
end

def format_args(*args)

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

def initialize(target, name, options={})

def initialize(target, name, options={})
  @declared_as = options[:__declared_as] || 'Mock'
  @target = target
  @name = name
end

def intro

def intro
  if @name
    "#{@declared_as} #{@name.inspect}"
  elsif TestDouble === @target
    @declared_as
  elsif Class === @target
    "<#{@target.inspect} (class)>"
  elsif @target
    @target
  else
    "nil"
  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_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, actual_received_count, *args)

Other tags:
    Private: -
def raise_expectation_error(message, expected_received_count, actual_received_count, *args)
  __raise "(#{intro}).#{message}#{format_args(*args)}\n    expected: #{count_message(expected_received_count)}\n    received: #{count_message(actual_received_count)}"
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 = args.collect {|a| format_args(*a)}.join(", ")
  __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)

Other tags:
    Private: -
def raise_similar_message_args_error(expectation, *args)
  expected_args = format_args(*expectation.expected_args)
  actual_args = args.collect {|a| format_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_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_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