super_diff 0.9.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +65 -26
  3. data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -2
  4. data/lib/super_diff/active_record/differs.rb +1 -1
  5. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +22 -18
  6. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +14 -7
  7. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +2 -2
  8. data/lib/super_diff/active_record/object_inspection.rb +1 -1
  9. data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +1 -2
  10. data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -2
  11. data/lib/super_diff/active_record/operation_tree_builders.rb +2 -2
  12. data/lib/super_diff/active_record/operation_tree_flatteners.rb +1 -1
  13. data/lib/super_diff/active_record/operation_trees.rb +1 -1
  14. data/lib/super_diff/active_record.rb +7 -15
  15. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +5 -6
  16. data/lib/super_diff/active_support/differs.rb +1 -1
  17. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +20 -11
  18. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +46 -0
  19. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +5 -1
  20. data/lib/super_diff/active_support/object_inspection.rb +1 -1
  21. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
  22. data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
  23. data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
  24. data/lib/super_diff/active_support/operation_trees.rb +1 -1
  25. data/lib/super_diff/active_support.rb +6 -10
  26. data/lib/super_diff/colorized_document_extensions.rb +2 -4
  27. data/lib/super_diff/configuration.rb +14 -8
  28. data/lib/super_diff/csi/color.rb +4 -4
  29. data/lib/super_diff/csi/colorized_document.rb +12 -16
  30. data/lib/super_diff/csi/document.rb +8 -19
  31. data/lib/super_diff/csi/eight_bit_color.rb +19 -19
  32. data/lib/super_diff/csi/four_bit_color.rb +82 -31
  33. data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
  34. data/lib/super_diff/csi/uncolorized_document.rb +2 -6
  35. data/lib/super_diff/csi.rb +10 -14
  36. data/lib/super_diff/diff_formatters/collection.rb +35 -41
  37. data/lib/super_diff/differs/date_like.rb +15 -0
  38. data/lib/super_diff/differs/default_object.rb +1 -1
  39. data/lib/super_diff/differs/defaults.rb +2 -1
  40. data/lib/super_diff/differs/main.rb +2 -13
  41. data/lib/super_diff/differs.rb +1 -0
  42. data/lib/super_diff/equality_matchers/array.rb +10 -12
  43. data/lib/super_diff/equality_matchers/base.rb +1 -1
  44. data/lib/super_diff/equality_matchers/default.rb +2 -4
  45. data/lib/super_diff/equality_matchers/defaults.rb +1 -1
  46. data/lib/super_diff/equality_matchers/hash.rb +10 -12
  47. data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
  48. data/lib/super_diff/equality_matchers/primitive.rb +10 -12
  49. data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
  50. data/lib/super_diff/equality_matchers.rb +1 -1
  51. data/lib/super_diff/errors.rb +2 -6
  52. data/lib/super_diff/gem_version.rb +3 -3
  53. data/lib/super_diff/helpers.rb +10 -10
  54. data/lib/super_diff/implementation_checks.rb +2 -2
  55. data/lib/super_diff/line.rb +3 -3
  56. data/lib/super_diff/object_inspection/inspection_tree.rb +64 -73
  57. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +29 -14
  58. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +17 -13
  59. data/lib/super_diff/object_inspection/inspection_tree_builders/date_like.rb +51 -0
  60. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +43 -27
  61. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +2 -1
  62. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +35 -18
  63. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +3 -5
  64. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +30 -36
  65. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +13 -9
  66. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +11 -22
  67. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
  68. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
  69. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
  70. data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
  71. data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
  72. data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
  73. data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
  74. data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
  75. data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
  76. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
  77. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
  78. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
  79. data/lib/super_diff/object_inspection/nodes.rb +7 -7
  80. data/lib/super_diff/object_inspection.rb +3 -3
  81. data/lib/super_diff/operation_tree_builders/array.rb +12 -11
  82. data/lib/super_diff/operation_tree_builders/base.rb +17 -15
  83. data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
  84. data/lib/super_diff/operation_tree_builders/date_like.rb +15 -0
  85. data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
  86. data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
  87. data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
  88. data/lib/super_diff/operation_tree_builders/main.rb +4 -11
  89. data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
  90. data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
  91. data/lib/super_diff/operation_tree_builders.rb +2 -1
  92. data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
  93. data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
  94. data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
  95. data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
  96. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
  97. data/lib/super_diff/operation_tree_flatteners.rb +3 -3
  98. data/lib/super_diff/operation_trees/base.rb +3 -5
  99. data/lib/super_diff/operation_trees/default_object.rb +1 -3
  100. data/lib/super_diff/operations/binary_operation.rb +2 -2
  101. data/lib/super_diff/operations/unary_operation.rb +1 -1
  102. data/lib/super_diff/rails.rb +2 -1
  103. data/lib/super_diff/recursion_guard.rb +5 -4
  104. data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
  105. data/lib/super_diff/rspec/differ.rb +6 -13
  106. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
  107. data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
  108. data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
  109. data/lib/super_diff/rspec/differs.rb +3 -3
  110. data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
  111. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
  112. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
  113. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +2 -10
  114. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
  115. data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
  116. data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
  117. data/lib/super_diff/rspec/monkey_patches.rb +180 -123
  118. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +14 -7
  119. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +21 -13
  120. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +35 -36
  121. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +19 -0
  122. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +21 -15
  123. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +11 -10
  124. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +11 -10
  125. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +14 -7
  126. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +10 -11
  127. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +13 -9
  128. data/lib/super_diff/rspec/object_inspection.rb +1 -1
  129. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
  130. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
  131. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
  132. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
  133. data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
  134. data/lib/super_diff/rspec.rb +17 -18
  135. data/lib/super_diff/tiered_lines_elider.rb +87 -115
  136. data/lib/super_diff/tiered_lines_formatter.rb +5 -9
  137. data/lib/super_diff/version.rb +1 -1
  138. data/lib/super_diff.rb +13 -9
  139. data/spec/examples.txt +541 -483
  140. data/spec/integration/rails/active_record_spec.rb +3 -1
  141. data/spec/integration/rails/engines_spec.rb +25 -0
  142. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
  143. data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
  144. data/spec/integration/rspec/be_matcher_spec.rb +360 -320
  145. data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
  146. data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
  147. data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
  148. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +257 -254
  149. data/spec/integration/rspec/eq_matcher_spec.rb +695 -585
  150. data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
  151. data/spec/integration/rspec/have_attributes_matcher_spec.rb +312 -304
  152. data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
  153. data/spec/integration/rspec/include_matcher_spec.rb +327 -225
  154. data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
  155. data/spec/integration/rspec/match_array_matcher_spec.rb +294 -291
  156. data/spec/integration/rspec/match_matcher_spec.rb +916 -903
  157. data/spec/integration/rspec/raise_error_matcher_spec.rb +1208 -449
  158. data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
  159. data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
  160. data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
  161. data/spec/internal/log/test.log +0 -0
  162. data/spec/spec_helper.rb +20 -20
  163. data/spec/support/command_runner.rb +34 -57
  164. data/spec/support/integration/helpers.rb +44 -32
  165. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
  166. data/spec/support/integration/matchers.rb +34 -0
  167. data/spec/support/integration/test_programs/base.rb +17 -22
  168. data/spec/support/integration/test_programs/plain.rb +6 -0
  169. data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
  170. data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
  171. data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
  172. data/spec/support/integration/test_programs/rspec_rails_engine.rb +20 -0
  173. data/spec/support/models/active_record/person.rb +6 -4
  174. data/spec/support/models/active_record/shipping_address.rb +9 -10
  175. data/spec/support/models/customer.rb +2 -4
  176. data/spec/support/models/player.rb +3 -6
  177. data/spec/support/models/shipping_address.rb +4 -13
  178. data/spec/support/shared_examples/active_record.rb +258 -240
  179. data/spec/support/shared_examples/active_support.rb +174 -51
  180. data/spec/support/shared_examples/elided_diffs.rb +447 -423
  181. data/spec/support/shared_examples/hash_with_indifferent_access.rb +500 -464
  182. data/spec/support/shared_examples/key.rb +123 -0
  183. data/spec/support/unit/helpers.rb +1 -3
  184. data/spec/support/unit/matchers/match_output.rb +12 -13
  185. data/spec/unit/active_record/object_inspection_spec.rb +222 -206
  186. data/spec/unit/active_support/object_inspection_spec.rb +170 -0
  187. data/spec/unit/equality_matchers/main_spec.rb +1049 -984
  188. data/spec/unit/helpers_spec.rb +14 -21
  189. data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
  190. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
  191. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
  192. data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
  193. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
  194. data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
  195. data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
  196. data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
  197. data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
  198. data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
  199. data/spec/unit/rspec/matchers/include_spec.rb +2 -2
  200. data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
  201. data/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
  202. data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
  203. data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
  204. data/spec/unit/rspec/object_inspection_spec.rb +351 -326
  205. data/spec/unit/super_diff_spec.rb +1594 -1437
  206. data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
  207. data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
  208. data/super_diff.gemspec +13 -12
  209. metadata +88 -75
  210. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +0 -21
  211. data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +0 -22
  212. data/spec/tmp/warnings_logger/all_warnings.txt +0 -2
