super_diff 0.5.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +49 -22
- data/lib/super_diff.rb +25 -7
- data/lib/super_diff/colorized_document_extensions.rb +4 -4
- data/lib/super_diff/configuration.rb +32 -22
- data/lib/super_diff/csi.rb +2 -1
- data/lib/super_diff/diff_formatters/collection.rb +2 -2
- data/lib/super_diff/diff_formatters/multiline_string.rb +4 -4
- data/lib/super_diff/equality_matchers/array.rb +4 -4
- data/lib/super_diff/equality_matchers/default.rb +4 -4
- data/lib/super_diff/equality_matchers/hash.rb +4 -4
- data/lib/super_diff/equality_matchers/multiline_string.rb +4 -4
- data/lib/super_diff/equality_matchers/primitive.rb +4 -4
- data/lib/super_diff/equality_matchers/singleline_string.rb +4 -4
- data/lib/super_diff/gem_version.rb +45 -0
- data/lib/super_diff/object_inspection.rb +0 -8
- data/lib/super_diff/object_inspection/nodes/inspection.rb +1 -1
- data/lib/super_diff/operation_trees/base.rb +2 -0
- data/lib/super_diff/recursion_guard.rb +2 -0
- data/lib/super_diff/rspec.rb +7 -0
- data/lib/super_diff/rspec/matcher_text_builders/base.rb +7 -7
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +6 -6
- data/lib/super_diff/rspec/matcher_text_builders/contain_exactly.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +4 -4
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +5 -5
- data/lib/super_diff/rspec/monkey_patches.rb +353 -306
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +12 -1
- data/lib/super_diff/version.rb +1 -1
- data/spec/combustion/Gemfile.lock +173 -0
- data/spec/examples.txt +406 -5
- data/spec/integration/rspec/be_falsey_matcher_spec.rb +10 -10
- data/spec/integration/rspec/be_matcher_spec.rb +100 -100
- data/spec/integration/rspec/be_nil_matcher_spec.rb +10 -10
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +103 -103
- data/spec/integration/rspec/be_truthy_matcher_spec.rb +10 -10
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +107 -107
- data/spec/integration/rspec/eq_matcher_spec.rb +230 -230
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +129 -129
- data/spec/integration/rspec/have_predicate_matcher_spec.rb +65 -65
- data/spec/integration/rspec/include_matcher_spec.rb +73 -73
- data/spec/integration/rspec/match_array_matcher_spec.rb +149 -107
- data/spec/integration/rspec/match_matcher_spec.rb +274 -274
- data/spec/integration/rspec/raise_error_matcher_spec.rb +86 -86
- data/spec/integration/rspec/respond_to_matcher_spec.rb +240 -240
- data/spec/integration/rspec/third_party_matcher_spec.rb +8 -8
- data/spec/integration/rspec/unhandled_errors_spec.rb +5 -5
- data/spec/spec_helper.rb +30 -13
- data/spec/support/integration/helpers.rb +6 -2
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +1 -1
- data/spec/support/integration/test_programs/base.rb +2 -0
- data/spec/support/integration/test_programs/rspec_active_record.rb +1 -1
- data/spec/support/integration/test_programs/rspec_active_support.rb +17 -0
- data/spec/support/integration/test_programs/rspec_rails.rb +1 -1
- data/spec/support/shared_examples/active_record.rb +108 -108
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +196 -232
- data/spec/unit/equality_matchers/main_spec.rb +403 -403
- data/spec/unit/{object_inspection_spec.rb → super_diff_spec.rb} +136 -76
- data/super_diff.gemspec +2 -1
- metadata +15 -6
@@ -1,18 +1,24 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
RSpec.describe SuperDiff
|
4
|
-
describe ".
|
3
|
+
RSpec.describe SuperDiff do
|
4
|
+
describe ".inspect_object" do
|
5
5
|
context "given nil" do
|
6
6
|
context "given as_single_line: true" do
|
7
7
|
it "returns nil, inspected" do
|
8
|
-
inspection = described_class.
|
8
|
+
inspection = described_class.inspect_object(
|
9
|
+
nil,
|
10
|
+
as_single_line: true,
|
11
|
+
)
|
9
12
|
expect(inspection).to eq("nil")
|
10
13
|
end
|
11
14
|
end
|
12
15
|
|
13
16
|
context "given as_single_line: false" do
|
14
17
|
it "returns nil, inspected" do
|
15
|
-
inspection = described_class.
|
18
|
+
inspection = described_class.inspect_object(
|
19
|
+
nil,
|
20
|
+
as_single_line: false,
|
21
|
+
)
|
16
22
|
expect(inspection).to eq("nil")
|
17
23
|
end
|
18
24
|
end
|
@@ -21,14 +27,20 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
21
27
|
context "given true" do
|
22
28
|
context "given as_single_line: true" do
|
23
29
|
it "returns nil, inspected" do
|
24
|
-
inspection = described_class.
|
30
|
+
inspection = described_class.inspect_object(
|
31
|
+
nil,
|
32
|
+
as_single_line: true,
|
33
|
+
)
|
25
34
|
expect(inspection).to eq("nil")
|
26
35
|
end
|
27
36
|
end
|
28
37
|
|
29
38
|
context "given as_single_line: false" do
|
30
39
|
it "returns nil, inspected" do
|
31
|
-
inspection = described_class.
|
40
|
+
inspection = described_class.inspect_object(
|
41
|
+
nil,
|
42
|
+
as_single_line: false,
|
43
|
+
)
|
32
44
|
expect(inspection).to eq("nil")
|
33
45
|
end
|
34
46
|
end
|
@@ -37,14 +49,20 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
37
49
|
context "given false" do
|
38
50
|
context "given as_single_line: false" do
|
39
51
|
it "returns false, inspected" do
|
40
|
-
inspection = described_class.
|
52
|
+
inspection = described_class.inspect_object(
|
53
|
+
false,
|
54
|
+
as_single_line: false,
|
55
|
+
)
|
41
56
|
expect(inspection).to eq("false")
|
42
57
|
end
|
43
58
|
end
|
44
59
|
|
45
60
|
context "given as_single_line: false" do
|
46
61
|
it "returns false, inspected" do
|
47
|
-
inspection = described_class.
|
62
|
+
inspection = described_class.inspect_object(
|
63
|
+
false,
|
64
|
+
as_single_line: false,
|
65
|
+
)
|
48
66
|
expect(inspection).to eq("false")
|
49
67
|
end
|
50
68
|
end
|
@@ -53,14 +71,20 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
53
71
|
context "given a number" do
|
54
72
|
context "given as_single_line: true" do
|
55
73
|
it "returns the number as a string" do
|
56
|
-
inspection = described_class.
|
74
|
+
inspection = described_class.inspect_object(
|
75
|
+
3,
|
76
|
+
as_single_line: true,
|
77
|
+
)
|
57
78
|
expect(inspection).to eq("3")
|
58
79
|
end
|
59
80
|
end
|
60
81
|
|
61
82
|
context "given as_single_line: false" do
|
62
83
|
it "returns the number as a string" do
|
63
|
-
inspection = described_class.
|
84
|
+
inspection = described_class.inspect_object(
|
85
|
+
3,
|
86
|
+
as_single_line: false,
|
87
|
+
)
|
64
88
|
expect(inspection).to eq("3")
|
65
89
|
end
|
66
90
|
end
|
@@ -69,14 +93,20 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
69
93
|
context "given a symbol" do
|
70
94
|
context "given as_single_line: true" do
|
71
95
|
it "returns the symbol, inspected" do
|
72
|
-
inspection = described_class.
|
96
|
+
inspection = described_class.inspect_object(
|
97
|
+
:foo,
|
98
|
+
as_single_line: true,
|
99
|
+
)
|
73
100
|
expect(inspection).to eq(":foo")
|
74
101
|
end
|
75
102
|
end
|
76
103
|
|
77
104
|
context "given as_single_line: false" do
|
78
105
|
it "returns the symbol, inspected" do
|
79
|
-
inspection = described_class.
|
106
|
+
inspection = described_class.inspect_object(
|
107
|
+
:foo,
|
108
|
+
as_single_line: false,
|
109
|
+
)
|
80
110
|
expect(inspection).to eq(":foo")
|
81
111
|
end
|
82
112
|
end
|
@@ -85,14 +115,20 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
85
115
|
context "given a regex" do
|
86
116
|
context "given as_single_line: true" do
|
87
117
|
it "returns the regex, inspected" do
|
88
|
-
inspection = described_class.
|
118
|
+
inspection = described_class.inspect_object(
|
119
|
+
/foo/,
|
120
|
+
as_single_line: true,
|
121
|
+
)
|
89
122
|
expect(inspection).to eq("/foo/")
|
90
123
|
end
|
91
124
|
end
|
92
125
|
|
93
126
|
context "given as_single_line: false" do
|
94
127
|
it "returns the regex, inspected" do
|
95
|
-
inspection = described_class.
|
128
|
+
inspection = described_class.inspect_object(
|
129
|
+
/foo/,
|
130
|
+
as_single_line: false,
|
131
|
+
)
|
96
132
|
expect(inspection).to eq("/foo/")
|
97
133
|
end
|
98
134
|
end
|
@@ -100,7 +136,10 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
100
136
|
|
101
137
|
context "given a single-line string" do
|
102
138
|
it "returns the string surrounded by quotes" do
|
103
|
-
inspection = described_class.
|
139
|
+
inspection = described_class.inspect_object(
|
140
|
+
"Marty",
|
141
|
+
as_single_line: true,
|
142
|
+
)
|
104
143
|
expect(inspection).to eq('"Marty"')
|
105
144
|
end
|
106
145
|
end
|
@@ -108,7 +147,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
108
147
|
context "given a multi-line string" do
|
109
148
|
context "that does not contain color codes" do
|
110
149
|
it "returns the string surrounded by quotes, with newline characters escaped" do
|
111
|
-
inspection = described_class.
|
150
|
+
inspection = described_class.inspect_object(
|
112
151
|
"This is a line\nAnd that's a line\nAnd there's a line too",
|
113
152
|
as_single_line: true,
|
114
153
|
)
|
@@ -141,7 +180,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
141
180
|
colorize("And there's a line too", colors[2]),
|
142
181
|
].join("\n")
|
143
182
|
|
144
|
-
inspection = described_class.
|
183
|
+
inspection = described_class.inspect_object(
|
145
184
|
string_to_inspect,
|
146
185
|
as_single_line: true,
|
147
186
|
)
|
@@ -158,7 +197,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
158
197
|
context "containing only primitive values" do
|
159
198
|
context "given as_single_line: true" do
|
160
199
|
it "returns a representation of the array on a single line" do
|
161
|
-
inspection = described_class.
|
200
|
+
inspection = described_class.inspect_object(
|
162
201
|
["foo", 2, :baz],
|
163
202
|
as_single_line: true,
|
164
203
|
)
|
@@ -168,7 +207,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
168
207
|
|
169
208
|
context "given as_single_line: false" do
|
170
209
|
it "returns a representation of the array across multiple lines" do
|
171
|
-
inspection = described_class.
|
210
|
+
inspection = described_class.inspect_object(
|
172
211
|
["foo", 2, :baz],
|
173
212
|
as_single_line: false,
|
174
213
|
)
|
@@ -186,7 +225,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
186
225
|
context "containing other arrays" do
|
187
226
|
context "given as_single_line: true" do
|
188
227
|
it "returns a representation of the array on a single line" do
|
189
|
-
inspection = described_class.
|
228
|
+
inspection = described_class.inspect_object(
|
190
229
|
[
|
191
230
|
"foo",
|
192
231
|
["bar", "baz"],
|
@@ -200,7 +239,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
200
239
|
|
201
240
|
context "given as_single_line: false" do
|
202
241
|
it "returns a representation of the array across multiple lines" do
|
203
|
-
inspection = described_class.
|
242
|
+
inspection = described_class.inspect_object(
|
204
243
|
[
|
205
244
|
"foo",
|
206
245
|
["bar", "baz"],
|
@@ -225,14 +264,20 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
225
264
|
context "which is empty" do
|
226
265
|
context "given as_single_line: true" do
|
227
266
|
it "returns a representation of the array on a single line" do
|
228
|
-
inspection = described_class.
|
267
|
+
inspection = described_class.inspect_object(
|
268
|
+
[],
|
269
|
+
as_single_line: true,
|
270
|
+
)
|
229
271
|
expect(inspection).to eq(%([]))
|
230
272
|
end
|
231
273
|
end
|
232
274
|
|
233
275
|
context "given as_single_line: false" do
|
234
276
|
it "returns a representation of the array on a single line" do
|
235
|
-
inspection = described_class.
|
277
|
+
inspection = described_class.inspect_object(
|
278
|
+
[],
|
279
|
+
as_single_line: false,
|
280
|
+
)
|
236
281
|
expect(inspection).to eq(%([]))
|
237
282
|
end
|
238
283
|
end
|
@@ -244,7 +289,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
244
289
|
context "where all of the keys are symbols" do
|
245
290
|
context "given as_single_line: true" do
|
246
291
|
it "returns a representation of the hash on a single line" do
|
247
|
-
inspection = described_class.
|
292
|
+
inspection = described_class.inspect_object(
|
248
293
|
# rubocop:disable Style/HashSyntax
|
249
294
|
{ :foo => "bar", :baz => "qux" },
|
250
295
|
# rubocop:enable Style/HashSyntax
|
@@ -256,7 +301,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
256
301
|
|
257
302
|
context "given as_single_line: false" do
|
258
303
|
it "returns a representation of the hash across multiple lines" do
|
259
|
-
inspection = described_class.
|
304
|
+
inspection = described_class.inspect_object(
|
260
305
|
# rubocop:disable Style/HashSyntax
|
261
306
|
{ :foo => "bar", :baz => "qux" },
|
262
307
|
# rubocop:enable Style/HashSyntax
|
@@ -275,7 +320,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
275
320
|
context "where only some of the keys are symbols" do
|
276
321
|
context "given as_single_line: true" do
|
277
322
|
it "returns a representation of the hash on a single line" do
|
278
|
-
inspection = described_class.
|
323
|
+
inspection = described_class.inspect_object(
|
279
324
|
{ :foo => "bar", 2 => "baz" },
|
280
325
|
as_single_line: true,
|
281
326
|
)
|
@@ -285,7 +330,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
285
330
|
|
286
331
|
context "given as_single_line: false" do
|
287
332
|
it "returns a representation of the hash across multiple lines" do
|
288
|
-
inspection = described_class.
|
333
|
+
inspection = described_class.inspect_object(
|
289
334
|
{ :foo => "bar", 2 => "baz" },
|
290
335
|
as_single_line: false,
|
291
336
|
)
|
@@ -314,7 +359,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
314
359
|
:number_of_products => 2,
|
315
360
|
# rubocop:enable Style/HashSyntax
|
316
361
|
}
|
317
|
-
inspection = described_class.
|
362
|
+
inspection = described_class.inspect_object(
|
318
363
|
value_to_inspect,
|
319
364
|
as_single_line: true,
|
320
365
|
)
|
@@ -338,7 +383,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
338
383
|
:number_of_products => 2,
|
339
384
|
# rubocop:enable Style/HashSyntax
|
340
385
|
}
|
341
|
-
inspection = described_class.
|
386
|
+
inspection = described_class.inspect_object(
|
342
387
|
value_to_inspect,
|
343
388
|
as_single_line: false,
|
344
389
|
)
|
@@ -365,14 +410,20 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
365
410
|
context "which is empty" do
|
366
411
|
context "given as_single_line: true" do
|
367
412
|
it "returns a representation of the array on a single line" do
|
368
|
-
inspection = described_class.
|
413
|
+
inspection = described_class.inspect_object(
|
414
|
+
{},
|
415
|
+
as_single_line: true,
|
416
|
+
)
|
369
417
|
expect(inspection).to eq(%({}))
|
370
418
|
end
|
371
419
|
end
|
372
420
|
|
373
421
|
context "given as_single_line: false" do
|
374
422
|
it "returns a representation of the array on a single line" do
|
375
|
-
inspection = described_class.
|
423
|
+
inspection = described_class.inspect_object(
|
424
|
+
{},
|
425
|
+
as_single_line: false,
|
426
|
+
)
|
376
427
|
expect(inspection).to eq(%({}))
|
377
428
|
end
|
378
429
|
end
|
@@ -382,7 +433,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
382
433
|
context "given a class" do
|
383
434
|
context "given as_single_line: true" do
|
384
435
|
it "returns a representation of the object on a single line" do
|
385
|
-
inspection = described_class.
|
436
|
+
inspection = described_class.inspect_object(
|
386
437
|
SuperDiff::Test::Person,
|
387
438
|
as_single_line: true,
|
388
439
|
)
|
@@ -392,7 +443,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
392
443
|
|
393
444
|
context "given as_single_line: false" do
|
394
445
|
it "returns a representation of the object on a single line" do
|
395
|
-
inspection = described_class.
|
446
|
+
inspection = described_class.inspect_object(
|
396
447
|
SuperDiff::Test::Person,
|
397
448
|
as_single_line: false,
|
398
449
|
)
|
@@ -405,7 +456,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
405
456
|
context "containing only primitive values" do
|
406
457
|
context "given as_single_line: true" do
|
407
458
|
it "returns a representation of the object on a single line" do
|
408
|
-
inspection = described_class.
|
459
|
+
inspection = described_class.inspect_object(
|
409
460
|
SuperDiff::Test::Person.new(name: "Doc", age: 58),
|
410
461
|
as_single_line: true,
|
411
462
|
)
|
@@ -417,7 +468,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
417
468
|
|
418
469
|
context "given as_single_line: false" do
|
419
470
|
it "returns a representation of the object across multiple lines" do
|
420
|
-
inspection = described_class.
|
471
|
+
inspection = described_class.inspect_object(
|
421
472
|
SuperDiff::Test::Person.new(name: "Doc", age: 58),
|
422
473
|
as_single_line: false,
|
423
474
|
)
|
@@ -434,7 +485,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
434
485
|
context "containing other custom objects" do
|
435
486
|
context "given as_single_line: true" do
|
436
487
|
it "returns a representation of the object on a single line" do
|
437
|
-
inspection = described_class.
|
488
|
+
inspection = described_class.inspect_object(
|
438
489
|
SuperDiff::Test::Customer.new(
|
439
490
|
name: "Marty McFly",
|
440
491
|
shipping_address: SuperDiff::Test::ShippingAddress.new(
|
@@ -458,7 +509,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
458
509
|
|
459
510
|
context "given as_single_line: false" do
|
460
511
|
it "returns a representation of the object across multiple lines" do
|
461
|
-
inspection = described_class.
|
512
|
+
inspection = described_class.inspect_object(
|
462
513
|
SuperDiff::Test::Customer.new(
|
463
514
|
name: "Marty McFly",
|
464
515
|
shipping_address: SuperDiff::Test::ShippingAddress.new(
|
@@ -494,7 +545,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
494
545
|
context "containing only primitive values" do
|
495
546
|
context "given as_single_line: true" do
|
496
547
|
it "returns a representation of the object on a single line" do
|
497
|
-
inspection = described_class.
|
548
|
+
inspection = described_class.inspect_object(
|
498
549
|
SuperDiff::Test::Item.new(
|
499
550
|
name: "mac and cheese",
|
500
551
|
quantity: 2,
|
@@ -511,7 +562,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
511
562
|
|
512
563
|
context "given as_single_line: false" do
|
513
564
|
it "returns a representation of the object across multiple lines" do
|
514
|
-
inspection = described_class.
|
565
|
+
inspection = described_class.inspect_object(
|
515
566
|
SuperDiff::Test::Item.new(
|
516
567
|
name: "mac and cheese",
|
517
568
|
quantity: 2,
|
@@ -519,10 +570,10 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
519
570
|
as_single_line: false,
|
520
571
|
)
|
521
572
|
regexp = <<~INSPECTION.rstrip
|
522
|
-
#<SuperDiff::Test::Item:0x[a-z0-9]+
|
573
|
+
#<SuperDiff::Test::Item:0x[a-z0-9]+ \{
|
523
574
|
@name="mac and cheese",
|
524
575
|
@quantity=2
|
525
|
-
|
576
|
+
\}>
|
526
577
|
INSPECTION
|
527
578
|
expect(inspection).to match(/\A#{regexp}\Z/)
|
528
579
|
end
|
@@ -532,7 +583,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
532
583
|
context "containing other custom objects" do
|
533
584
|
context "given as_single_line: true" do
|
534
585
|
it "returns a representation of the object on a single line" do
|
535
|
-
inspection = described_class.
|
586
|
+
inspection = described_class.inspect_object(
|
536
587
|
SuperDiff::Test::Order.new([
|
537
588
|
SuperDiff::Test::Item.new(name: "ham", quantity: 1),
|
538
589
|
SuperDiff::Test::Item.new(name: "eggs", quantity: 2),
|
@@ -550,7 +601,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
550
601
|
|
551
602
|
context "given as_single_line: false" do
|
552
603
|
it "returns a representation of the object across multiple lines" do
|
553
|
-
inspection = described_class.
|
604
|
+
inspection = described_class.inspect_object(
|
554
605
|
SuperDiff::Test::Order.new([
|
555
606
|
SuperDiff::Test::Item.new(name: "ham", quantity: 1),
|
556
607
|
SuperDiff::Test::Item.new(name: "eggs", quantity: 2),
|
@@ -574,7 +625,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
574
625
|
@quantity=1
|
575
626
|
\\}>
|
576
627
|
\\]
|
577
|
-
}>
|
628
|
+
\\}>
|
578
629
|
INSPECTION
|
579
630
|
expect(inspection).to match(/\A#{regexp}\Z/)
|
580
631
|
end
|
@@ -584,19 +635,19 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
584
635
|
context "which is empty" do
|
585
636
|
context "given as_single_line: true" do
|
586
637
|
it "returns a representation of the array on a single line" do
|
587
|
-
inspection = described_class.
|
638
|
+
inspection = described_class.inspect_object(
|
588
639
|
SuperDiff::Test::EmptyClass.new,
|
589
640
|
as_single_line: true,
|
590
641
|
)
|
591
642
|
expect(inspection).to match(
|
592
|
-
/#<SuperDiff::Test::EmptyClass:0x[a-z0-9]
|
643
|
+
/#<SuperDiff::Test::EmptyClass:0x[a-z0-9]+>/,
|
593
644
|
)
|
594
645
|
end
|
595
646
|
end
|
596
647
|
|
597
648
|
context "given as_single_line: false" do
|
598
649
|
it "returns a representation of the array on a single line" do
|
599
|
-
inspection = described_class.
|
650
|
+
inspection = described_class.inspect_object(
|
600
651
|
SuperDiff::Test::EmptyClass.new,
|
601
652
|
as_single_line: false,
|
602
653
|
)
|
@@ -611,7 +662,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
611
662
|
context "given a hash-including-<something>" do
|
612
663
|
context "given as_single_line: true" do
|
613
664
|
it "returns a representation of the object on a single line" do
|
614
|
-
inspection = described_class.
|
665
|
+
inspection = described_class.inspect_object(
|
615
666
|
a_hash_including(foo: "bar", baz: "qux"),
|
616
667
|
as_single_line: true,
|
617
668
|
)
|
@@ -624,7 +675,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
624
675
|
|
625
676
|
context "given as_single_line: false" do
|
626
677
|
it "returns a representation of the object across multiple lines" do
|
627
|
-
inspection = described_class.
|
678
|
+
inspection = described_class.inspect_object(
|
628
679
|
a_hash_including(foo: "bar", baz: "qux"),
|
629
680
|
as_single_line: false,
|
630
681
|
)
|
@@ -642,7 +693,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
642
693
|
context "given a collection-including-<something>" do
|
643
694
|
context "given as_single_line: true" do
|
644
695
|
it "returns a representation of the object on a single line" do
|
645
|
-
inspection = described_class.
|
696
|
+
inspection = described_class.inspect_object(
|
646
697
|
a_collection_including(1, 2, 3),
|
647
698
|
as_single_line: true,
|
648
699
|
)
|
@@ -655,7 +706,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
655
706
|
|
656
707
|
context "given as_single_line: false" do
|
657
708
|
it "returns a representation of the object across multiple lines" do
|
658
|
-
inspection = described_class.
|
709
|
+
inspection = described_class.inspect_object(
|
659
710
|
a_collection_including(1, 2, 3),
|
660
711
|
as_single_line: false,
|
661
712
|
)
|
@@ -674,7 +725,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
674
725
|
context "given a fuzzy object" do
|
675
726
|
context "given as_single_line: true" do
|
676
727
|
it "returns a representation of the object on a single line" do
|
677
|
-
inspection = described_class.
|
728
|
+
inspection = described_class.inspect_object(
|
678
729
|
an_object_having_attributes(foo: "bar", baz: "qux"),
|
679
730
|
as_single_line: true,
|
680
731
|
)
|
@@ -687,7 +738,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
687
738
|
|
688
739
|
context "given as_single_line: false" do
|
689
740
|
it "returns a representation of the object across multiple lines" do
|
690
|
-
inspection = described_class.
|
741
|
+
inspection = described_class.inspect_object(
|
691
742
|
an_object_having_attributes(foo: "bar", baz: "qux"),
|
692
743
|
as_single_line: false,
|
693
744
|
)
|
@@ -705,7 +756,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
705
756
|
context "given a collection-containing-exactly-<something>" do
|
706
757
|
context "given as_single_line: true" do
|
707
758
|
it "returns a representation of the object on a single line" do
|
708
|
-
inspection = described_class.
|
759
|
+
inspection = described_class.inspect_object(
|
709
760
|
a_collection_containing_exactly("foo", "bar", "baz"),
|
710
761
|
as_single_line: true,
|
711
762
|
)
|
@@ -718,7 +769,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
718
769
|
|
719
770
|
context "given as_single_line: false" do
|
720
771
|
it "returns a representation of the object across multiple lines" do
|
721
|
-
inspection = described_class.
|
772
|
+
inspection = described_class.inspect_object(
|
722
773
|
a_collection_containing_exactly("foo", "bar", "baz"),
|
723
774
|
as_single_line: false,
|
724
775
|
)
|
@@ -737,7 +788,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
737
788
|
context "given a kind-of-<something>" do
|
738
789
|
context "given as_single_line: true" do
|
739
790
|
it "returns a representation of the object on a single line" do
|
740
|
-
inspection = described_class.
|
791
|
+
inspection = described_class.inspect_object(
|
741
792
|
a_kind_of(Symbol),
|
742
793
|
as_single_line: true,
|
743
794
|
)
|
@@ -748,7 +799,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
748
799
|
|
749
800
|
context "given as_single_line: false" do
|
750
801
|
it "returns a representation of the object on a single line" do
|
751
|
-
inspection = described_class.
|
802
|
+
inspection = described_class.inspect_object(
|
752
803
|
a_kind_of(Symbol),
|
753
804
|
as_single_line: false,
|
754
805
|
)
|
@@ -761,7 +812,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
761
812
|
context "given an-instance-of-<something>" do
|
762
813
|
context "given as_single_line: true" do
|
763
814
|
it "returns a representation of the object on a single line" do
|
764
|
-
inspection = described_class.
|
815
|
+
inspection = described_class.inspect_object(
|
765
816
|
an_instance_of(Symbol),
|
766
817
|
as_single_line: true,
|
767
818
|
)
|
@@ -772,7 +823,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
772
823
|
|
773
824
|
context "given as_single_line: false" do
|
774
825
|
it "returns a representation of the object on a single line" do
|
775
|
-
inspection = described_class.
|
826
|
+
inspection = described_class.inspect_object(
|
776
827
|
an_instance_of(Symbol),
|
777
828
|
as_single_line: false,
|
778
829
|
)
|
@@ -785,7 +836,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
785
836
|
context "given a-value-within-<something>" do
|
786
837
|
context "given as_single_line: true" do
|
787
838
|
it "returns a representation of the object on a single line" do
|
788
|
-
inspection = described_class.
|
839
|
+
inspection = described_class.inspect_object(
|
789
840
|
a_value_within(1).of(Time.utc(2020, 4, 9)),
|
790
841
|
as_single_line: true,
|
791
842
|
)
|
@@ -798,7 +849,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
798
849
|
|
799
850
|
context "given as_single_line: false" do
|
800
851
|
it "returns a representation of the object on a single line" do
|
801
|
-
inspection = described_class.
|
852
|
+
inspection = described_class.inspect_object(
|
802
853
|
a_value_within(1).of(Time.utc(2020, 4, 9)),
|
803
854
|
as_single_line: false,
|
804
855
|
)
|
@@ -814,7 +865,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
814
865
|
context "that is anonymous" do
|
815
866
|
context "given as_single_line: true" do
|
816
867
|
it "returns a representation of the object on a single line" do
|
817
|
-
inspection = described_class.
|
868
|
+
inspection = described_class.inspect_object(
|
818
869
|
double(foo: "bar", baz: "qux"),
|
819
870
|
as_single_line: true,
|
820
871
|
)
|
@@ -825,7 +876,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
825
876
|
|
826
877
|
context "given as_single_line: false" do
|
827
878
|
it "returns a representation of the object across multiple lines" do
|
828
|
-
inspection = described_class.
|
879
|
+
inspection = described_class.inspect_object(
|
829
880
|
double(foo: "bar", baz: "qux"),
|
830
881
|
as_single_line: false,
|
831
882
|
)
|
@@ -839,7 +890,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
839
890
|
context "given an ActiveRecord object", active_record: true do
|
840
891
|
context "given as_single_line: true" do
|
841
892
|
it "returns a representation of the object on a single line" do
|
842
|
-
inspection = described_class.
|
893
|
+
inspection = described_class.inspect_object(
|
843
894
|
SuperDiff::Test::Models::ActiveRecord::Person.new(
|
844
895
|
name: "Elliot",
|
845
896
|
age: 31,
|
@@ -847,15 +898,17 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
847
898
|
as_single_line: true,
|
848
899
|
)
|
849
900
|
|
901
|
+
# rubocop:disable Metrics/LineLength
|
850
902
|
expect(inspection).to eq(
|
851
|
-
%(#<SuperDiff::Test::Models::ActiveRecord::Person id: nil, age: 31, name: "Elliot">)
|
903
|
+
%(#<SuperDiff::Test::Models::ActiveRecord::Person id: nil, age: 31, name: "Elliot">),
|
852
904
|
)
|
905
|
+
# rubocop:enable Metrics/LineLength
|
853
906
|
end
|
854
907
|
end
|
855
908
|
|
856
909
|
context "given as_single_line: false" do
|
857
910
|
it "returns a representation of the object across multiple lines" do
|
858
|
-
inspection = described_class.
|
911
|
+
inspection = described_class.inspect_object(
|
859
912
|
SuperDiff::Test::Models::ActiveRecord::Person.new(
|
860
913
|
name: "Elliot",
|
861
914
|
age: 31,
|
@@ -886,14 +939,16 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
886
939
|
age: 17,
|
887
940
|
)
|
888
941
|
|
889
|
-
inspection = described_class.
|
942
|
+
inspection = described_class.inspect_object(
|
890
943
|
SuperDiff::Test::Models::ActiveRecord::Person.all,
|
891
944
|
as_single_line: true,
|
892
945
|
)
|
893
946
|
|
947
|
+
# rubocop:disable Metrics/LineLength
|
894
948
|
expect(inspection).to eq(
|
895
|
-
%(#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person id: 1, age: 19, name: "Marty">, #<SuperDiff::Test::Models::ActiveRecord::Person id: 2, age: 17, name: "Jennifer">]>)
|
949
|
+
%(#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person id: 1, age: 19, name: "Marty">, #<SuperDiff::Test::Models::ActiveRecord::Person id: 2, age: 17, name: "Jennifer">]>),
|
896
950
|
)
|
951
|
+
# rubocop:enable Metrics/LineLength
|
897
952
|
end
|
898
953
|
end
|
899
954
|
|
@@ -908,7 +963,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
908
963
|
age: 17,
|
909
964
|
)
|
910
965
|
|
911
|
-
inspection = described_class.
|
966
|
+
inspection = described_class.inspect_object(
|
912
967
|
SuperDiff::Test::Models::ActiveRecord::Person.all,
|
913
968
|
as_single_line: false,
|
914
969
|
)
|
@@ -934,7 +989,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
934
989
|
context "given a HashWithIndifferentAccess", active_record: true do
|
935
990
|
context "given as_single_line: true" do
|
936
991
|
it "returns a representation of the object on a single line" do
|
937
|
-
inspection = described_class.
|
992
|
+
inspection = described_class.inspect_object(
|
938
993
|
HashWithIndifferentAccess.new({
|
939
994
|
line_1: "123 Main St.",
|
940
995
|
city: "Hill Valley",
|
@@ -944,15 +999,17 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
944
999
|
as_single_line: true,
|
945
1000
|
)
|
946
1001
|
|
1002
|
+
# rubocop:disable Metrics/LineLength
|
947
1003
|
expect(inspection).to eq(
|
948
|
-
%(#<HashWithIndifferentAccess { "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }>)
|
1004
|
+
%(#<HashWithIndifferentAccess { "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }>),
|
949
1005
|
)
|
1006
|
+
# rubocop:enable Metrics/LineLength
|
950
1007
|
end
|
951
1008
|
end
|
952
1009
|
|
953
1010
|
context "given as_single_line: false" do
|
954
1011
|
it "returns a representation of the object across multiple lines" do
|
955
|
-
inspection = described_class.
|
1012
|
+
inspection = described_class.inspect_object(
|
956
1013
|
HashWithIndifferentAccess.new({
|
957
1014
|
line_1: "123 Main St.",
|
958
1015
|
city: "Hill Valley",
|
@@ -977,7 +1034,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
977
1034
|
context "given a combination of all kinds of values" do
|
978
1035
|
context "given as_single_line: true" do
|
979
1036
|
it "returns a representation of the object on a single line" do
|
980
|
-
inspection = described_class.
|
1037
|
+
inspection = described_class.inspect_object(
|
981
1038
|
{
|
982
1039
|
state: :down,
|
983
1040
|
errors: [
|
@@ -1031,7 +1088,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
1031
1088
|
|
1032
1089
|
context "given as_single_line: false" do
|
1033
1090
|
it "returns a representation of the object across multiple lines" do
|
1034
|
-
inspection = described_class.
|
1091
|
+
inspection = described_class.inspect_object(
|
1035
1092
|
{
|
1036
1093
|
state: :down,
|
1037
1094
|
errors: [
|
@@ -1140,7 +1197,7 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
1140
1197
|
it "replaces the reference with ∙∙∙" do
|
1141
1198
|
value = ["a", "b", "c"]
|
1142
1199
|
value.insert(1, value)
|
1143
|
-
inspection = described_class.
|
1200
|
+
inspection = described_class.inspect_object(value, as_single_line: true)
|
1144
1201
|
expect(inspection).to eq(%(["a", ∙∙∙, "b", "c"]))
|
1145
1202
|
end
|
1146
1203
|
end
|
@@ -1149,7 +1206,10 @@ RSpec.describe SuperDiff::ObjectInspection do
|
|
1149
1206
|
it "replaces the reference with ∙∙∙" do
|
1150
1207
|
value = ["a", "b", "c"]
|
1151
1208
|
value.insert(1, value)
|
1152
|
-
inspection = described_class.
|
1209
|
+
inspection = described_class.inspect_object(
|
1210
|
+
value,
|
1211
|
+
as_single_line: false,
|
1212
|
+
)
|
1153
1213
|
expect(inspection).to eq(<<~INSPECTION.rstrip)
|
1154
1214
|
[
|
1155
1215
|
"a",
|