Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 65398e7

Browse files
committed
fixup! Remove LCS version-specific hacks from spec
1 parent 6962f8b commit 65398e7

File tree

1 file changed

+55
-100
lines changed

1 file changed

+55
-100
lines changed

spec/rspec/support/differ_spec.rb

Lines changed: 55 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,35 @@
22
require 'timeout'
33
require 'rspec/support/spec/string_matcher'
44

5-
RSpec::Support.require_rspec_support "spec/diff_helpers"
6-
75
module RSpec
86
module Support
97
RSpec.describe Differ do
10-
include Spec::DiffHelpers
11-
128
describe '#diff' do
139
let(:differ) { RSpec::Support::Differ.new }
1410

1511
it "outputs unified diff of two strings" do
1612
expected = "foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n"
1713
actual = "foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n"
1814

19-
if Diff::LCS::VERSION.to_f < 1.4 || Diff::LCS::VERSION >= "1.4.4"
20-
expected_diff = dedent(<<-'EOD')
21-
|
22-
|
23-
|@@ -1,6 +1,6 @@
24-
| foo
25-
|-zap
26-
| bar
27-
|+zap
28-
| this
29-
| is
30-
| soo
31-
|@@ -9,6 +9,5 @@
32-
| equal
33-
| insert
34-
| a
35-
|-another
36-
| line
37-
|
38-
EOD
39-
else
40-
expected_diff = dedent(<<-'EOD')
41-
|
42-
|
43-
|@@ -1,4 +1,6 @@
44-
| foo
45-
|-zap
46-
| bar
47-
|+zap
48-
| this
49-
|@@ -9,6 +11,7 @@
50-
| equal
51-
| insert
52-
| a
53-
|-another
54-
| line
55-
|
56-
EOD
57-
end
58-
15+
expected_diff = dedent(<<-'EOD')
16+
|
17+
|
18+
|@@ -1,6 +1,6 @@
19+
| foo
20+
|-zap
21+
| bar
22+
|+zap
23+
| this
24+
| is
25+
| soo
26+
|@@ -9,6 +9,5 @@
27+
| equal
28+
| insert
29+
| a
30+
|-another
31+
| line
32+
|
33+
EOD
5934

6035
diff = differ.diff(actual, expected)
6136
expect(diff).to be_diffed_as(expected_diff)
@@ -65,45 +40,25 @@ module Support
6540
expected = "foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n"
6641
actual = "foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n"
6742

68-
if Diff::LCS::VERSION.to_f < 1.4 || Diff::LCS::VERSION >= "1.4.4"
69-
expected_diff = dedent(<<-'EOS')
70-
|
71-
|
72-
|@@ -1,6 +1,6 @@
73-
| foo
74-
|-zap
75-
| bar
76-
|+zap
77-
| this
78-
| is
79-
| soo
80-
|@@ -9,6 +9,5 @@
81-
| equal
82-
| insert
83-
| a
84-
|-another
85-
| line
86-
|
87-
EOS
88-
else
89-
expected_diff = dedent(<<-'EOS')
90-
|
91-
|
92-
|@@ -1,4 +1,6 @@
93-
| foo
94-
|-zap
95-
| bar
96-
|+zap
97-
| this
98-
|@@ -9,6 +11,7 @@
99-
| equal
100-
| insert
101-
| a
102-
|-another
103-
| line
104-
|
105-
EOS
106-
end
43+
expected_diff = dedent(<<-'EOS')
44+
|
45+
|
46+
|@@ -1,6 +1,6 @@
47+
| foo
48+
|-zap
49+
| bar
50+
|+zap
51+
| this
52+
| is
53+
| soo
54+
|@@ -9,6 +9,5 @@
55+
| equal
56+
| insert
57+
| a
58+
|-another
59+
| line
60+
|
61+
EOS
10762

10863
diff = differ.diff(actual, expected)
10964
expect(diff).to be_diffed_as(expected_diff)
@@ -135,7 +90,7 @@ def differ_ivars
13590
actual = "Tu avec carté {count} itém has\n".encode('UTF-16LE')
13691
expected_diff = dedent(<<-EOD).encode('UTF-16LE')
13792
|
138-
|@@ #{one_line_header} @@
93+
|@@ -1 +1 @@
13994
|-Tu avec carte {count} item has
14095
|+Tu avec carté {count} itém has
14196
|
@@ -148,15 +103,15 @@ def differ_ivars
148103
it 'handles differently encoded strings that are compatible' do
149104
expected = "abc\n".encode('us-ascii')
150105
actual = "강인철\n".encode('UTF-8')
151-
expected_diff = "\n@@ #{one_line_header} @@\n-abc\n+강인철\n"
106+
expected_diff = "\n@@ -1 +1 @@\n-abc\n+강인철\n"
152107
diff = differ.diff(actual, expected)
153108
expect(diff).to be_diffed_as(expected_diff)
154109
end
155110

156111
it 'uses the default external encoding when the two strings have incompatible encodings' do
157112
expected = "Tu avec carte {count} item has\n"
158113
actual = "Tu avec carté {count} itém has\n".encode('UTF-16LE')
159-
expected_diff = "\n@@ #{one_line_header} @@\n-Tu avec carte {count} item has\n+Tu avec carté {count} itém has\n"
114+
expected_diff = "\n@@ -1 +1 @@\n-Tu avec carte {count} item has\n+Tu avec carté {count} itém has\n"
160115

161116
diff = differ.diff(actual, expected)
162117
expect(diff).to be_diffed_as(expected_diff)
@@ -247,7 +202,7 @@ def inspect; "<BrokenObject>"; end
247202