@@ -4,54 +4,57 @@ shared_examples_for "integration with ActiveRecord" do
4
4
  it "produces the correct output" do
5
5
  as_both_colored_and_uncolored do |color_enabled|
6
6
  snippet = <<~TEST.strip
7
+ actual = SuperDiff::Test::Models::ActiveRecord::ShippingAddress.new(
8
+ line_1: "456 Ponderosa Ct.",
9
+ city: "Oakland",
10
+ state: "CA",
11
+ zip: "91234",
12
+ )
7
13
  expected = SuperDiff::Test::Models::ActiveRecord::ShippingAddress.new(
8
14
  line_1: "123 Main St.",
9
15
  city: "Hill Valley",
10
16
  state: "CA",
11
17
  zip: "90382",
12
18
  )
13
- actual = SuperDiff::Test::Models::ActiveRecord::ShippingAddress.new(
14
- line_1: "456 Ponderosa Ct.",
15
- city: "Oakland",
16
- state: "CA",
17
- zip: "91234",
18
- )
19
19
  expect(actual).to eq(expected)
20
20
  TEST
21
21
  program = make_program(snippet, color_enabled: color_enabled)
22
22
 
23
- expected_output = build_expected_output(
24
- color_enabled: color_enabled,
25
- snippet: "expect(actual).to eq(expected)",
26
- expectation: proc {
27
- line do
28
- plain %|Expected |
29
- actual %|#<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: nil, city: "Oakland", line_1: "456 Ponderosa Ct.", line_2: "", state: "CA", zip: "91234">|
30
- end
23
+ expected_output =
24
+ build_expected_output(
25
+ color_enabled: color_enabled,
26
+ snippet: "expect(actual).to eq(expected)",
27
+ expectation:
28
+ proc do
29
+ line do
30
+ plain "Expected "
31
+ actual %|#<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: nil, city: "Oakland", line_1: "456 Ponderosa Ct.", line_2: "", state: "CA", zip: "91234">|
32
+ end
31
33
 
32
- line do
33
- plain %| to eq |
34
- expected %|#<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: nil, city: "Hill Valley", line_1: "123 Main St.", line_2: "", state: "CA", zip: "90382">|
35
- end
36
- },
37
- diff: proc {
38
- plain_line %| #<SuperDiff::Test::Models::ActiveRecord::ShippingAddress {|
39
- plain_line %| id: nil,|
40
- expected_line %|- city: "Hill Valley",|
41
- actual_line %|+ city: "Oakland",|
42
- expected_line %|- line_1: "123 Main St.",|
43
- actual_line %|+ line_1: "456 Ponderosa Ct.",|
44
- plain_line %| line_2: "",|
45
- plain_line %| state: "CA",|
46
- expected_line %|- zip: "90382"|
47
- actual_line %|+ zip: "91234"|
48
- plain_line %| }>|
49
- },
50
- )
34
+ line do
35
+ plain " to eq "
36
+ expected %|#<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: nil, city: "Hill Valley", line_1: "123 Main St.", line_2: "", state: "CA", zip: "90382">|
37
+ end
38
+ end,
39
+ diff:
40
+ proc do
41
+ plain_line " #<SuperDiff::Test::Models::ActiveRecord::ShippingAddress {"
42
+ plain_line " id: nil,"
43
+ expected_line %|- city: "Hill Valley",|
44
+ actual_line %|+ city: "Oakland",|
45
+ expected_line %|- line_1: "123 Main St.",|
46
+ actual_line %|+ line_1: "456 Ponderosa Ct.",|
47
+ plain_line %| line_2: "",|
48
+ plain_line %| state: "CA",|
49
+ expected_line %|- zip: "90382"|
50
+ actual_line %|+ zip: "91234"|
51
+ plain_line " }>"
52
+ end
53
+ )
51
54
 
