Skip to content

Commit 8d2ab95

Browse files
committed
Add support for symbols
1 parent 6e81a74 commit 8d2ab95

File tree

2 files changed

+64
-16
lines changed

2 files changed

+64
-16
lines changed

lib/super_diff/differ.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def plural_type_for(value)
162162
case value
163163
when Numeric then "numbers"
164164
when String then "strings"
165+
when Symbol then "symbols"
165166
else "objects"
166167
end
167168
end

spec/unit/differ_spec.rb

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@
2525
end
2626
end
2727

28+
context "given the same symbol" do
29+
it "returns an empty string" do
30+
output = described_class.call(expected: :foo, actual: :foo)
31+
32+
expect(output).to eq("")
33+
end
34+
end
35+
36+
context "given differing symbols" do
37+
it "returns a message along with a comparison" do
38+
actual_output = described_class.call(expected: :foo, actual: :bar)
39+
40+
expected_output = <<~STR
41+
Differing symbols.
42+
43+
Expected: :foo
44+
Actual: :bar
45+
STR
46+
47+
expect(actual_output).to eq(expected_output)
48+
end
49+
end
50+
2851
context "given the same string" do
2952
it "returns an empty string" do
3053
output = described_class.call(expected: "", actual: "")
@@ -131,48 +154,72 @@
131154
end
132155
end
133156

134-
context "given two equal-length, one-dimensional arrays with differing strings" do
157+
context "given two equal-length, one-dimensional arrays with differing numbers" do
135158
it "returns a message along with the diff" do
136159
actual_output = described_class.call(
137-
expected: ["foo", "bar", "qux"],
138-
actual: ["foo", "baz", "qux"]
160+
expected: [1, 2, 3, 4],
161+
actual: [1, 2, 99, 4]
139162
)
140163

141164
expected_output = <<~STR
142165
Differing arrays.
143166
144-
Expected: ["foo", "bar", "qux"]
145-
Actual: ["foo", "baz", "qux"]
167+
Expected: [1, 2, 3, 4]
168+
Actual: [1, 2, 99, 4]
146169
147170
Details:
148171
149-
- *[1]: Differing strings.
150-
Expected: "bar"
151-
Actual: "baz"
172+
- *[2]: Differing numbers.
173+
Expected: 3
174+
Actual: 99
152175
STR
153176

154177
expect(actual_output).to eq(expected_output)
155178
end
156179
end
157180

158-
context "given two equal-length, one-dimensional arrays with differing numbers" do
181+
context "given two equal-length, one-dimensional arrays with differing symbols" do
159182
it "returns a message along with the diff" do
160183
actual_output = described_class.call(
161-
expected: [1, 2, 3, 4],
162-
actual: [1, 2, 99, 4]
184+
expected: [:one, :fish, :two, :fish],
185+
actual: [:one, :FISH, :two, :fish]
163186
)
164187

165188
expected_output = <<~STR
166189
Differing arrays.
167190
168-
Expected: [1, 2, 3, 4]
169-
Actual: [1, 2, 99, 4]
191+
Expected: [:one, :fish, :two, :fish]
192+
Actual: [:one, :FISH, :two, :fish]
170193
171194
Details:
172195
173-
- *[2]: Differing numbers.
174-
Expected: 3
175-
Actual: 99
196+
- *[1]: Differing symbols.
197+
Expected: :fish
198+
Actual: :FISH
199+
STR
200+
201+
expect(actual_output).to eq(expected_output)
202+
end
203+
end
204+
205+
context "given two equal-length, one-dimensional arrays with differing strings" do
206+
it "returns a message along with the diff" do
207+
actual_output = described_class.call(
208+
expected: ["foo", "bar", "qux"],
209+
actual: ["foo", "baz", "qux"]
210+
)
211+
212+
expected_output = <<~STR
213+
Differing arrays.
214+
215+
Expected: ["foo", "bar", "qux"]
216+
Actual: ["foo", "baz", "qux"]
217+
218+
Details:
219+
220+
- *[1]: Differing strings.
221+
Expected: "bar"
222+
Actual: "baz"
176223
STR
177224

178225
expect(actual_output).to eq(expected_output)

0 commit comments

Comments
 (0)