@api private Provides the implementation for `equal`. Not intended to be instantiated directly.
@api private @return [Boolean]
# File lib/rspec/matchers/built_in/equal.rb, line 34 def diffable? !expected_is_a_literal_singleton? end
@api private @return [String]
# File lib/rspec/matchers/built_in/equal.rb, line 11 def failure_message if expected_is_a_literal_singleton? simple_failure_message else detailed_failure_message end end
@api private @return [String]
# File lib/rspec/matchers/built_in/equal.rb, line 21 def failure_message_when_negated return <<-MESSAGE expected not #{inspect_object(actual)} got #{inspect_object(expected)} Compared using equal?, which compares object identity. MESSAGE end
# File lib/rspec/matchers/built_in/equal.rb, line 50 def actual_inspected if LITERAL_SINGLETONS.include?(actual) actual.inspect else inspect_object(actual) end end
# File lib/rspec/matchers/built_in/equal.rb, line 62 def detailed_failure_message return <<-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
# File lib/rspec/matchers/built_in/equal.rb, line 46 def expected_is_a_literal_singleton? LITERAL_SINGLETONS.include?(expected) end
# File lib/rspec/matchers/built_in/equal.rb, line 76 def inspect_object(o) "#<#{o.class}:#{o.object_id}> => #{o.inspect}" end
# File lib/rspec/matchers/built_in/equal.rb, line 40 def match(expected, actual) actual.equal? expected end
# File lib/rspec/matchers/built_in/equal.rb, line 58 def simple_failure_message "\nexpected #{expected.inspect}\n got #{actual_inspected}\n" end