52
- expect(program).
53
- to produce_output_when_run(expected_output).
54
- in_color(color_enabled)
55
+ expect(program).to produce_output_when_run(expected_output).in_color(
56
+ color_enabled
57
+ )
55
58
  end
56
59
  end
57
60
  end
@@ -60,40 +63,42 @@ shared_examples_for "integration with ActiveRecord" do
60
63
  it "produces the correct output" do
61
64
  as_both_colored_and_uncolored do |color_enabled|
62
65
  snippet = <<~TEST.strip
66
+ actual = SuperDiff::Test::Models::ActiveRecord::Person.new(
67
+ name: "Elliot",
68
+ age: 31,
69
+ )
63
70
  expected = SuperDiff::Test::Models::ActiveRecord::ShippingAddress.new(
64
71
  line_1: "123 Main St.",
65
72
  city: "Hill Valley",
66
73
  state: "CA",
67
74
  zip: "90382",
68
75
  )
69
- actual = SuperDiff::Test::Models::ActiveRecord::Person.new(
70
- name: "Elliot",
71
- age: 31,
72
- )
73
76
  expect(actual).to eq(expected)
74
77
  TEST
75
78
  program = make_program(snippet, color_enabled: color_enabled)
76
79
 
77
- expected_output = build_expected_output(
78
- color_enabled: color_enabled,
79
- snippet: "expect(actual).to eq(expected)",
80
- newline_before_expectation: true,
81
- expectation: proc {
82
- line do
83
- plain %|Expected |
84
- actual %|#<SuperDiff::Test::Models::ActiveRecord::Person id: nil, age: 31, name: "Elliot">|
85
- end
80
+ expected_output =
81
+ build_expected_output(
82
+ color_enabled: color_enabled,
83
+ snippet: "expect(actual).to eq(expected)",
84
+ newline_before_expectation: true,
85
+ expectation:
86
+ proc do
87
+ line do
88
+ plain "Expected "
89
+ actual %|#<SuperDiff::Test::Models::ActiveRecord::Person id: nil, age: 31, name: "Elliot">|
90
+ end
86
91
 
87
- line do
88
- plain %| to eq |
89
- expected %|#<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: nil, city: "Hill Valley", line_1: "123 Main St.", line_2: "", state: "CA", zip: "90382">|
90
- end
91
- },
92
- )
92
+ line do
93
+ plain " to eq "
94
+ expected %|#<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: nil, city: "Hill Valley", line_1: "123 Main St.", line_2: "", state: "CA", zip: "90382">|
95
+ end
96
+ end
97
+ )
93
98
 
