super_diff 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -1
  3. data/lib/super_diff.rb +27 -6
  4. data/lib/super_diff/active_record.rb +7 -7
  5. data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -13
  6. data/lib/super_diff/active_record/object_inspection.rb +2 -6
  7. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +16 -0
  8. data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_model.rb +19 -20
  9. data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_relation.rb +9 -8
  10. data/lib/super_diff/active_record/operation_tree_flatteners.rb +10 -0
  11. data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +17 -0
  12. data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +8 -7
  13. data/lib/super_diff/active_support.rb +8 -8
  14. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -13
  15. data/lib/super_diff/active_support/object_inspection.rb +2 -6
  16. data/lib/super_diff/active_support/object_inspection/{inspectors.rb → inspection_tree_builders.rb} +2 -2
  17. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +37 -0
  18. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +17 -0
  19. data/lib/super_diff/active_support/operation_tree_flatteners.rb +10 -0
  20. data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +17 -0
  21. data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +4 -7
  22. data/lib/super_diff/colorized_document_extensions.rb +9 -6
  23. data/lib/super_diff/configuration.rb +81 -8
  24. data/lib/super_diff/csi.rb +1 -2
  25. data/lib/super_diff/csi/four_bit_color.rb +0 -2
  26. data/lib/super_diff/differs/array.rb +1 -1
  27. data/lib/super_diff/differs/base.rb +3 -21
  28. data/lib/super_diff/differs/custom_object.rb +1 -1
  29. data/lib/super_diff/differs/default_object.rb +1 -1
  30. data/lib/super_diff/differs/hash.rb +1 -1
  31. data/lib/super_diff/differs/main.rb +1 -7
  32. data/lib/super_diff/differs/multiline_string.rb +1 -1
  33. data/lib/super_diff/differs/time_like.rb +1 -1
  34. data/lib/super_diff/equality_matchers/array.rb +2 -2
  35. data/lib/super_diff/equality_matchers/default.rb +2 -2
  36. data/lib/super_diff/equality_matchers/hash.rb +2 -2
  37. data/lib/super_diff/equality_matchers/multiline_string.rb +2 -2
  38. data/lib/super_diff/equality_matchers/primitive.rb +4 -7
  39. data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
  40. data/lib/super_diff/helpers.rb +52 -2
  41. data/lib/super_diff/line.rb +83 -0
  42. data/lib/super_diff/object_inspection.rb +12 -1
  43. data/lib/super_diff/object_inspection/inspection_tree.rb +183 -81
  44. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +44 -0
  45. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +38 -0
  46. data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +27 -0
  47. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +37 -0
  48. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +63 -0
  49. data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/defaults.rb +1 -2
  50. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +46 -0
  51. data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/main.rb +5 -10
  52. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +21 -0
  53. data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/time_like.rb +19 -18
  54. data/lib/super_diff/object_inspection/nodes.rb +33 -32
  55. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +97 -0
  56. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +27 -0
  57. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +27 -0
  58. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +33 -0
  59. data/lib/super_diff/object_inspection/nodes/base.rb +55 -20
  60. data/lib/super_diff/object_inspection/nodes/inspection.rb +47 -7
  61. data/lib/super_diff/object_inspection/nodes/nesting.rb +16 -5
  62. data/lib/super_diff/object_inspection/nodes/only_when.rb +54 -0
  63. data/lib/super_diff/object_inspection/nodes/text.rb +16 -2
  64. data/lib/super_diff/object_inspection/nodes/when_empty.rb +21 -6
  65. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +20 -5
  66. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +27 -0
  67. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +27 -0
  68. data/lib/super_diff/object_inspection/prefix_for_next_node.rb +6 -0
  69. data/lib/super_diff/object_inspection/prelude_for_next_node.rb +6 -0
  70. data/lib/super_diff/operation_tree_builders/array.rb +7 -10
  71. data/lib/super_diff/operation_tree_builders/base.rb +6 -6
  72. data/lib/super_diff/operation_tree_builders/custom_object.rb +5 -2
  73. data/lib/super_diff/operation_tree_builders/default_object.rb +1 -1
  74. data/lib/super_diff/operation_tree_builders/hash.rb +0 -7
  75. data/lib/super_diff/operation_tree_builders/multiline_string.rb +2 -6
  76. data/lib/super_diff/operation_tree_flatteners.rb +20 -0
  77. data/lib/super_diff/operation_tree_flatteners/array.rb +15 -0
  78. data/lib/super_diff/operation_tree_flatteners/base.rb +54 -0
  79. data/lib/super_diff/operation_tree_flatteners/collection.rb +139 -0
  80. data/lib/super_diff/operation_tree_flatteners/custom_object.rb +28 -0
  81. data/lib/super_diff/operation_tree_flatteners/default_object.rb +32 -0
  82. data/lib/super_diff/operation_tree_flatteners/hash.rb +41 -0
  83. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +17 -0
  84. data/lib/super_diff/operation_trees/array.rb +4 -7
  85. data/lib/super_diff/operation_trees/base.rb +39 -16
  86. data/lib/super_diff/operation_trees/custom_object.rb +4 -8
  87. data/lib/super_diff/operation_trees/default_object.rb +28 -13
  88. data/lib/super_diff/operation_trees/hash.rb +4 -7
  89. data/lib/super_diff/operation_trees/main.rb +1 -1
  90. data/lib/super_diff/operation_trees/multiline_string.rb +4 -7
  91. data/lib/super_diff/operations/binary_operation.rb +1 -6
  92. data/lib/super_diff/operations/unary_operation.rb +2 -30
  93. data/lib/super_diff/recursion_guard.rb +3 -3
  94. data/lib/super_diff/rspec.rb +12 -13
  95. data/lib/super_diff/rspec/monkey_patches.rb +2 -2
  96. data/lib/super_diff/rspec/object_inspection.rb +4 -1
  97. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +44 -0
  98. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/collection_containing_exactly.rb +9 -8
  99. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/collection_including.rb +9 -8
  100. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +103 -0
  101. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +36 -0
  102. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/instance_of.rb +3 -5
  103. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/kind_of.rb +3 -5
  104. data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/object_having_attributes.rb +10 -12
  105. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +10 -0
  106. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +33 -0
  107. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +0 -3
  108. data/lib/super_diff/tiered_lines.rb +4 -0
  109. data/lib/super_diff/tiered_lines_elider.rb +490 -0
  110. data/lib/super_diff/tiered_lines_formatter.rb +79 -0
  111. data/lib/super_diff/version.rb +1 -1
  112. data/spec/examples.txt +407 -410
  113. data/spec/integration/rails/active_support_spec.rb +19 -0
  114. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +12 -6
  115. data/spec/integration/rspec/eq_matcher_spec.rb +22 -88
  116. data/spec/integration/rspec/have_attributes_matcher_spec.rb +6 -7
  117. data/spec/integration/rspec/match_array_matcher_spec.rb +14 -7
  118. data/spec/integration/rspec/match_matcher_spec.rb +10 -5
  119. data/spec/spec_helper.rb +1 -0
  120. data/spec/support/command_runner.rb +15 -25
  121. data/spec/support/helpers.rb +21 -0
  122. data/spec/support/integration/helpers.rb +2 -0
  123. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +3 -3
  124. data/spec/support/integration/test_programs/base.rb +36 -10
  125. data/spec/support/shared_examples/active_record.rb +3 -2
  126. data/spec/support/shared_examples/active_support.rb +65 -0
  127. data/spec/support/shared_examples/elided_diffs.rb +914 -0
  128. data/spec/support/shared_examples/hash_with_indifferent_access.rb +16 -16
  129. data/spec/support/unit/helpers.rb +15 -0
  130. data/spec/support/unit/matchers/match_output.rb +41 -0
  131. data/spec/unit/active_record/object_inspection_spec.rb +273 -0
  132. data/spec/unit/equality_matchers/main_spec.rb +51 -71
  133. data/spec/unit/helpers_spec.rb +61 -0
  134. data/spec/unit/operation_tree_flatteners/array_spec.rb +604 -0
  135. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +667 -0
  136. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +687 -0
  137. data/spec/unit/operation_tree_flatteners/hash_spec.rb +632 -0
  138. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +121 -0
  139. data/spec/unit/rspec/object_inspection_spec.rb +446 -0
  140. data/spec/unit/super_diff_spec.rb +1488 -846
  141. data/spec/unit/tiered_lines_elider_spec.rb +6356 -0
  142. data/spec/unit/tiered_lines_formatter_spec.rb +193 -0
  143. metadata +88 -50
  144. data/lib/super_diff/active_record/diff_formatters.rb +0 -10
  145. data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +0 -23
  146. data/lib/super_diff/active_record/object_inspection/inspectors.rb +0 -16
  147. data/lib/super_diff/active_support/diff_formatters.rb +0 -10
  148. data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +0 -36
  149. data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +0 -28
  150. data/lib/super_diff/diff_formatters.rb +0 -14
  151. data/lib/super_diff/diff_formatters/array.rb +0 -21
  152. data/lib/super_diff/diff_formatters/base.rb +0 -33
  153. data/lib/super_diff/diff_formatters/custom_object.rb +0 -30
  154. data/lib/super_diff/diff_formatters/default_object.rb +0 -46
  155. data/lib/super_diff/diff_formatters/defaults.rb +0 -10
  156. data/lib/super_diff/diff_formatters/hash.rb +0 -34
  157. data/lib/super_diff/diff_formatters/main.rb +0 -41
  158. data/lib/super_diff/object_inspection/inspectors.rb +0 -23
  159. data/lib/super_diff/object_inspection/inspectors/array.rb +0 -32
  160. data/lib/super_diff/object_inspection/inspectors/base.rb +0 -36
  161. data/lib/super_diff/object_inspection/inspectors/custom_object.rb +0 -37
  162. data/lib/super_diff/object_inspection/inspectors/default_object.rb +0 -61
  163. data/lib/super_diff/object_inspection/inspectors/hash.rb +0 -32
  164. data/lib/super_diff/object_inspection/inspectors/primitive.rb +0 -28
  165. data/lib/super_diff/object_inspection/inspectors/string.rb +0 -23
  166. data/lib/super_diff/object_inspection/nodes/break.rb +0 -15
  167. data/lib/super_diff/object_inspection/nodes/when_multiline.rb +0 -22
  168. data/lib/super_diff/object_inspection/nodes/when_singleline.rb +0 -24
  169. data/lib/super_diff/rspec/object_inspection/inspectors.rb +0 -40
  170. data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +0 -36
  171. data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +0 -13
  172. data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +0 -29
  173. data/spec/support/object_id.rb +0 -27
  174. data/spec/support/ruby_versions.rb +0 -11
