class RSpec::Matchers::BuiltIn::Equal

@api private Provides the implementation for `equal`. Not intended to be instantiated directly.

Constants

LITERAL_SINGLETONS

Public Instance Methods

diffable?() click to toggle source

@api private @return [Boolean]

# File lib/rspec/matchers/built_in/equal.rb, line 33
def diffable?
  !expected_is_a_literal_singleton?
end
failure_message() click to toggle source

@api private @return [String]

# File lib/rspec/matchers/built_in/equal.rb, line 10
def failure_message
  if expected_is_a_literal_singleton?
    simple_failure_message
  else
    detailed_failure_message
  end
end
failure_message_when_negated() click to toggle source

@api private @return [String]

# File lib/rspec/matchers/built_in/equal.rb, line 20
        def failure_message_when_negated
          <<-MESSAGE

expected not #{inspect_object(actual)}
         got #{inspect_object(expected)}

Compared using equal?, which compares object identity.

MESSAGE
        end

Private Instance Methods

actual_inspected() click to toggle source
# File lib/rspec/matchers/built_in/equal.rb, line 49
def actual_inspected
  if LITERAL_SINGLETONS.include?(actual)
    actual_formatted
  else
    inspect_object(actual)
  end
end
detailed_failure_message() click to toggle source
# File lib/rspec/matchers/built_in/equal.rb, line 61
        def detailed_failure_message
          <<-MESSAGE

expected #{inspect_object(expected)}
     got #{inspect_object(actual)}

Compared using equal?, which compares object identity,
but expected and actual are not the same object. Use
`expect(actual).to eq(expected)` if you don't care about
object identity in this example.

MESSAGE
        end
expected_is_a_literal_singleton?() click to toggle source
# File lib/rspec/matchers/built_in/equal.rb, line 45
def expected_is_a_literal_singleton?
  LITERAL_SINGLETONS.include?(expected)
end
inspect_object(o) click to toggle source
# File lib/rspec/matchers/built_in/equal.rb, line 75
def inspect_object(o)
  "#<#{o.class}:#{o.object_id}> => #{RSpec::Support::ObjectFormatter.format(o)}"
end
match(expected, actual) click to toggle source
# File lib/rspec/matchers/built_in/equal.rb, line 39
def match(expected, actual)
  actual.equal? expected
end
simple_failure_message() click to toggle source
# File lib/rspec/matchers/built_in/equal.rb, line 57
def simple_failure_message
  "\nexpected #{expected_formatted}\n     got #{actual_inspected}\n"
end