module RSpec::Mocks::TestDoubleFormatter

def self.format(dbl, unwrap=false)

def self.format(dbl, unwrap=false)
  format = "#{type_desc(dbl)}#{verified_module_desc(dbl)} #{name_desc(dbl)}"
  return format if unwrap
  "#<#{format}>"
end

def name_desc(dbl)

def name_desc(dbl)
  return "(anonymous)" unless (name = IVAR_GET.bind(dbl).call(:@name))
  name.inspect
end

def type_desc(dbl)

def type_desc(dbl)
  case dbl
  when InstanceVerifyingDouble then "InstanceDouble"
  when ClassVerifyingDouble    then "ClassDouble"
  when ObjectVerifyingDouble   then "ObjectDouble"
  else "Double"
  end
end

def verified_module_desc(dbl)

def verified_module_desc(dbl)
  return nil unless VerifyingDouble === dbl
  "(#{IVAR_GET.bind(dbl).call(:@doubled_module).description})"
end