This repository was archived by the owner on Nov 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 384
Expand file tree
/
Copy pathequal.rb
More file actions
81 lines (65 loc) · 1.87 KB
/
equal.rb
File metadata and controls
81 lines (65 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `equal`.
# Not intended to be instantiated directly.
class Equal < BaseMatcher
# @api private
# @return [String]
def failure_message
if expected_is_a_literal_singleton?
simple_failure_message
else
detailed_failure_message
end
end
# @api private
# @return [String]
def failure_message_when_negated
<<-MESSAGE
expected not #{inspect_object(actual)}
got #{inspect_object(expected)}
Compared using equal?, which compares object identity.
MESSAGE
end
# @api private
# @return [Boolean]
def diffable?
!expected_is_a_literal_singleton?
end
private
def match(expected, actual)
actual.equal? expected
end
LITERAL_SINGLETONS = [true, false, nil]
def expected_is_a_literal_singleton?
LITERAL_SINGLETONS.include?(expected)
end
def actual_inspected
if LITERAL_SINGLETONS.include?(actual)
actual_formatted
else
inspect_object(actual)
end
end
def simple_failure_message
"\nexpected #{expected_formatted}\n got #{actual_inspected}\n"
end
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
def inspect_object(o)
"#<#{o.class}:#{o.object_id}> => #{RSpec::Support::ObjectFormatter.format(o)}"
end
end
end
end
end