summaryrefslogtreecommitdiff
path: root/spec/mspec/lib/mspec/utils/format.rb
blob: 425dd4d11c104b688ba6a5629dc788a2db23d36d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# If the implementation on which the specs are run cannot
# load pp from the standard library, add a pp.rb file that
# defines the #pretty_inspect method on Object or Kernel.
begin
  require 'pp'
rescue LoadError
  module Kernel
    def pretty_inspect
      inspect
    end
  end
end

module MSpec
  def self.format(obj)
    if String === obj and obj.include?("\n")
      "\n#{obj.inspect.gsub('\n', "\n")}"
    else
      obj.pretty_inspect.chomp
    end
  rescue => e
    "#<#{obj.class}>(#pretty_inspect raised #{e.inspect})"
  end
end