@@ -0,0 +1,21 @@
1
+ module SuperDiff
2
+ module Test
3
+ module OutputHelpers
4
+ def self.bookended(text)
5
+ divider("START") + text + "\n" + divider("END")
6
+ end
7
+
8
+ def self.divider(title = "")
9
+ total_length = 72
10
+ start_length = 3
11
+
12
+ string = ""
13
+ string << ("-" * start_length)
14
+ string << title
15
+ string << "-" * (total_length - start_length - title.length)
16
+ string << "\n"
17
+ string
18
+ end
19
+ end
20
+ end
21
+ end
@@ -11,11 +11,13 @@ module SuperDiff
11
11
  def make_plain_test_program(
12
12
  test,
13
13
  color_enabled:,
14
+ configuration: {},
14
15
  preserve_as_whole_file: false
15
16
  )
16
17
  TestPrograms::Plain.new(
17
18
  test,
18
19
  color_enabled: color_enabled,
20
+ configuration: configuration,
19
21
  preserve_as_whole_file: preserve_as_whole_file,
20
22
  )
21
23
  end
@@ -12,7 +12,7 @@ module SuperDiff
12
12
  end
13
13
 
14
14
  def removing_object_ids
15
- first_replacing(/#<([\w:]+):0x[a-z0-9]+(.*?)>/, '#<\1\2>')
15
+ first_replacing(/#<([\w:]+):0x[a-f0-9]+/, '#<\1')
16
16
  self
17
17
  end
18
18
 
@@ -38,10 +38,10 @@ module SuperDiff
38
38
  message =
39
39
  "Expected test to produce #{expect_output_to_contain_color? ? "colored" : "uncolored"} output, but it did not.\n\n" +
40
40
  "Expected output to contain:\n\n" +
41
- CommandRunner::OutputHelpers.bookended(expected_output) +
41
+ SuperDiff::Test::OutputHelpers.bookended(expected_output) +
42
42
  "\n" +
43
43
  "Actual output:\n\n" +
44
- CommandRunner::OutputHelpers.bookended(actual_output)
44
+ SuperDiff::Test::OutputHelpers.bookended(actual_output)
45
45
 
46
46
  if ["1", "true"].include?(ENV["SHOW_DIFF"])
47
47
  ::RSpec::Matchers::ExpectedsForMultipleDiffs.
@@ -1,4 +1,5 @@
1
1
  require "attr_extras/explicit"
2
+ require "json"
2
3
 
3
4
  module SuperDiff
4
5
  module IntegrationTests
@@ -9,11 +10,15 @@ module SuperDiff
9
10
  PROJECT_DIRECTORY = Pathname.new("../../../..").expand_path(__dir__)
10
11
  TEMP_DIRECTORY = PROJECT_DIRECTORY.join("tmp")
11
12
 
12
- attr_private :code, :color_enabled, :preserve_as_whole_file
13
-
14
- def initialize(code, color_enabled:, preserve_as_whole_file: false)
13
+ def initialize(
14
+ code,
15
+ color_enabled:,
16
+ configuration: {},
17
+ preserve_as_whole_file: false
18
+ )
15
19
  @code = code.strip
16
20
  @color_enabled = color_enabled
21
+ @configuration = configuration
17
22
  @preserve_as_whole_file = preserve_as_whole_file
18
23
  end
19
24
 
@@ -33,15 +38,27 @@ module SuperDiff
33
38
 
34
39
  private
35
40
 
36
- attr_query :color_enabled?
37
- attr_query :preserve_as_whole_file?
41
+ attr_reader :code, :configuration
42
+
43
+ def color_enabled?
44
+ @color_enabled
45
+ end
46
+
47
+ def preserve_as_whole_file?
48
+ @preserve_as_whole_file
49
+ end
38
50
 
39
51
  def result_of_command
40
52
  @_result_of_command ||=
41
53
  if zeus_running?
42
- Bundler.with_unbundled_env { CommandRunner.run(*command) }
54
+ Bundler.with_unbundled_env do
55
+ CommandRunner.run(Shellwords.join(command))
56
+ end
43
57
  else
44
- CommandRunner.run(*command)
58
+ CommandRunner.run(
59
+ Shellwords.join(command),
60
+ env: { 'DISABLE_PRY' => 'true' },
61
+ )
45
62
  end
46
63
  end
47
64
 
@@ -51,7 +68,15 @@ module SuperDiff
51
68
  end
52
69
 
53
70
  if zeus_running?
54
- ["zeus", test_plan_command, color_option, tempfile.to_s]
71
+ [
72
+ "zeus",
73
+ test_plan_command,
74
+ color_option,
75
+ "--no-pry",
76
+ tempfile.to_s,
77
+ "--configuration",
78
+ JSON.generate(configuration),
79
+ ]
55
80
  else
56
81
  [
57
82
  "rspec",
@@ -67,7 +92,7 @@ module SuperDiff
67
92
  end
68
93
 
69
94
  def color_option
70
- color_enabled ? "--color" : "--no-color"
95
+ color_enabled? ? "--color" : "--no-color"
71
96
  end
72
97
 
73
98
  def tempfile
@@ -88,7 +113,8 @@ module SuperDiff
88
113
 
89
114
  test_plan = TestPlan.new(
90
115
  using_outside_of_zeus: true,
91
- color_enabled: #{color_enabled?}
116
+ color_enabled: #{color_enabled?.inspect},
117
+ configuration: #{configuration.inspect}
92
118
  )
93
119
  test_plan.boot
94
120
  #{test_plan_prelude}
@@ -372,7 +372,7 @@ shared_examples_for "integration with ActiveRecord" do
372
372
  expectation: proc {
373
373
  line do
374
374
  plain %|Expected |
375
- actual %|[#<SuperDiff::Test::Models::ActiveRecord::Query @results=#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person id: 1, name: "Murphy", age: 20>]>>]|
375
+ actual %|[#<SuperDiff::Test::Models::ActiveRecord::Query @results=#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person id: 1, age: 20, name: "Murphy">]>>]|
376
376
  end
377
377
 
378
378
  line do
@@ -389,7 +389,8 @@ shared_examples_for "integration with ActiveRecord" do
389
389
  # expected_line %|- age: 19,| # TODO
390
390
  expected_line %|- age: 19|
391
391
  actual_line %|+ age: 20,|
392
- expected_line %|- name: "John"|
392
+ # expected_line %|- name: "John"| # TODO
393
+ expected_line %|- name: "John",|
393
394
  actual_line %|+ name: "Murphy"|
394
395
  plain_line %| }>|
395
396
  plain_line %| ]>|
@@ -0,0 +1,65 @@
1
+ shared_examples_for "integration with ActiveSupport" do
2
+ context "when comparing two different Time and ActiveSupport::TimeWithZone instances", active_record: true do
3
+ it "produces the correct failure message when used in the positive" do
4
+ as_both_colored_and_uncolored do |color_enabled|
5
+ snippet = <<~RUBY
6
+ expected = Time.utc(2011, 12, 13, 14, 15, 16)
7
+ actual = Time.utc(2011, 12, 13, 15, 15, 16).in_time_zone("Europe/Stockholm")
8
+ expect(expected).to eq(actual)
9
+ RUBY
10
+ program = make_rspec_rails_test_program(
11
+ snippet,
12
+ color_enabled: color_enabled,
13
+ )
14
+
15
+ expected_output = build_expected_output(
16
+ color_enabled: color_enabled,
17
+ snippet: %|expect(expected).to eq(actual)|,
18
+ expectation: proc {
19
+ line do
20
+ plain %|Expected |
21
+ actual %|#<Time 2011-12-13 14:15:16 +00:00 (UTC)>|
22
+ end
23
+
24
+ line do
25
+ plain %| to eq |
26
+ expected %|#<ActiveSupport::TimeWithZone 2011-12-13 16:15:16 +01:00 (CET)>|
27
+ end
28
+ },
29
+ diff: proc {
30
+ plain_line %| #<Time {|
31
+ plain_line %| year: 2011,|
32
+ plain_line %| month: 12,|
33
+ plain_line %| day: 13,|
34
+ expected_line %|- hour: 16,|
35
+ actual_line %|+ hour: 14,|
36
+ plain_line %| min: 15,|
37
+ plain_line %| sec: 16,|
38
+ plain_line %| subsec: 0,|
39
+ expected_line %|- zone: \"CET\",|
40
+ actual_line %|+ zone: \"UTC\",|
41
+ expected_line %|- utc_offset: 3600,|
42
+ actual_line %|+ utc_offset: 0,|
43
+ plain_line %| utc: #<Time {|
44
+ plain_line %| year: 2011,|
45
+ plain_line %| month: 12,|
46
+ plain_line %| day: 13,|
47
+ expected_line %|- hour: 15,|
48
+ actual_line %|+ hour: 14,|
49
+ plain_line %| min: 15,|
50
+ plain_line %| sec: 16,|
51
+ plain_line %| subsec: 0,|
52
+ plain_line %| zone: "UTC",|
53
+ plain_line %| utc_offset: 0|
54
+ plain_line %| }>|
55
+ plain_line %| }>|
56
+ },
57
+ )
58
+
59
+ expect(program).
60
+ to produce_output_when_run(expected_output).
61
+ in_color(color_enabled)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,914 @@
1
+ shared_examples_for "a matcher that supports elided diffs" do
2
+ context "when comparing two one-dimensional data structures which feature a changed section flanked by unchanged sections" do
3
+ context "if diff_elision_enabled is set to true" do
4
+ it "elides the unchanged sections, preserving <maximum> number of lines within all unchanged sections (including the elision marker)" do
5
+ as_both_colored_and_uncolored do |color_enabled|
6
+ snippet = <<~TEST.strip
7
+ expected = [
8
+ "Afghanistan",
9
+ "Aland Islands",
10
+ "Albania",
11
+ "Algeria",
12
+ "American Samoa",
13
+ "Andorra",
14
+ "Angola",
15
+ "Antarctica",
16
+ "Antigua And Barbuda",
17
+ "Argentina",
18
+ "Armenia",
19
+ "Aruba",
20
+ "Australia"
21
+ ]
22
+ actual = [
23
+ "Afghanistan",
24
+ "Aland Islands",
25
+ "Albania",
26
+ "Algeria",
27
+ "American Samoa",
28
+ "Andorra",
29
+ "Anguilla",
30
+ "Antarctica",
31
+ "Antigua And Barbuda",
32
+ "Argentina",
33
+ "Armenia",
34
+ "Aruba",
35
+ "Australia"
36
+ ]
37
+ expect(actual).to #{matcher}(expected)
38
+ TEST
39
+ program = make_plain_test_program(
40
+ snippet,
41
+ color_enabled: color_enabled,
42
+ configuration: {
43
+ diff_elision_enabled: true,
44
+ diff_elision_maximum: 3,
45
+ },
46
+ )
47
+
48
+ expected_output = build_expected_output(
49
+ color_enabled: color_enabled,
50
+ snippet: %|expect(actual).to #{matcher}(expected)|,
51
+ newline_before_expectation: true,
52
+ expectation: proc {
53
+ line do
54
+ plain "Expected "
55
+ # rubocop:disable Layout/LineLength
56
+ actual %|["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia"]|
57
+ # rubocop:enable Layout/LineLength
58
+ end
59
+
60
+ line do
61
+ plain " to eq "
62
+ # rubocop:disable Layout/LineLength
63
+ expected %|["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia"]|
64
+ # rubocop:enable Layout/LineLength
65
+ end
66
+ },
67
+ diff: proc {
68
+ plain_line %| [|
69
+ elision_marker_line %| # ...|
70
+ plain_line %| "American Samoa",|
71
+ plain_line %| "Andorra",|
72
+ expected_line %|- "Angola",|
73
+ actual_line %|+ "Anguilla",|
74
+ plain_line %| "Antarctica",|
75
+ plain_line %| "Antigua And Barbuda",|
76
+ elision_marker_line %| # ...|
77
+ plain_line %| ]|
78
+ },
79
+ )
80
+
81
+ expect(program).
82
+ to produce_output_when_run(expected_output).
83
+ in_color(color_enabled)
84
+ end
85
+ end
86
+ end
87
+
88
+ context "if diff_elision_enabled is set to false" do
89
+ it "does not elide anything" do
90
+ as_both_colored_and_uncolored do |color_enabled|
91
+ snippet = <<~TEST.strip
92
+ expected = [
93
+ "Afghanistan",
94
+ "Aland Islands",
95
+ "Albania",
96
+ "Algeria",
97
+ "American Samoa",
98
+ "Andorra",
99
+ "Angola",
100
+ "Antarctica",
101
+ "Antigua And Barbuda",
102
+ "Argentina",
103
+ "Armenia",
104
+ "Aruba",
105
+ "Australia"
106
+ ]
107
+ actual = [
108
+ "Afghanistan",
109
+ "Aland Islands",
110
+ "Albania",
111
+ "Algeria",
112
+ "American Samoa",
113
+ "Andorra",
114
+ "Anguilla",
115
+ "Antarctica",
116
+ "Antigua And Barbuda",
117
+ "Argentina",
118
+ "Armenia",
119
+ "Aruba",
120
+ "Australia"
121
+ ]
122
+ expect(actual).to #{matcher}(expected)
123
+ TEST
124
+ program = make_plain_test_program(
125
+ snippet,
126
+ color_enabled: color_enabled,
127
+ configuration: {
128
+ diff_elision_enabled: false,
129
+ diff_elision_maximum: 3,
130
+ },
131
+ )
132
+
133
+ expected_output = build_expected_output(
134
+ color_enabled: color_enabled,
135
+ snippet: %|expect(actual).to #{matcher}(expected)|,
136
+ newline_before_expectation: true,
137
+ expectation: proc {
138
+ line do
139
+ plain "Expected "
140
+ # rubocop:disable Layout/LineLength
141
+ actual %|["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia"]|
142
+ # rubocop:enable Layout/LineLength
143
+ end
144
+
145
+ line do
146
+ plain " to eq "
147
+ # rubocop:disable Layout/LineLength
148
+ expected %|["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia"]|
149
+ # rubocop:enable Layout/LineLength
150
+ end
151
+ },
152
+ diff: proc {
153
+ plain_line %| [|
154
+ plain_line %| "Afghanistan",|
155
+ plain_line %| "Aland Islands",|
156
+ plain_line %| "Albania",|
157
+ plain_line %| "Algeria",|
158
+ plain_line %| "American Samoa",|
159
+ plain_line %| "Andorra",|
160
+ expected_line %|- "Angola",|
161
+ actual_line %|+ "Anguilla",|
162
+ plain_line %| "Antarctica",|
163
+ plain_line %| "Antigua And Barbuda",|
164
+ plain_line %| "Argentina",|
165
+ plain_line %| "Armenia",|
166
+ plain_line %| "Aruba",|
167
+ plain_line %| "Australia"|
168
+ plain_line %| ]|
169
+ },
170
+ )
171
+
172
+ expect(program).
173
+ to produce_output_when_run(expected_output).
174
+ in_color(color_enabled)
175
+ end
176
+ end
177
+ end
178
+ end
179
+
180
+ context "when comparing two one-dimensional data structures which feature a unchanged section flanked by changed sections" do
181
+ context "if diff_elision_enabled is set to true" do
182
+ it "elides the unchanged sections, preserving <maximum> number of lines within all unchanged sections (including the elision marker)" do
183
+ as_both_colored_and_uncolored do |color_enabled|
184
+ snippet = <<~TEST.strip
185
+ expected = [
186
+ "Afghanistan",
187
+ "Aland Islands",
188
+ "Albania",
189
+ "Algeria",
190
+ "American Samoa",
191
+ "Andorra",
192
+ "Angola",
193
+ "Anguilla",
194
+ "Antarctica",
195
+ "Antigua And Barbuda",
196
+ "Argentina",
197
+ "Armenia",
198
+ "Aruba",
199
+ "Australia"
200
+ ]
201
+ actual = [
202
+ "Zambia",
203
+ "Aland Islands",
204
+ "Albania",
205
+ "Algeria",
206
+ "American Samoa",
207
+ "Andorra",
208
+ "Angola",
209
+ "Anguilla",
210
+ "Antarctica",
211
+ "Antigua And Barbuda",
212
+ "Argentina",
213
+ "Armenia",
214
+ "Aruba",
215
+ "Zimbabwe"
216
+ ]
217
+ expect(actual).to #{matcher}(expected)
218
+ TEST
219
+ program = make_plain_test_program(
220
+ snippet,
221
+ color_enabled: color_enabled,
222
+ configuration: {
223
+ diff_elision_enabled: true,
224
+ diff_elision_maximum: 3,
225
+ },
226
+ )
227
+
228
+ expected_output = build_expected_output(
229
+ color_enabled: color_enabled,
230
+ snippet: %|expect(actual).to #{matcher}(expected)|,
231
+ newline_before_expectation: true,
232
+ expectation: proc {
233
+ line do
234
+ plain "Expected "
235
+ # rubocop:disable Layout/LineLength
236
+ actual %|["Zambia", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Zimbabwe"]|
237
+ # rubocop:enable Layout/LineLength
238
+ end
239
+
240
+ line do
241
+ plain " to eq "
242
+ # rubocop:disable Layout/LineLength
243
+ expected %|["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia"]|
244
+ # rubocop:enable Layout/LineLength
245
+ end
246
+ },
247
+ diff: proc {
248
+ plain_line %| [|
249
+ expected_line %|- "Afghanistan",|
250
+ actual_line %|+ "Zambia",|
251
+ plain_line %| "Aland Islands",|
252
+ elision_marker_line %| # ...|
253
+ plain_line %| "Aruba",|
254
+ expected_line %|- "Australia"|
255
+ actual_line %|+ "Zimbabwe"|
256
+ plain_line %| ]|
257
+ },
258
+ )
259
+
260
+ expect(program).
261
+ to produce_output_when_run(expected_output).
262
+ in_color(color_enabled)
263
+ end
264
+ end
265
+ end
266
+
267
+ context "if diff_elision_enabled is set to false" do
268
+ it "does not elide anything" do
269
+ as_both_colored_and_uncolored do |color_enabled|
270
+ snippet = <<~TEST.strip
271
+ expected = [
272
+ "Afghanistan",
273
+ "Aland Islands",
274
+ "Albania",
275
+ "Algeria",
276
+ "American Samoa",
277
+ "Andorra",
278
+ "Angola",
279
+ "Anguilla",
280
+ "Antarctica",
281
+ "Antigua And Barbuda",
282
+ "Argentina",
283
+ "Armenia",
284
+ "Aruba",
285
+ "Australia"
286
+ ]
287
+ actual = [
288
+ "Zambia",
289
+ "Aland Islands",
290
+ "Albania",
291
+ "Algeria",
292
+ "American Samoa",
293
+ "Andorra",
294
+ "Angola",
295
+ "Anguilla",
296
+ "Antarctica",
297
+ "Antigua And Barbuda",
298
+ "Argentina",
299
+ "Armenia",
300
+ "Aruba",
301
+ "Zimbabwe"
302
+ ]
303
+ expect(actual).to #{matcher}(expected)
304
+ TEST
305
+ program = make_plain_test_program(
306
+ snippet,
307
+ color_enabled: color_enabled,
308
+ configuration: {
309
+ diff_elision_enabled: false,
310
+ diff_elision_maximum: 3,
311
+ },
312
+ )
313
+
314
+ expected_output = build_expected_output(
315
+ color_enabled: color_enabled,
316
+ snippet: %|expect(actual).to #{matcher}(expected)|,
317
+ newline_before_expectation: true,
318
+ expectation: proc {
319
+ line do
320
+ plain "Expected "
321
+ # rubocop:disable Layout/LineLength
322
+ actual %|["Zambia", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Zimbabwe"]|
323
+ # rubocop:enable Layout/LineLength
324
+ end
325
+
326
+ line do
327
+ plain " to eq "
328
+ # rubocop:disable Layout/LineLength
329
+ expected %|["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia"]|
330
+ # rubocop:enable Layout/LineLength
331
+ end
332
+ },
333
+ diff: proc {
334
+ plain_line %| [|
335
+ expected_line %|- "Afghanistan",|
336
+ actual_line %|+ "Zambia",|
337
+ plain_line %| "Aland Islands",|
338
+ plain_line %| "Albania",|
339
+ plain_line %| "Algeria",|
340
+ plain_line %| "American Samoa",|
341
+ plain_line %| "Andorra",|
342
+ plain_line %| "Angola",|
343
+ plain_line %| "Anguilla",|
344
+ plain_line %| "Antarctica",|
345
+ plain_line %| "Antigua And Barbuda",|
346
+ plain_line %| "Argentina",|
347
+ plain_line %| "Armenia",|
348
+ plain_line %| "Aruba",|
349
+ expected_line %|- "Australia"|
350
+ actual_line %|+ "Zimbabwe"|
351
+ plain_line %| ]|
352
+ },
353
+ )
354
+
355
+ expect(program).
356
+ to produce_output_when_run(expected_output).
357
+ in_color(color_enabled)
358
+ end
359
+ end
360
+ end
361
+ end
362
+
363
+ context "when comparing two multi-dimensional data structures which feature large unchanged sections" do
364
+ context "if diff_elision_enabled is set to true" do
365
+ it "elides the unchanged sections, preserving <maximum> number of lines within all unchanged sections (including the elision marker)" do
366
+ # TODO see if we can correct the order of the keys here so it's not
367
+ # totally weird
368
+ as_both_colored_and_uncolored do |color_enabled|
369
+ snippet = <<~TEST.strip
370
+ expected = [
371
+ {
372
+ "user_id": "18949452",
373
+ "user": {
374
+ "id": 18949452,
375
+ "name": "Financial Times",
376
+ "screen_name": "FT",
377
+ "location": "London",
378
+ "entities": {
379
+ "url": {
380
+ "urls": [
381
+ {
382
+ "url": "http://t.co/dnhLQpd9BY",
383
+ "expanded_url": "http://www.ft.com/",
384
+ "display_url": "ft.com",
385
+ "indices": [
386
+ 0,
387
+ 22
388
+ ]
389
+ }
390
+ ]
391
+ },
392
+ "description": {
393
+ "urls": [
394
+ {
395
+ "url": "https://t.co/5BsmLs9y1Z",
396
+ "expanded_url": "http://FT.com",
397
+ "indices": [
398
+ 65,
399
+ 88
400
+ ]
401
+ }
402
+ ]
403
+ }
404
+ },
405
+ "listed_count": 37009,
406
+ "created_at": "Tue Jan 13 19:28:24 +0000 2009",
407
+ "favourites_count": 38,
408
+ "utc_offset": nil,
409
+ "time_zone": nil,
410
+ "geo_enabled": false,
411
+ "verified": true,
412
+ "statuses_count": 273860,
413
+ "media_count": 51044,
414
+ "contributors_enabled": false,
415
+ "is_translator": false,
416
+ "is_translation_enabled": false,
417
+ "profile_background_color": "FFF1E0",
418
+ "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
419
+ "profile_background_tile": false,
420
+ "profile_image_url": "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",
421
+ "profile_image_url_https": "https://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",
422
+ "profile_banner_url": "https://pbs.twimg.com/profile_banners/18949452/1581526592",
423
+ "profile_image_extensions": {
424
+ "mediaStats": {
425
+ "r": {
426
+ "missing": nil
427
+ },
428
+ "ttl": -1
429
+ }
430
+ },
431
+ "profile_banner_extensions": {},
432
+ "blocking": false,
433
+ "blocked_by": false,
434
+ "want_retweets": false,
435
+ "advertiser_account_type": "none",
436
+ "advertiser_account_service_levels": [],
437
+ "profile_interstitial_type": "",
438
+ "business_profile_state": "none",
439
+ "translator_type": "none",
440
+ "followed_by": false,
441
+ "ext": {
442
+ "highlightedLabel": {
443
+ "ttl": -1
444
+ }
445
+ },
446
+ "require_some_consent": false
447
+ },
448
+ "token": "117"
449
+ }
450
+ ]
451
+ actual = [
452
+ {
453
+ "user_id": "18949452",
454
+ "user": {
455
+ "id": 18949452,
456
+ "name": "Financial Times",
457
+ "screen_name": "FT",
458
+ "location": "London",
459
+ "url": "http://t.co/dnhLQpd9BY",
460
+ "entities": {
461
+ "url": {
462
+ "urls": [
463
+ {
464
+ "url": "http://t.co/dnhLQpd9BY",
465
+ "expanded_url": "http://www.ft.com/",
466
+ "display_url": "ft.com",
467
+ "indices": [
468
+ 0,
469
+ 22
470
+ ]
471
+ }
472
+ ]
473
+ },
474
+ "description": {
475
+ "urls": [
476
+ {
477
+ "url": "https://t.co/5BsmLs9y1Z",
478
+ "display_url": "FT.com",
479
+ "indices": [
480
+ 65,
481
+ 88
482
+ ]
483
+ }
484
+ ]
485
+ }
486
+ },
487
+ "protected": false,
488
+ "listed_count": 37009,
489
+ "created_at": "Tue Jan 13 19:28:24 +0000 2009",
490
+ "favourites_count": 38,
491
+ "utc_offset": nil,
492
+ "time_zone": nil,
493
+ "geo_enabled": false,
494
+ "verified": true,
495
+ "statuses_count": 273860,
496
+ "media_count": 51044,
497
+ "contributors_enabled": false,
498
+ "is_translator": false,
499
+ "is_translation_enabled": false,
500
+ "profile_background_color": "FFF1E0",
501
+ "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
502
+ "profile_image_url_https": "https://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",
503
+ "profile_banner_url": "https://pbs.twimg.com/profile_banners/18949452/1581526592",
504
+ "profile_image_extensions": {
505
+ "mediaStats": {
506
+ "r": {
507
+ "missing": nil
508
+ },
509
+ "ttl": -1
510
+ }
511
+ },
512
+ "profile_banner_extensions": {},
513
+ "blocking": false,
514
+ "blocked_by": false,
515
+ "want_retweets": false,
516
+ "advertiser_account_type": "none",
517
+ "profile_interstitial_type": "",
518
+ "business_profile_state": "none",
519
+ "translator_type": "none",
520
+ "followed_by": false,
521
+ "ext": {
522
+ "highlightedLabel": {
523
+ "ttl": -1
524
+ }
525
+ },
526
+ "require_some_consent": false
527
+ },
528
+ "token": "117"
529
+ }
530
+ ]
531
+ expect(actual).to #{matcher}(expected)
532
+ TEST
533
+ program = make_plain_test_program(
534
+ snippet,
535
+ color_enabled: color_enabled,
536
+ configuration: {
537
+ diff_elision_enabled: true,
538
+ diff_elision_maximum: 10,
539
+ },
540
+ )
541
+
542
+ expected_output = build_expected_output(
543
+ color_enabled: color_enabled,
544
+ snippet: %|expect(actual).to #{matcher}(expected)|,
545
+ newline_before_expectation: true,
546
+ expectation: proc {
547
+ line do
548
+ plain "Expected "
549
+ # rubocop:disable Layout/LineLength
550
+ actual %<[{ user_id: "18949452", user: { id: 18949452, name: "Financial Times", screen_name: "FT", location: "London", url: "http://t.co/dnhLQpd9BY", entities: { url: { urls: [{ url: "http://t.co/dnhLQpd9BY", expanded_url: "http://www.ft.com/", display_url: "ft.com", indices: [0, 22] }] }, description: { urls: [{ url: "https://t.co/5BsmLs9y1Z", display_url: "FT.com", indices: [65, 88] }] } }, protected: false, listed_count: 37009, created_at: "Tue Jan 13 19:28:24 +0000 2009", favourites_count: 38, utc_offset: nil, time_zone: nil, geo_enabled: false, verified: true, statuses_count: 273860, media_count: 51044, contributors_enabled: false, is_translator: false, is_translation_enabled: false, profile_background_color: "FFF1E0", profile_background_image_url: "http://abs.twimg.com/images/themes/theme1/bg.png", profile_image_url_https: "https://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg", profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592", profile_image_extensions: { mediaStats: { r: { missing: nil }, ttl: -1 } }, profile_banner_extensions: {}, blocking: false, blocked_by: false, want_retweets: false, advertiser_account_type: "none", profile_interstitial_type: "", business_profile_state: "none", translator_type: "none", followed_by: false, ext: { highlightedLabel: { ttl: -1 } }, require_some_consent: false }, token: "117" }]>
551
+ # rubocop:enable Layout/LineLength
552
+ end
553
+
554
+ line do
555
+ plain " to eq "
556
+ # rubocop:disable Layout/LineLength
557
+ expected %<[{ user_id: "18949452", user: { id: 18949452, name: "Financial Times", screen_name: "FT", location: "London", entities: { url: { urls: [{ url: "http://t.co/dnhLQpd9BY", expanded_url: "http://www.ft.com/", display_url: "ft.com", indices: [0, 22] }] }, description: { urls: [{ url: "https://t.co/5BsmLs9y1Z", expanded_url: "http://FT.com", indices: [65, 88] }] } }, listed_count: 37009, created_at: "Tue Jan 13 19:28:24 +0000 2009", favourites_count: 38, utc_offset: nil, time_zone: nil, geo_enabled: false, verified: true, statuses_count: 273860, media_count: 51044, contributors_enabled: false, is_translator: false, is_translation_enabled: false, profile_background_color: "FFF1E0", profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png", profile_background_tile: false, profile_image_url: "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg", profile_image_url_https: "https://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg", profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592", profile_image_extensions: { mediaStats: { r: { missing: nil }, ttl: -1 } }, profile_banner_extensions: {}, blocking: false, blocked_by: false, want_retweets: false, advertiser_account_type: "none", advertiser_account_service_levels: [], profile_interstitial_type: "", business_profile_state: "none", translator_type: "none", followed_by: false, ext: { highlightedLabel: { ttl: -1 } }, require_some_consent: false }, token: "117" }]>
558
+ # rubocop:enable Layout/LineLength
559
+ end
560
+ },
561
+ diff: proc {
562
+ plain_line %| [|
563
+ plain_line %| {|
564
+ plain_line %| user_id: "18949452",|
565
+ plain_line %| user: {|
566
+ plain_line %| id: 18949452,|
567
+ plain_line %| name: "Financial Times",|
568
+ plain_line %| screen_name: "FT",|
569
+ plain_line %| location: "London",|
570
+ actual_line %|+ url: "http://t.co/dnhLQpd9BY",|
571
+ plain_line %| entities: {|
572
+ plain_line %| url: {|
573
+ plain_line %| urls: [|
574
+ elision_marker_line %| # ...|
575
+ plain_line %| ]|
576
+ plain_line %| },|
577
+ plain_line %| description: {|
578
+ plain_line %| urls: [|
579
+ plain_line %| {|
580
+ elision_marker_line %| # ...|
581
+ expected_line %|- expanded_url: "http://FT.com",|
582
+ actual_line %|+ display_url: "FT.com",|
583
+ plain_line %| indices: [|
584
+ plain_line %| 65,|
585
+ plain_line %| 88|
586
+ plain_line %| ]|
587
+ plain_line %| }|
588
+ plain_line %| ]|
589
+ plain_line %| }|
590
+ plain_line %| },|
591
+ actual_line %|+ protected: false,|
592
+ elision_marker_line %| # ...|
593
+ expected_line %|- profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png",|
594
+ expected_line %|- profile_background_tile: false,|
595
+ expected_line %|- profile_image_url: "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",|
596
+ actual_line %|+ profile_background_image_url: "http://abs.twimg.com/images/themes/theme1/bg.png",|
597
+ plain_line %| profile_image_url_https: "https://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",|
598
+ plain_line %| profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592",|
599
+ plain_line %| profile_image_extensions: {|
600
+ elision_marker_line %| # ...|
601
+ plain_line %| },|
602
+ plain_line %| profile_banner_extensions: {},|
603
+ plain_line %| blocking: false,|
604
+ plain_line %| blocked_by: false,|
605
+ plain_line %| want_retweets: false,|
606
+ plain_line %| advertiser_account_type: "none",|
607
+ expected_line %|- advertiser_account_service_levels: [],|
608
+ elision_marker_line %| # ...|
609
+ plain_line %| },|
610
+ plain_line %| token: "117"|
611
+ plain_line %| }|
612
+ plain_line %| ]|
613
+ },
614
+ )
615
+
616
+ expect(program).
617
+ to produce_output_when_run(expected_output).
618
+ in_color(color_enabled)
619
+ end
620
+ end
621
+ end
622
+
623
+ context "if diff_elision_enabled is set to false" do
624
+ it "does not elide anything" do
625
+ as_both_colored_and_uncolored do |color_enabled|
626
+ snippet = <<~TEST.strip
627
+ expected = [
628
+ {
629
+ "user_id": "18949452",
630
+ "user": {
631
+ "id": 18949452,
632
+ "name": "Financial Times",
633
+ "screen_name": "FT",
634
+ "location": "London",
635
+ "entities": {
636
+ "url": {
637
+ "urls": [
638
+ {
639
+ "url": "http://t.co/dnhLQpd9BY",
640
+ "expanded_url": "http://www.ft.com/",
641
+ "display_url": "ft.com",
642
+ "indices": [
643
+ 0,
644
+ 22
645
+ ]
646
+ }
647
+ ]
648
+ },
649
+ "description": {
650
+ "urls": [
651
+ {
652
+ "url": "https://t.co/5BsmLs9y1Z",
653
+ "expanded_url": "http://FT.com",
654
+ "indices": [
655
+ 65,
656
+ 88
657
+ ]
658
+ }
659
+ ]
660
+ }
661
+ },
662
+ "listed_count": 37009,
663
+ "created_at": "Tue Jan 13 19:28:24 +0000 2009",
664
+ "favourites_count": 38,
665
+ "utc_offset": nil,
666
+ "time_zone": nil,
667
+ "geo_enabled": false,
668
+ "verified": true,
669
+ "statuses_count": 273860,
670
+ "media_count": 51044,
671
+ "contributors_enabled": false,
672
+ "is_translator": false,
673
+ "is_translation_enabled": false,
674
+ "profile_background_color": "FFF1E0",
675
+ "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
676
+ "profile_background_tile": false,
677
+ "profile_image_url": "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",
678
+ "profile_image_url_https": "https://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",
679
+ "profile_banner_url": "https://pbs.twimg.com/profile_banners/18949452/1581526592",
680
+ "profile_image_extensions": {
681
+ "mediaStats": {
682
+ "r": {
683
+ "missing": nil
684
+ },
685
+ "ttl": -1
686
+ }
687
+ },
688
+ "profile_banner_extensions": {},
689
+ "blocking": false,
690
+ "blocked_by": false,
691
+ "want_retweets": false,
692
+ "advertiser_account_type": "none",
693
+ "advertiser_account_service_levels": [],
694
+ "profile_interstitial_type": "",
695
+ "business_profile_state": "none",
696
+ "translator_type": "none",
697
+ "followed_by": false,
698
+ "ext": {
699
+ "highlightedLabel": {
700
+ "ttl": -1
701
+ }
702
+ },
703
+ "require_some_consent": false
704
+ },
705
+ "token": "117"
706
+ }
707
+ ]
708
+ actual = [
709
+ {
710
+ "user_id": "18949452",
711
+ "user": {
712
+ "id": 18949452,
713
+ "name": "Financial Times",
714
+ "screen_name": "FT",
715
+ "location": "London",
716
+ "url": "http://t.co/dnhLQpd9BY",
717
+ "entities": {
718
+ "url": {
719
+ "urls": [
720
+ {
721
+ "url": "http://t.co/dnhLQpd9BY",
722
+ "expanded_url": "http://www.ft.com/",
723
+ "display_url": "ft.com",
724
+ "indices": [
725
+ 0,
726
+ 22
727
+ ]
728
+ }
729
+ ]
730
+ },
731
+ "description": {
732
+ "urls": [
733
+ {
734
+ "url": "https://t.co/5BsmLs9y1Z",
735
+ "display_url": "FT.com",
736
+ "indices": [
737
+ 65,
738
+ 88
739
+ ]
740
+ }
741
+ ]
742
+ }
743
+ },
744
+ "protected": false,
745
+ "listed_count": 37009,
746
+ "created_at": "Tue Jan 13 19:28:24 +0000 2009",
747
+ "favourites_count": 38,
748
+ "utc_offset": nil,
749
+ "time_zone": nil,
750
+ "geo_enabled": false,
751
+ "verified": true,
752
+ "statuses_count": 273860,
753
+ "media_count": 51044,
754
+ "contributors_enabled": false,
755
+ "is_translator": false,
756
+ "is_translation_enabled": false,
757
+ "profile_background_color": "FFF1E0",
758
+ "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
759
+ "profile_image_url_https": "https://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",
760
+ "profile_banner_url": "https://pbs.twimg.com/profile_banners/18949452/1581526592",
761
+ "profile_image_extensions": {
762
+ "mediaStats": {
763
+ "r": {
764
+ "missing": nil
765
+ },
766
+ "ttl": -1
767
+ }
768
+ },
769
+ "profile_banner_extensions": {},
770
+ "blocking": false,
771
+ "blocked_by": false,
772
+ "want_retweets": false,
773
+ "advertiser_account_type": "none",
774
+ "profile_interstitial_type": "",
775
+ "business_profile_state": "none",
776
+ "translator_type": "none",
777
+ "followed_by": false,
778
+ "ext": {
779
+ "highlightedLabel": {
780
+ "ttl": -1
781
+ }
782
+ },
783
+ "require_some_consent": false
784
+ },
785
+ "token": "117"
786
+ }
787
+ ]
788
+ expect(actual).to #{matcher}(expected)
789
+ TEST
790
+ program = make_plain_test_program(
791
+ snippet,
792
+ color_enabled: color_enabled,
793
+ configuration: {
794
+ diff_elision_enabled: false,
795
+ diff_elision_maximum: 10,
796
+ },
797
+ )
798
+
799
+ expected_output = build_expected_output(
800
+ color_enabled: color_enabled,
801
+ snippet: %|expect(actual).to #{matcher}(expected)|,
802
+ newline_before_expectation: true,
803
+ expectation: proc {
804
+ line do
805
+ plain "Expected "
806
+ # rubocop:disable Layout/LineLength
807
+ actual %<[{ user_id: "18949452", user: { id: 18949452, name: "Financial Times", screen_name: "FT", location: "London", url: "http://t.co/dnhLQpd9BY", entities: { url: { urls: [{ url: "http://t.co/dnhLQpd9BY", expanded_url: "http://www.ft.com/", display_url: "ft.com", indices: [0, 22] }] }, description: { urls: [{ url: "https://t.co/5BsmLs9y1Z", display_url: "FT.com", indices: [65, 88] }] } }, protected: false, listed_count: 37009, created_at: "Tue Jan 13 19:28:24 +0000 2009", favourites_count: 38, utc_offset: nil, time_zone: nil, geo_enabled: false, verified: true, statuses_count: 273860, media_count: 51044, contributors_enabled: false, is_translator: false, is_translation_enabled: false, profile_background_color: "FFF1E0", profile_background_image_url: "http://abs.twimg.com/images/themes/theme1/bg.png", profile_image_url_https: "https://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg", profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592", profile_image_extensions: { mediaStats: { r: { missing: nil }, ttl: -1 } }, profile_banner_extensions: {}, blocking: false, blocked_by: false, want_retweets: false, advertiser_account_type: "none", profile_interstitial_type: "", business_profile_state: "none", translator_type: "none", followed_by: false, ext: { highlightedLabel: { ttl: -1 } }, require_some_consent: false }, token: "117" }]>
808
+ # rubocop:enable Layout/LineLength
809
+ end
810
+
811
+ line do
812
+ plain " to eq "
813
+ # rubocop:disable Layout/LineLength
814
+ expected %<[{ user_id: "18949452", user: { id: 18949452, name: "Financial Times", screen_name: "FT", location: "London", entities: { url: { urls: [{ url: "http://t.co/dnhLQpd9BY", expanded_url: "http://www.ft.com/", display_url: "ft.com", indices: [0, 22] }] }, description: { urls: [{ url: "https://t.co/5BsmLs9y1Z", expanded_url: "http://FT.com", indices: [65, 88] }] } }, listed_count: 37009, created_at: "Tue Jan 13 19:28:24 +0000 2009", favourites_count: 38, utc_offset: nil, time_zone: nil, geo_enabled: false, verified: true, statuses_count: 273860, media_count: 51044, contributors_enabled: false, is_translator: false, is_translation_enabled: false, profile_background_color: "FFF1E0", profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png", profile_background_tile: false, profile_image_url: "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg", profile_image_url_https: "https://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg", profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592", profile_image_extensions: { mediaStats: { r: { missing: nil }, ttl: -1 } }, profile_banner_extensions: {}, blocking: false, blocked_by: false, want_retweets: false, advertiser_account_type: "none", advertiser_account_service_levels: [], profile_interstitial_type: "", business_profile_state: "none", translator_type: "none", followed_by: false, ext: { highlightedLabel: { ttl: -1 } }, require_some_consent: false }, token: "117" }]>
815
+ # rubocop:enable Layout/LineLength
816
+ end
817
+ },
818
+ diff: proc {
819
+ plain_line %| [|
820
+ plain_line %| {|
821
+ plain_line %| user_id: "18949452",|
822
+ plain_line %| user: {|
823
+ plain_line %| id: 18949452,|
824
+ plain_line %| name: "Financial Times",|
825
+ plain_line %| screen_name: "FT",|
826
+ plain_line %| location: "London",|
827
+ actual_line %|+ url: "http://t.co/dnhLQpd9BY",|
828
+ plain_line %| entities: {|
829
+ plain_line %| url: {|
830
+ plain_line %| urls: [|
831
+ plain_line %| {|
832
+ plain_line %| url: "http://t.co/dnhLQpd9BY",|
833
+ plain_line %| expanded_url: "http://www.ft.com/",|
834
+ plain_line %| display_url: "ft.com",|
835
+ plain_line %| indices: [|
836
+ plain_line %| 0,|
837
+ plain_line %| 22|
838
+ plain_line %| ]|
839
+ plain_line %| }|
840
+ plain_line %| ]|
841
+ plain_line %| },|
842
+ plain_line %| description: {|
843
+ plain_line %| urls: [|
844
+ plain_line %| {|
845
+ plain_line %| url: "https://t.co/5BsmLs9y1Z",|
846
+ expected_line %|- expanded_url: "http://FT.com",|
847
+ actual_line %|+ display_url: "FT.com",|
848
+ plain_line %| indices: [|
849
+ plain_line %| 65,|
850
+ plain_line %| 88|
851
+ plain_line %| ]|
852
+ plain_line %| }|
853
+ plain_line %| ]|
854
+ plain_line %| }|
855
+ plain_line %| },|
856
+ actual_line %|+ protected: false,|
857
+ plain_line %| listed_count: 37009,|
858
+ plain_line %| created_at: "Tue Jan 13 19:28:24 +0000 2009",|
859
+ plain_line %| favourites_count: 38,|
860
+ plain_line %| utc_offset: nil,|
861
+ plain_line %| time_zone: nil,|
862
+ plain_line %| geo_enabled: false,|
863
+ plain_line %| verified: true,|
864
+ plain_line %| statuses_count: 273860,|
865
+ plain_line %| media_count: 51044,|
866
+ plain_line %| contributors_enabled: false,|
867
+ plain_line %| is_translator: false,|
868
+ plain_line %| is_translation_enabled: false,|
869
+ plain_line %| profile_background_color: "FFF1E0",|
870
+ expected_line %|- profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png",|
871
+ expected_line %|- profile_background_tile: false,|
872
+ expected_line %|- profile_image_url: "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",|
873
+ actual_line %|+ profile_background_image_url: "http://abs.twimg.com/images/themes/theme1/bg.png",|
874
+ plain_line %| profile_image_url_https: "https://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",|
875
+ plain_line %| profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592",|
876
+ plain_line %| profile_image_extensions: {|
877
+ plain_line %| mediaStats: {|
878
+ plain_line %| r: {|
879
+ plain_line %| missing: nil|
880
+ plain_line %| },|
881
+ plain_line %| ttl: -1|
882
+ plain_line %| }|
883
+ plain_line %| },|
884
+ plain_line %| profile_banner_extensions: {},|
885
+ plain_line %| blocking: false,|
886
+ plain_line %| blocked_by: false,|
887
+ plain_line %| want_retweets: false,|
888
+ plain_line %| advertiser_account_type: "none",|
889
+ expected_line %|- advertiser_account_service_levels: [],|
890
+ plain_line %| profile_interstitial_type: "",|
891
+ plain_line %| business_profile_state: "none",|
892
+ plain_line %| translator_type: "none",|
893
+ plain_line %| followed_by: false,|
894
+ plain_line %| ext: {|
895
+ plain_line %| highlightedLabel: {|
896
+ plain_line %| ttl: -1|
897
+ plain_line %| }|
898
+ plain_line %| },|
899
+ plain_line %| require_some_consent: false|
900
+ plain_line %| },|
901
+ plain_line %| token: "117"|
902
+ plain_line %| }|
903
+ plain_line %| ]|
904
+ },
905
+ )
906
+
907
+ expect(program).
908
+ to produce_output_when_run(expected_output).
909
+ in_color(color_enabled)
910
+ end
911
+ end
912
+ end
913
+ end
914
+ end