94
- expect(program).
95
- to produce_output_when_run(expected_output).
96
- in_color(color_enabled)
99
+ expect(program).to produce_output_when_run(expected_output).in_color(
100
+ color_enabled
101
+ )
97
102
  end
98
103
  end
99
104
  end
@@ -102,37 +107,39 @@ shared_examples_for "integration with ActiveRecord" do
102
107
  it "produces the correct output" do
103
108
  as_both_colored_and_uncolored do |color_enabled|
104
109
  snippet = <<~TEST.strip
110
+ actual = nil
105
111
  expected = SuperDiff::Test::Models::ActiveRecord::ShippingAddress.new(
106
112
  line_1: "123 Main St.",
107
113
  city: "Hill Valley",
108
114
  state: "CA",
109
115
  zip: "90382"
110
116
  )
111
- actual = nil
112
117
  expect(actual).to eq(expected)
113
118
  TEST
114
119
  program = make_program(snippet, color_enabled: color_enabled)
115
120
 
116
- expected_output = build_expected_output(
117
- color_enabled: color_enabled,
118
- snippet: "expect(actual).to eq(expected)",
119
- newline_before_expectation: true,
120
- expectation: proc {
121
- line do
122
- plain %|Expected |
123
- actual %|nil|
124
- end
121
+ expected_output =
122
+ build_expected_output(
123
+ color_enabled: color_enabled,
124
+ snippet: "expect(actual).to eq(expected)",
125
+ newline_before_expectation: true,
126
+ expectation:
127
+ proc do
128
+ line do
129
+ plain "Expected "
130
+ actual "nil"
131
+ end
125
132
 
126
- line do
127
- plain %| to eq |
128
- expected %|#<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: nil, city: "Hill Valley", line_1: "123 Main St.", line_2: "", state: "CA", zip: "90382">|
129
- end
130
- },
131
- )
133
+ line do
134
+ plain " to eq "
135
+ expected %|#<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: nil, city: "Hill Valley", line_1: "123 Main St.", line_2: "", state: "CA", zip: "90382">|
136
+ end
137
+ end
138
+ )
132
139
 
133
- expect(program).
134
- to produce_output_when_run(expected_output).
135
- in_color(color_enabled)
140
+ expect(program).to produce_output_when_run(expected_output).in_color(
141
+ color_enabled
142
+ )
136
143
  end
137
144
  end
138
145
  end
@@ -141,63 +148,66 @@ shared_examples_for "integration with ActiveRecord" do
141
148
  it "produces the correct output" do