248203
expected_diff = dedent(<<-EOD)
249204
|
250-
|@@ #{one_line_header} @@
205+
|@@ -1 +1 @@
251206
|-[]
252207
|+[<BrokenObject>]
253208
|
@@ -259,7 +214,7 @@ def inspect; "<BrokenObject>"; end
259214
diff = differ.diff(["a\r\nb"], ["a\r\nc"])
260215
expected_diff = dedent(<<-EOD)
261216
|
262-
|@@ #{one_line_header} @@
217+
|@@ -1 +1 @@
263218
|-a\\r\\nc
264219
|+a\\r\\nb
265220
|
@@ -310,7 +265,7 @@ def inspect; "<BrokenObject>"; end
310265
it 'outputs unified diff message of two hashes with differing encoding' do
311266
expected_diff = dedent(<<-"EOD")
312267
|
313-
|@@ #{one_line_header} @@
268+
|@@ -1 +1 @@
314269
|-"a" => "a",
315270
|+"ö" => "ö",
316271
|
@@ -323,7 +278,7 @@ def inspect; "<BrokenObject>"; end
323278
it 'outputs unified diff message of two hashes with encoding different to key encoding' do
324279
expected_diff = dedent(<<-"EOD")
325280
|
326-
|@@ #{one_line_header} @@
281+
|@@ -1 +1 @@
327282
|-:a => "a",
328283
|+\"한글\" => \"한글2\",
329284
|
@@ -336,7 +291,7 @@ def inspect; "<BrokenObject>"; end
336291
it "outputs unified diff message of two hashes with object keys" do
337292
expected_diff = dedent(<<-"EOD")
338293
|
339-
|@@ #{one_line_header} @@
294+
|@@ -1 +1 @@
340295
|-["a", "c"] => "b",
341296
|+["d", "c"] => "b",
342297
|
@@ -353,7 +308,7 @@ def inspect; "<BrokenObject>"; end
353308
it "outputs unified diff message of two hashes with Time object keys" do
354309
expected_diff = dedent(<<-"EOD")
355310
|
356-
|@@ #{one_line_header} @@
311+
|@@ -1 +1 @@
357312
|-#{formatted_time} => "b",
358313
|+#{formatted_time} => "c",
359314
|
@@ -366,7 +321,7 @@ def inspect; "<BrokenObject>"; end
366321
it "outputs unified diff message of two hashes with hashes inside them" do
367322
expected_diff = dedent(<<-"EOD")
368323
|
369-
|@@ #{one_line_header} @@
324+
|@@ -1 +1 @@
370325
|-"b" => {"key_1"=>#{formatted_time}},
371326
|+"c" => {"key_1"=>#{formatted_time}},
372327
|
@@ -386,7 +341,7 @@ def inspect; "<BrokenObject>"; end
386341
it "outputs unified diff message of two arrays with Time object keys" do
387342
expected_diff = dedent(<<-"EOD")
388343
|
389-
|@@ #{one_line_header} @@
344+
|@@ -1 +1 @@
390345
|-[#{formatted_time}, "b"]
391346
|+[#{formatted_time}, "c"]
392347
|
@@ -399,7 +354,7 @@ def inspect; "<BrokenObject>"; end
399354
it "outputs unified diff message of two arrays with hashes inside them" do
400355
expected_diff = dedent(<<-"EOD")
401356
|
402-
|@@ #{one_line_header} @@
357+
|@@ -1 +1 @@
403358
|-[{"b"=>#{formatted_time}}, "c"]
404359
|+[{"a"=>#{formatted_time}}, "c"]
405360
|
@@ -432,7 +387,7 @@ def inspect; "<BrokenObject>"; end
432387
it "splits items with newlines" do
433388
expected_diff = dedent(<<-"EOD")
434389
|
435-
|@@ #{removing_two_line_header} @@
390+
|@@ -1,3 +1 @@
436391
|-a\\nb
437392
|-c\\nd
438393
|
@@ -445,7 +400,7 @@ def inspect; "<BrokenObject>"; end
445400
it "shows inner arrays on a single line" do
446401
expected_diff = dedent(<<-"EOD")
447402
|
448-
|@@ #{removing_two_line_header} @@
403+
|@@ -1,3 +1 @@
449404
|-a\\nb
450405
|-["c\\nd"]
451406
|
@@ -498,7 +453,7 @@ def inspect; "<BrokenObject>"; end
498453

499454
expected_diff = dedent(<<-EOS)
500455
|
501-
|@@ #{one_line_header} @@
456+
|@@ -1 +1 @@
502457
|-[#<SimpleDelegator(#{object.inspect})>]
503458
|+[#{object.inspect}]
504459
|
@@ -520,7 +475,7 @@ def inspect; "<BrokenObject>"; end
520475

521476
expected_diff = dedent(<<-EOS)
522477
|
523-
|@@ #{one_line_header} @@
478+
|@@ -1 +1 @@
524479
|-"oop"
525480
|+"oof"
526481
|
@@ -537,7 +492,7 @@ def inspect; "<BrokenObject>"; end
537492
it "outputs colored diffs" do
538493
expected = "foo bar baz\n"
539494
actual = "foo bang baz\n"
540-
expected_diff = "\e[0m\n\e[0m\e[34m@@ #{one_line_header} @@\n\e[0m\e[31m-foo bang baz\n\e[0m\e[32m+foo bar baz\n\e[0m"
495+
expected_diff = "\e[0m\n\e[0m\e[34m@@ -1 +1 @@\n\e[0m\e[31m-foo bang baz\n\e[0m\e[32m+foo bar baz\n\e[0m"
541496

542497
diff = differ.diff(expected,actual)
543498
expect(diff).to be_diffed_as(expected_diff)

0 commit comments

Comments
 (0)