142
149
  as_both_colored_and_uncolored do |color_enabled|
143
150
  snippet = <<~TEST.strip
144
- expected = {
151
+ actual = {
145
152
  name: "Marty McFly",
146
153
  shipping_address: SuperDiff::Test::Models::ActiveRecord::ShippingAddress.new(
147
- line_1: "123 Main St.",
148
- city: "Hill Valley",
154
+ line_1: "456 Ponderosa Ct.",
155
+ city: "Oakland",
149
156
  state: "CA",
150
- zip: "90382",
157
+ zip: "91234",
151
158
  )
152
159
  }
153
- actual = {
160
+ expected = {
154
161
  name: "Marty McFly",
155
162
  shipping_address: SuperDiff::Test::Models::ActiveRecord::ShippingAddress.new(
156
- line_1: "456 Ponderosa Ct.",
157
- city: "Oakland",
163
+ line_1: "123 Main St.",
164
+ city: "Hill Valley",
158
165
  state: "CA",
159
- zip: "91234",
166
+ zip: "90382",
160
167
  )
161
168
  }
162
169
  expect(actual).to eq(expected)
163
170
  TEST
164
171
  program = make_program(snippet, color_enabled: color_enabled)
165
172
 
166
- expected_output = build_expected_output(
167
- color_enabled: color_enabled,
168
- snippet: "expect(actual).to eq(expected)",
169
- expectation: proc {
170
- line do
171
- plain %|Expected |
172
- actual %|{ name: "Marty McFly", shipping_address: #<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: nil, city: "Oakland", line_1: "456 Ponderosa Ct.", line_2: "", state: "CA", zip: "91234"> }|
173
- end
173
+ expected_output =
174
+ build_expected_output(
175
+ color_enabled: color_enabled,
176
+ snippet: "expect(actual).to eq(expected)",
177
+ expectation:
178
+ proc do
179
+ line do
180
+ plain "Expected "
181
+ actual %|{ name: "Marty McFly", shipping_address: #<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: nil, city: "Oakland", line_1: "456 Ponderosa Ct.", line_2: "", state: "CA", zip: "91234"> }|
182
+ end
174
183
 
175
- line do
176
- plain %| to eq |
177
- expected %|{ name: "Marty McFly", shipping_address: #<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: nil, city: "Hill Valley", line_1: "123 Main St.", line_2: "", state: "CA", zip: "90382"> }|
178
- end
179
- },
180
- diff: proc {
181
- plain_line %| {|
182
- plain_line %| name: "Marty McFly",|
183
- plain_line %| shipping_address: #<SuperDiff::Test::Models::ActiveRecord::ShippingAddress {|
184
- plain_line %| id: nil,|
185
- expected_line %|- city: "Hill Valley",|
186
- actual_line %|+ city: "Oakland",|
187
- expected_line %|- line_1: "123 Main St.",|
188
- actual_line %|+ line_1: "456 Ponderosa Ct.",|
189
- plain_line %| line_2: "",|
190
- plain_line %| state: "CA",|
191
- expected_line %|- zip: "90382"|
192
- actual_line %|+ zip: "91234"|
193
- plain_line %| }>|
194
- plain_line %| }|
195
- },
196
- )
184
+ line do
185
+ plain " to eq "
186
+ expected %|{ name: "Marty McFly", shipping_address: #<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: nil, city: "Hill Valley", line_1: "123 Main St.", line_2: "", state: "CA", zip: "90382"> }|
187
+ end
188
+ end,
189
+ diff:
190
+ proc do
191
+ plain_line " {"
192
+ plain_line %| name: "Marty McFly",|
193
+ plain_line " shipping_address: #<SuperDiff::Test::Models::ActiveRecord::ShippingAddress {"
194
+ plain_line " id: nil,"
195
+ expected_line %|- city: "Hill Valley",|
196
+ actual_line %|+ city: "Oakland",|
197
+ expected_line %|- line_1: "123 Main St.",|
198
+ actual_line %|+ line_1: "456 Ponderosa Ct.",|
199
+ plain_line %| line_2: "",|
200
+ plain_line %| state: "CA",|
201
+ expected_line %|- zip: "90382"|
202
+ actual_line %|+ zip: "91234"|
203
+ plain_line " }>"
204
+ plain_line " }"
205
+ end
206
+ )
197
207
 
198
- expect(program).
199
- to produce_output_when_run(expected_output).
200
- in_color(color_enabled)
208
+ expect(program).to produce_output_when_run(expected_output).in_color(
209
+ color_enabled
210
+ )
201
211
  end
202
212
  end
203
213
  end
@@ -206,6 +216,13 @@ shared_examples_for "integration with ActiveRecord" do
206
216
  it "produces the correct output" do
207
217
  as_both_colored_and_uncolored do |color_enabled|
208
218
  snippet = <<~TEST.strip
219
+ actual = {
220
+ name: "Marty McFly",
221
+ shipping_address: SuperDiff::Test::Models::ActiveRecord::Person.new(
222
+ name: "Elliot",
223
+ age: 31,
224
+ )
225
+ }
209
226
  expected = {
210
227
  name: "Marty McFly",
211
228
  shipping_address: SuperDiff::Test::Models::ActiveRecord::ShippingAddress.new(
@@ -215,54 +232,50 @@ shared_examples_for "integration with ActiveRecord" do
215
232
  zip: "90382",
216
233
  )
217
234
  }
218
- actual = {
219
- name: "Marty McFly",
220
- shipping_address: SuperDiff::Test::Models::ActiveRecord::Person.new(
221
- name: "Elliot",
222
- age: 31,
223
- )
224
- }
225
235
  expect(actual).to eq(expected)
226
236
  TEST
227
237
  program = make_program(snippet, color_enabled: color_enabled)
228
238
 
229
- expected_output = build_expected_output(
230
- color_enabled: color_enabled,
231
- snippet: "expect(actual).to eq(expected)",
232
- expectation: proc {
233
- line do
234
- plain %|Expected |
235
- actual %|{ name: "Marty McFly", shipping_address: #<SuperDiff::Test::Models::ActiveRecord::Person id: nil, age: 31, name: "Elliot"> }|
236
- end
239
+ expected_output =
240
+ build_expected_output(
241
+ color_enabled: color_enabled,
242
+ snippet: "expect(actual).to eq(expected)",
243
+ expectation:
244
+ proc do
245
+ line do
246
+ plain "Expected "
247
+ actual %|{ name: "Marty McFly", shipping_address: #<SuperDiff::Test::Models::ActiveRecord::Person id: nil, age: 31, name: "Elliot"> }|
248
+ end
237
249
 
238
- line do
239
- plain %| to eq |
240
- expected %|{ name: "Marty McFly", shipping_address: #<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: nil, city: "Hill Valley", line_1: "123 Main St.", line_2: "", state: "CA", zip: "90382"> }|
241
- end
242
- },
243
- diff: proc {
244
- plain_line %| {|
245
- plain_line %| name: "Marty McFly",|
246
- expected_line %|- shipping_address: #<SuperDiff::Test::Models::ActiveRecord::ShippingAddress {|
247
- expected_line %|- id: nil,|
248
- expected_line %|- city: "Hill Valley",|
249
- expected_line %|- line_1: "123 Main St.",|
250
- expected_line %|- line_2: "",|
251
- expected_line %|- state: "CA",|
252
- expected_line %|- zip: "90382"|
253
- expected_line %|- }>|
254
- actual_line %|+ shipping_address: #<SuperDiff::Test::Models::ActiveRecord::Person {|
255
- actual_line %|+ id: nil,|
256
- actual_line %|+ age: 31,|
257
- actual_line %|+ name: "Elliot"|
258
- actual_line %|+ }>|
259
- plain_line %| }|
260
- },
261
- )
250
+ line do
251
+ plain " to eq "
252
+ expected %|{ name: "Marty McFly", shipping_address: #<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: nil, city: "Hill Valley", line_1: "123 Main St.", line_2: "", state: "CA", zip: "90382"> }|
253
+ end
254
+ end,
255
+ diff:
256
+ proc do
257
+ plain_line " {"
258
+ plain_line %| name: "Marty McFly",|
259
+ expected_line "- shipping_address: #<SuperDiff::Test::Models::ActiveRecord::ShippingAddress {"
260
+ expected_line "- id: nil,"
261
+ expected_line %|- city: "Hill Valley",|
262
+ expected_line %|- line_1: "123 Main St.",|
263
+ expected_line %|- line_2: "",|
264
+ expected_line %|- state: "CA",|
265
+ expected_line %|- zip: "90382"|
266
+ expected_line "- }>"
267
+ actual_line "+ shipping_address: #<SuperDiff::Test::Models::ActiveRecord::Person {"
268
+ actual_line "+ id: nil,"
269
+ actual_line "+ age: 31,"
270
+ actual_line %|+ name: "Elliot"|
271
+ actual_line "+ }>"
272
+ plain_line " }"
273
+ end
274
+ )
262
275
 
263
- expect(program).
264
- to produce_output_when_run(expected_output).
265
- in_color(color_enabled)
276
+ expect(program).to produce_output_when_run(expected_output).in_color(
277
+ color_enabled
278
+ )
266
279
  end
267
280
  end
268
281
  end
@@ -286,51 +299,54 @@ shared_examples_for "integration with ActiveRecord" do
286
299
  zip: "91234",
287
300
  )
288
301
  ]
302
+ actual = SuperDiff::Test::Models::ActiveRecord::ShippingAddress.all
289
303
  expected = [shipping_addresses.first]
290
- actual = SuperDiff::Test::Models::ActiveRecord::ShippingAddress.all
291
304
  expect(actual).to eq(expected)
292
305
  TEST
293
306
  program = make_program(snippet, color_enabled: color_enabled)
294
307
 
295
- expected_output = build_expected_output(
296
- color_enabled: color_enabled,
297
- snippet: "expect(actual).to eq(expected)",
298
- expectation: proc {
299
- line do
300
- plain %|Expected |
301
- actual %|#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: 1, city: "Hill Valley", line_1: "123 Main St.", line_2: "", state: "CA", zip: "90382">, #<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: 2, city: "Oakland", line_1: "456 Ponderosa Ct.", line_2: "", state: "CA", zip: "91234">]>|
302
- end
308
+ expected_output =
309
+ build_expected_output(
310
+ color_enabled: color_enabled,
311
+ snippet: "expect(actual).to eq(expected)",
312
+ expectation:
313
+ proc do
314
+ line do
315
+ plain "Expected "
316
+ actual %|#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: 1, city: "Hill Valley", line_1: "123 Main St.", line_2: "", state: "CA", zip: "90382">, #<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: 2, city: "Oakland", line_1: "456 Ponderosa Ct.", line_2: "", state: "CA", zip: "91234">]>|
317
+ end
303
318
 
304
- line do
305
- plain %| to eq |
306
- expected %|[#<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: 1, city: "Hill Valley", line_1: "123 Main St.", line_2: "", state: "CA", zip: "90382">]|
307
- end
308
- },
309
- diff: proc {
310
- plain_line %| #<ActiveRecord::Relation [|
311
- plain_line %| #<SuperDiff::Test::Models::ActiveRecord::ShippingAddress {|
312
- plain_line %| id: 1,|
313
- plain_line %| city: "Hill Valley",|
314
- plain_line %| line_1: "123 Main St.",|
315
- plain_line %| line_2: "",|
316
- plain_line %| state: "CA",|
317
- plain_line %| zip: "90382"|
318
- plain_line %| }>,|
319
- actual_line %|+ #<SuperDiff::Test::Models::ActiveRecord::ShippingAddress {|
320
- actual_line %|+ id: 2,|
321
- actual_line %|+ city: "Oakland",|
322
- actual_line %|+ line_1: "456 Ponderosa Ct.",|
323
- actual_line %|+ line_2: "",|
324
- actual_line %|+ state: "CA",|
325
- actual_line %|+ zip: "91234"|
326
- actual_line %|+ }>|
327
- plain_line %| ]>|
328
- },
329
- )
319
+ line do
320
+ plain " to eq "
321
+ expected %|[#<SuperDiff::Test::Models::ActiveRecord::ShippingAddress id: 1, city: "Hill Valley", line_1: "123 Main St.", line_2: "", state: "CA", zip: "90382">]|
322
+ end
323
+ end,
324
+ diff:
325
+ proc do
326
+ plain_line " #<ActiveRecord::Relation ["
327
+ plain_line " #<SuperDiff::Test::Models::ActiveRecord::ShippingAddress {"
328
+ plain_line " id: 1,"
329
+ plain_line %| city: "Hill Valley",|
330
+ plain_line %| line_1: "123 Main St.",|
331
+ plain_line %| line_2: "",|
332
+ plain_line %| state: "CA",|
333
+ plain_line %| zip: "90382"|
334
+ plain_line " }>,"
335
+ actual_line "+ #<SuperDiff::Test::Models::ActiveRecord::ShippingAddress {"
336
+ actual_line "+ id: 2,"
337
+ actual_line %|+ city: "Oakland",|
338
+ actual_line %|+ line_1: "456 Ponderosa Ct.",|
339
+ actual_line %|+ line_2: "",|
340
+ actual_line %|+ state: "CA",|
341
+ actual_line %|+ zip: "91234"|
342
+ actual_line "+ }>"
343
+ plain_line " ]>"
344
+ end
345
+ )
330
346
 
331
- expect(program).
332
- to produce_output_when_run(expected_output).
333
- in_color(color_enabled)
347
+ expect(program).to produce_output_when_run(expected_output).in_color(
348
+ color_enabled
349
+ )
334
350
  end
335
351
  end
336
352
  end
@@ -346,6 +362,12 @@ shared_examples_for "integration with ActiveRecord" do
346
362
  age: 20
347
363
  )
348
364
 
365
+ actual = [
366
+ SuperDiff::Test::Models::ActiveRecord::Query.new(
367
+ results: SuperDiff::Test::Models::ActiveRecord::Person.all
368
+ )
369
+ ]
370
+
349
371
  expected = [
350
372
  an_object_having_attributes(
351
373
  results: [
@@ -354,55 +376,51 @@ shared_examples_for "integration with ActiveRecord" do
354
376
  )
355
377
  ]
356
378
 
357
- actual = [
358
- SuperDiff::Test::Models::ActiveRecord::Query.new(
359
- results: SuperDiff::Test::Models::ActiveRecord::Person.all
360
- )
361
- ]
362
-
363
379
  expect(actual).to match(expected)
364
380
  TEST
365
381
 
366
382
  program = make_program(snippet, color_enabled: color_enabled)
367
383
 
368
- expected_output = build_expected_output(
369
- color_enabled: color_enabled,
370
- snippet: %|expect(actual).to match(expected)|,
371
- newline_before_expectation: true,
372
- expectation: proc {
373
- line do
374
- plain %|Expected |
375
- actual %|[#<SuperDiff::Test::Models::ActiveRecord::Query @results=#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person id: 1, age: 20, name: "Murphy">]>>]|
376
- end
384
+ expected_output =
385
+ build_expected_output(
386
+ color_enabled: color_enabled,
387
+ snippet: "expect(actual).to match(expected)",
388
+ newline_before_expectation: true,
389
+ expectation:
390
+ proc do
391
+ line do
392
+ plain "Expected "
393
+ actual %|[#<SuperDiff::Test::Models::ActiveRecord::Query @results=#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person id: 1, age: 20, name: "Murphy">]>>]|
394
+ end
377
395
 
378
- line do
379
- plain %|to match |
380
- expected %|[#<an object having attributes (results: [#<an object having attributes (name: "John", age: 19)>])>]|
381
- end
382
- },
383
- diff: proc {
384
- plain_line %| [|
385
- plain_line %| #<SuperDiff::Test::Models::ActiveRecord::Query {|
386
- plain_line %| @results=#<ActiveRecord::Relation [|
387
- plain_line %| #<SuperDiff::Test::Models::ActiveRecord::Person {|
388
- plain_line %| id: 1,|
389
- # expected_line %|- age: 19,| # TODO
390
- expected_line %|- age: 19|
391
- actual_line %|+ age: 20,|
392
- # expected_line %|- name: "John"| # TODO
393
- expected_line %|- name: "John",|
394
- actual_line %|+ name: "Murphy"|
395
- plain_line %| }>|
396
- plain_line %| ]>|
397
- plain_line %| }>|
398
- plain_line %| ]|
399
- },
400
- )
396
+ line do
397
+ plain "to match "
398
+ expected %|[#<an object having attributes (results: [#<an object having attributes (name: "John", age: 19)>])>]|
399
+ end
400
+ end,
401
+ diff:
402
+ proc do
403
+ plain_line " ["
404
+ plain_line " #<SuperDiff::Test::Models::ActiveRecord::Query {"
405
+ plain_line " @results=#<ActiveRecord::Relation ["
406
+ plain_line " #<SuperDiff::Test::Models::ActiveRecord::Person {"
407
+ plain_line " id: 1,"
408
+ # expected_line %|- age: 19,| # TODO
409
+ expected_line "- age: 19"
410
+ actual_line "+ age: 20,"
411
+ # expected_line %|- name: "John"| # TODO
412
+ expected_line %|- name: "John",|
413
+ actual_line %|+ name: "Murphy"|
414
+ plain_line " }>"
415
+ plain_line " ]>"
416
+ plain_line " }>"
417
+ plain_line " ]"
418
+ end
419
+ )
401
420
 
402
- expect(program).
403
- to produce_output_when_run(expected_output).
404
- in_color(color_enabled).
405
- removing_object_ids
421
+ expect(program).to produce_output_when_run(expected_output).in_color(
422
+ color_enabled
423
+ ).removing_object_ids
406
424
  end
407
425
  end
408
426
  end