super_diff 0.9.0 → 0.11.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 (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
@@ -1,238 +1,249 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe "Integration with RSpec's #have_attributes matcher", type: :integration do
4
- context "when the actual value is an object" do
3
+ RSpec.describe "Integration with RSpec's #have_attributes matcher",
4
+ type: :integration do
5
+ context "when the actual value is an object" do
5
6
  context "with a small set of attributes" do
6
- context "when all of the names are methods on the actual object" do
7
+ context "when all of the names are methods on the actual object" do
7
8
  it "produces the correct output when used in the positive" do
8
9
  as_both_colored_and_uncolored do |color_enabled|
9
10
  snippet = <<~TEST.strip
11
+ actual = SuperDiff::Test::Person.new(name: "a", age: 9)
10
12
  expected = { name: "b" }
11
- actual = SuperDiff::Test::Person.new(name: "a", age: 9)
12
13
  expect(actual).to have_attributes(expected)
13
14
  TEST
14
- program = make_plain_test_program(
15
- snippet,
16
- color_enabled: color_enabled,
17
- )
18
-
19
- expected_output = build_expected_output(
20
- color_enabled: color_enabled,
21
- snippet: %|expect(actual).to have_attributes(expected)|,
22
- expectation: proc {
23
- line do
24
- plain %|Expected |
25
- actual %|#<SuperDiff::Test::Person name: "a", age: 9>|
26
- plain %| to have attributes |
27
- expected %|(name: "b")|
28
- plain %|.|
29
- end
30
- },
31
- diff: proc {
32
- plain_line %| #<SuperDiff::Test::Person {|
33
- # expected_line %|- name: "b",| # FIXME
34
- expected_line %|- name: "b"|
35
- actual_line %|+ name: "a",|
36
- plain_line %| age: 9|
37
- plain_line %| }>|
38
- },
39
- )
15
+ program =
16
+ make_plain_test_program(snippet, color_enabled: color_enabled)
17
+
18
+ expected_output =
19
+ build_expected_output(
20
+ color_enabled: color_enabled,
21
+ snippet: "expect(actual).to have_attributes(expected)",
22
+ expectation:
23
+ proc do
24
+ line do
25
+ plain "Expected "
26
+ actual %|#<SuperDiff::Test::Person name: "a", age: 9>|
27
+ plain " to have attributes "
28
+ expected %|(name: "b")|
29
+ plain "."
30
+ end
31
+ end,
32
+ diff:
33
+ proc do
34
+ plain_line " #<SuperDiff::Test::Person {"
35
+ # expected_line %|- name: "b",| # FIXME
36
+ expected_line %|- name: "b"|
37
+ actual_line %|+ name: "a",|
38
+ plain_line " age: 9"
39
+ plain_line " }>"
40
+ end
41
+ )
40
42
 
41
- expect(program).
42
- to produce_output_when_run(expected_output).
43
- in_color(color_enabled)
43
+ expect(program).to produce_output_when_run(
44
+ expected_output
45
+ ).in_color(color_enabled)
44
46
  end
45
47
  end
46
48
 
47
49
  it "produces the correct output when used in the negative" do
48
50
  as_both_colored_and_uncolored do |color_enabled|
49
51
  snippet = <<~TEST.strip
52
+ actual = SuperDiff::Test::Person.new(name: "a", age: 9)
50
53
  expected = { name: "a" }
51
- actual = SuperDiff::Test::Person.new(name: "a", age: 9)
52
54
  expect(actual).not_to have_attributes(expected)
53
55
  TEST
54
- program = make_plain_test_program(
55
- snippet,
56
- color_enabled: color_enabled,
57
- )
58
-
59
- expected_output = build_expected_output(
60
- color_enabled: color_enabled,
61
- snippet: %|expect(actual).not_to have_attributes(expected)|,
62
- expectation: proc {
63
- line do
64
- plain %|Expected |
65
- actual %|#<SuperDiff::Test::Person name: "a", age: 9>|
66
- plain %| not to have attributes |
67
- expected %|(name: "a")|
68
- plain %|.|
69
- end
70
- },
71
- )
56
+ program =
57
+ make_plain_test_program(snippet, color_enabled: color_enabled)
58
+
59
+ expected_output =
60
+ build_expected_output(
61
+ color_enabled: color_enabled,
62
+ snippet: "expect(actual).not_to have_attributes(expected)",
63
+ expectation:
64
+ proc do
65
+ line do
66
+ plain "Expected "
67
+ actual %|#<SuperDiff::Test::Person name: "a", age: 9>|
68
+ plain " not to have attributes "
69
+ expected %|(name: "a")|
70
+ plain "."
71
+ end
72
+ end
73
+ )
72
74
 
73
- expect(program).
74
- to produce_output_when_run(expected_output).
75
- in_color(color_enabled)
75
+ expect(program).to produce_output_when_run(
76
+ expected_output
77
+ ).in_color(color_enabled)
76
78
  end
77
79
  end
78
80
  end
79
81
 
80
- context "when some of the names are not methods on the actual object" do
82
+ context "when some of the names are not methods on the actual object" do
81
83
  it "produces the correct output" do
82
84
  as_both_colored_and_uncolored do |color_enabled|
83
85
  snippet = <<~TEST.strip
86
+ actual = SuperDiff::Test::Person.new(name: "a", age: 9)
84
87
  expected = { name: "b", foo: "bar" }
85
- actual = SuperDiff::Test::Person.new(name: "a", age: 9)
86
88
  expect(actual).to have_attributes(expected)
87
89
  TEST
88
- program = make_plain_test_program(
89
- snippet,
90
- color_enabled: color_enabled,
91
- )
92
-
93
- expected_output = build_expected_output(
94
- color_enabled: color_enabled,
95
- snippet: %|expect(actual).to have_attributes(expected)|,
96
- expectation: proc {
97
- line do
98
- plain %|Expected |
99
- actual %|#<SuperDiff::Test::Person name: "a", age: 9>|
100
- plain %| to respond to |
101
- expected %|:foo|
102
- plain %| with |
103
- expected %|0|
104
- plain %| arguments.|
105
- end
106
- },
107
- diff: proc {
108
- plain_line %| #<SuperDiff::Test::Person {|
109
- plain_line %| name: "a",|
110
- # plain_line %| age: 9,| # FIXME
111
- plain_line %| age: 9|
112
- # expected_line %|- foo: "bar"| # FIXME
113
- expected_line %|- foo: "bar",|
114
- plain_line %| }>|
115
- },
116
- )
90
+ program =
91
+ make_plain_test_program(snippet, color_enabled: color_enabled)
92
+
93
+ expected_output =
94
+ build_expected_output(
95
+ color_enabled: color_enabled,
96
+ snippet: "expect(actual).to have_attributes(expected)",
97
+ expectation:
98
+ proc do
99
+ line do
100
+ plain "Expected "
101
+ actual %|#<SuperDiff::Test::Person name: "a", age: 9>|
102
+ plain " to respond to "
103
+ expected ":foo"
104
+ plain " with "
105
+ expected "0"
106
+ plain " arguments."
107
+ end
108
+ end,
109
+ diff:
110
+ proc do
111
+ plain_line " #<SuperDiff::Test::Person {"
112
+ plain_line %| name: "a",|
113
+ # plain_line %| age: 9,| # FIXME
114
+ plain_line " age: 9"
115
+ # expected_line %|- foo: "bar"| # FIXME
116
+ expected_line %|- foo: "bar",|
117
+ plain_line " }>"
118
+ end
119
+ )
117
120
 
118
- expect(program).
119
- to produce_output_when_run(expected_output).
120
- in_color(color_enabled)
121
+ expect(program).to produce_output_when_run(
122
+ expected_output
123
+ ).in_color(color_enabled)
121
124
  end
122
125
  end
123
126
  end
124
127
  end
125
128
 
126
129
  context "with a large set of attributes" do
127
- context "when all of the names are methods on the actual object" do
130
+ context "when all of the names are methods on the actual object" do
128
131
  it "produces the correct output when used in the positive" do
129
132
  as_both_colored_and_uncolored do |color_enabled|
130
133
  snippet = <<~TEST.strip
131
- expected = {
132
- line_1: "123 Main St.",
133
- city: "Oakland",
134
- state: "CA",
135
- zip: "91234"
136
- }
137
- actual = SuperDiff::Test::ShippingAddress.new(
134
+ actual = SuperDiff::Test::ShippingAddress.new(
138
135
  line_1: "456 Ponderosa Ct.",
139
136
  line_2: nil,
140
137
  city: "Hill Valley",
141
138
  state: "CA",
142
139
  zip: "90382"
143
140
  )
141
+ expected = {
142
+ line_1: "123 Main St.",
143
+ city: "Oakland",
144
+ state: "CA",
145
+ zip: "91234"
146
+ }
144
147
  expect(actual).to have_attributes(expected)
145
148
  TEST
146
- program = make_plain_test_program(
147
- snippet,
148
- color_enabled: color_enabled,
149
- )
150
-
151
- expected_output = build_expected_output(
152
- color_enabled: color_enabled,
153
- snippet: %|expect(actual).to have_attributes(expected)|,
154
- expectation: proc {
155
- line do
156
- plain %| Expected |
157
- actual %|#<SuperDiff::Test::ShippingAddress line_1: "456 Ponderosa Ct.", line_2: nil, city: "Hill Valley", state: "CA", zip: "90382">|
158
- end
159
-
160
- line do
161
- plain %|to have attributes |
162
- expected %|(line_1: "123 Main St.", city: "Oakland", state: "CA", zip: "91234")|
163
- end
164
- },
165
- diff: proc {
166
- plain_line %| #<SuperDiff::Test::ShippingAddress {|
167
- expected_line %|- line_1: "123 Main St.",|
168
- actual_line %|+ line_1: "456 Ponderosa Ct.",|
169
- plain_line %| line_2: nil,|
170
- expected_line %|- city: "Oakland",|
171
- actual_line %|+ city: "Hill Valley",|
172
- plain_line %| state: "CA",|
173
- expected_line %|- zip: "91234",| # FIXME
174
- actual_line %|+ zip: "90382"|
175
- plain_line %| }>|
176
- },
177
- )
149
+ program =
150
+ make_plain_test_program(snippet, color_enabled: color_enabled)
151
+
152
+ expected_output =
153
+ build_expected_output(
154
+ color_enabled: color_enabled,
155
+ snippet: "expect(actual).to have_attributes(expected)",
156
+ expectation:
157
+ proc do
158
+ line do
159
+ plain " Expected "
160
+ actual %|#<SuperDiff::Test::ShippingAddress line_1: "456 Ponderosa Ct.", line_2: nil, city: "Hill Valley", state: "CA", zip: "90382">|
161
+ end
162
+
163
+ line do
164
+ plain "to have attributes "
165
+ expected %|(line_1: "123 Main St.", city: "Oakland", state: "CA", zip: "91234")|
166
+ end
167
+ end,
168
+ diff:
169
+ proc do
170
+ plain_line " #<SuperDiff::Test::ShippingAddress {"
171
+ expected_line %|- line_1: "123 Main St.",|
172
+ actual_line %|+ line_1: "456 Ponderosa Ct.",|
173
+ plain_line " line_2: nil,"
174
+ expected_line %|- city: "Oakland",|
175
+ actual_line %|+ city: "Hill Valley",|
176
+ plain_line %| state: "CA",|
177
+ expected_line %|- zip: "91234",| # FIXME
178
+ actual_line %|+ zip: "90382"|
179
+ plain_line " }>"
180
+ end
181
+ )
178
182
 
179
- expect(program).
180
- to produce_output_when_run(expected_output).
181
- in_color(color_enabled)
183
+ expect(program).to produce_output_when_run(
184
+ expected_output
185
+ ).in_color(color_enabled)
182
186
  end
183
187
  end
184
188
 
185
189
  it "produces the correct output when used in the negative" do
186
190
  as_both_colored_and_uncolored do |color_enabled|
187
191
  snippet = <<~TEST.strip
188
- expected = {
192
+ actual = SuperDiff::Test::ShippingAddress.new(
189
193
  line_1: "123 Main St.",
194
+ line_2: nil,
190
195
  city: "Oakland",
191
196
  state: "CA",
192
197
  zip: "91234"
193
- }
194
- actual = SuperDiff::Test::ShippingAddress.new(
198
+ )
199
+ expected = {
195
200
  line_1: "123 Main St.",
196
- line_2: nil,
197
201
  city: "Oakland",
198
202
  state: "CA",
199
203
  zip: "91234"
200
- )
204
+ }
201
205
  expect(actual).not_to have_attributes(expected)
202
206
  TEST
203
- program = make_plain_test_program(
204
- snippet,
205
- color_enabled: color_enabled,
206
- )
207
-
208
- expected_output = build_expected_output(
209
- color_enabled: color_enabled,
210
- snippet: %|expect(actual).not_to have_attributes(expected)|,
211
- newline_before_expectation: true,
212
- expectation: proc {
213
- line do
214
- plain %| Expected |
215
- actual %|#<SuperDiff::Test::ShippingAddress line_1: "123 Main St.", line_2: nil, city: "Oakland", state: "CA", zip: "91234">|
216
- end
217
-
218
- line do
219
- plain %|not to have attributes |
220
- expected %|(line_1: "123 Main St.", city: "Oakland", state: "CA", zip: "91234")|
221
- end
222
- },
223
- )
207
+ program =
208
+ make_plain_test_program(snippet, color_enabled: color_enabled)
209
+
210
+ expected_output =
211
+ build_expected_output(
212
+ color_enabled: color_enabled,
213
+ snippet: "expect(actual).not_to have_attributes(expected)",
214
+ newline_before_expectation: true,
215
+ expectation:
216
+ proc do
217
+ line do
218
+ plain " Expected "
219
+ actual %|#<SuperDiff::Test::ShippingAddress line_1: "123 Main St.", line_2: nil, city: "Oakland", state: "CA", zip: "91234">|
220
+ end
221
+
222
+ line do
223
+ plain "not to have attributes "
224
+ expected %|(line_1: "123 Main St.", city: "Oakland", state: "CA", zip: "91234")|
225
+ end
226
+ end
227
+ )
224
228
 
225
- expect(program).
226
- to produce_output_when_run(expected_output).
227
- in_color(color_enabled)
229
+ expect(program).to produce_output_when_run(
230
+ expected_output
231
+ ).in_color(color_enabled)
228
232
  end
229
233
  end
230
234
  end
231
235
 
232
- context "when some of the names are not methods on the actual object" do
236
+ context "when some of the names are not methods on the actual object" do
233
237
  it "produces the correct output" do
234
238
  as_both_colored_and_uncolored do |color_enabled|
235
239
  snippet = <<~TEST.strip
240
+ actual = SuperDiff::Test::ShippingAddress.new(
241
+ line_1: "456 Ponderosa Ct.",
242
+ line_2: nil,
243
+ city: "Hill Valley",
244
+ state: "CA",
245
+ zip: "90382"
246
+ )
236
247
  expected = {
237
248
  line_1: "123 Main St.",
238
249
  city: "Oakland",
@@ -241,109 +252,107 @@ RSpec.describe "Integration with RSpec's #have_attributes matcher", type: :integ
241
252
  foo: "bar",
242
253
  baz: "qux"
243
254
  }
244
- actual = SuperDiff::Test::ShippingAddress.new(
245
- line_1: "456 Ponderosa Ct.",
246
- line_2: nil,
247
- city: "Hill Valley",
248
- state: "CA",
249
- zip: "90382"
250
- )
251
255
  expect(actual).to have_attributes(expected)
252
256
  TEST
253
- program = make_plain_test_program(
254
- snippet,
255
- color_enabled: color_enabled,
256
- )
257
-
258
- expected_output = build_expected_output(
259
- color_enabled: color_enabled,
260
- snippet: %|expect(actual).to have_attributes(expected)|,
261
- expectation: proc {
262
- line do
263
- plain %| Expected |
264
- actual %|#<SuperDiff::Test::ShippingAddress line_1: "456 Ponderosa Ct.", line_2: nil, city: "Hill Valley", state: "CA", zip: "90382">|
265
- end
266
-
267
- line do
268
- plain %|to respond to |
269
- expected %|:foo|
270
- plain %| and |
271
- expected %|:baz|
272
- plain %| with |
273
- expected %|0|
274
- plain %| arguments|
275
- end
276
- },
277
- diff: proc {
278
- plain_line %| #<SuperDiff::Test::ShippingAddress {|
279
- plain_line %| line_1: "456 Ponderosa Ct.",|
280
- plain_line %| line_2: nil,|
281
- plain_line %| city: "Hill Valley",|
282
- plain_line %| state: "CA",|
283
- # plain_line %| zip: "90382",| # FIXME
284
- plain_line %| zip: "90382"|
285
- expected_line %|- foo: "bar",|
286
- # expected_line %|- baz: "qux"| # TODO
287
- expected_line %|- baz: "qux",|
288
- plain_line %| }>|
289
- },
290
- )
257
+ program =
258
+ make_plain_test_program(snippet, color_enabled: color_enabled)
259
+
260
+ expected_output =
261
+ build_expected_output(
262
+ color_enabled: color_enabled,
263
+ snippet: "expect(actual).to have_attributes(expected)",
264
+ expectation:
265
+ proc do
266
+ line do
267
+ plain " Expected "
268
+ actual %|#<SuperDiff::Test::ShippingAddress line_1: "456 Ponderosa Ct.", line_2: nil, city: "Hill Valley", state: "CA", zip: "90382">|
269
+ end
270
+
271
+ line do
272
+ plain "to respond to "
273
+ expected ":foo"
274
+ plain " and "
275
+ expected ":baz"
276
+ plain " with "
277
+ expected "0"
278
+ plain " arguments"
279
+ end
280
+ end,
281
+ diff:
282
+ proc do
283
+ plain_line " #<SuperDiff::Test::ShippingAddress {"
284
+ plain_line %| line_1: "456 Ponderosa Ct.",|
285
+ plain_line " line_2: nil,"
286
+ plain_line %| city: "Hill Valley",|
287
+ plain_line %| state: "CA",|
288
+ # plain_line %| zip: "90382",| # FIXME
289
+ plain_line %| zip: "90382"|
290
+ expected_line %|- foo: "bar",|
291
+ # expected_line %|- baz: "qux"| # TODO
292
+ expected_line %|- baz: "qux",|
293
+ plain_line " }>"
294
+ end
295
+ )
291
296
 
292
- expect(program).
293
- to produce_output_when_run(expected_output).
294
- in_color(color_enabled)
297
+ expect(program).to produce_output_when_run(
298
+ expected_output
299
+ ).in_color(color_enabled)
295
300
  end
296
301
  end
297
302
  end
298
303
  end
299
304
  end
300
305
 
301
- context "when the actual value is actually a hash instead of an object" do
306
+ context "when the actual value is actually a hash instead of an object" do
302
307
  it "displays the diff as if we were comparing hashes" do
303
308
  as_both_colored_and_uncolored do |color_enabled|
304
309
  snippet = <<~TEST.strip
310
+ actual = {}
305
311
  expected = { name: "Elliot", age: 32 }
306
- actual = {}
307
312
  expect(actual).to have_attributes(expected)
308
313
  TEST
309
314
 
310
315
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
311
316
 
312
- expected_output = build_expected_output(
313
- color_enabled: color_enabled,
314
- snippet: %|expect(actual).to have_attributes(expected)|,
315
- expectation: proc {
316
- line do
317
- plain %|Expected |
318
- actual %|{}|
319
- plain %| to respond to |
320
- expected %|:name|
321
- plain %| and |
322
- expected %|:age|
323
- plain %| with |
324
- expected %|0|
325
- plain %| arguments.|
326
- end
327
- },
328
- diff: proc {
329
- plain_line %| {|
330
- expected_line %|- name: "Elliot",|
331
- expected_line %|- age: 32|
332
- plain_line %| }|
333
- },
334
- )
317
+ expected_output =
318
+ build_expected_output(
319
+ color_enabled: color_enabled,
320
+ snippet: "expect(actual).to have_attributes(expected)",
321
+ expectation:
322
+ proc do
323
+ line do
324
+ plain "Expected "
325
+ actual "{}"
326
+ plain " to respond to "
327
+ expected ":name"
328
+ plain " and "
329
+ expected ":age"
330
+ plain " with "
331
+ expected "0"
332
+ plain " arguments."
333
+ end
334
+ end,
335
+ diff:
336
+ proc do
337
+ plain_line " {"
338
+ expected_line %|- name: "Elliot",|
339
+ expected_line "- age: 32"
340
+ plain_line " }"
341
+ end
342
+ )
335
343
 
336
- expect(program).
337
- to produce_output_when_run(expected_output).
338
- in_color(color_enabled)
344
+ expect(program).to produce_output_when_run(expected_output).in_color(
345
+ color_enabled
346
+ )
339
347
  end
340
348
  end
341
349
 
342
- # TODO: Add as many fuzzy matchers as we can here
343
- context "that contains fuzzy matcher objects instead of an object" do
350
+ # TODO: Add as many RSpec matchers as we can here
351
+ context "that contains RSpec matchers" do
344
352
  it "displays the hash correctly" do
345
353
  as_both_colored_and_uncolored do |color_enabled|
346
354
  snippet = <<~TEST.strip
355
+ actual = {}
347
356
  expected = {
348
357
  name: "Elliot",
349
358
  shipping_address: an_object_having_attributes(
@@ -358,76 +367,75 @@ RSpec.describe "Integration with RSpec's #have_attributes matcher", type: :integ
358
367
  created_at: a_value_within(1).of(Time.utc(2020, 4, 9))
359
368
  }
360
369
 
361
- actual = {}
362
-
363
370
  expect(actual).to have_attributes(expected)
364
371
  TEST
365
372
 
366
- program = make_plain_test_program(
367
- snippet,
368
- color_enabled: color_enabled,
369
- )
373
+ program =
374
+ make_plain_test_program(snippet, color_enabled: color_enabled)
370
375
 
371
- expected_output = build_expected_output(
372
- color_enabled: color_enabled,
373
- snippet: %|expect(actual).to have_attributes(expected)|,
374
- expectation: proc {
375
- line do
376
- plain %| Expected |
377
- actual %|{}|
378
- end
376
+ expected_output =
377
+ build_expected_output(
378
+ color_enabled: color_enabled,
379
+ snippet: "expect(actual).to have_attributes(expected)",
380
+ expectation:
381
+ proc do
382
+ line do
383
+ plain " Expected "
384
+ actual "{}"
385
+ end
386
+
387
+ line do
388
+ plain "to respond to "
389
+ expected ":name"
390
+ plain ", "
391
+ expected ":shipping_address"
392
+ plain ", "
393
+ expected ":order_ids"
394
+ plain ", "
395
+ expected ":data"
396
+ plain " and "
397
+ expected ":created_at"
398
+ plain " with "
399
+ expected "0"
400
+ plain " arguments"
401
+ end
402
+ end,
403
+ diff:
404
+ proc do
405
+ plain_line " {"
406
+ expected_line %|- name: "Elliot",|
407
+ expected_line "- shipping_address: #<an object having attributes ("
408
+ expected_line "- line_1: #<a kind of String>,"
409
+ expected_line "- line_2: nil,"
410
+ expected_line "- city: #<an instance of String>,"
411
+ expected_line %|- state: "CA",|
412
+ expected_line %|- zip: "91234"|
413
+ expected_line "- )>,"
414
+ expected_line "- order_ids: #<a collection including ("
415
+ expected_line "- 1,"
416
+ expected_line "- 2"
417
+ expected_line "- )>,"
418
+ expected_line "- data: #<a hash including ("
419
+ expected_line "- active: true"
420
+ expected_line "- )>,"
421
+ expected_line "- created_at: #<a value within 1 of #<Time {"
422
+ expected_line "- year: 2020,"
423
+ expected_line "- month: 4,"
424
+ expected_line "- day: 9,"
425
+ expected_line "- hour: 0,"
426
+ expected_line "- min: 0,"
427
+ expected_line "- sec: 0,"
428
+ expected_line "- subsec: 0,"
429
+ expected_line %|- zone: "UTC",|
430
+ expected_line "- utc_offset: 0"
431
+ expected_line "- }>>"
432
+ plain_line " }"
433
+ end
434
+ )
379
435
 
380
- line do
381
- plain %|to respond to |
382
- expected %|:name|
383
- plain %|, |
384
- expected %|:shipping_address|
385
- plain %|, |
386
- expected %|:order_ids|
387
- plain %|, |
388
- expected %|:data|
389
- plain %| and |
390
- expected %|:created_at|
391
- plain %| with |
392
- expected %|0|
393
- plain %| arguments|
394
- end
395
- },
396
- diff: proc {
397
- plain_line %| {|
398
- expected_line %|- name: "Elliot",|
399
- expected_line %|- shipping_address: #<an object having attributes (|
400
- expected_line %|- line_1: #<a kind of String>,|
401
- expected_line %|- line_2: nil,|
402
- expected_line %|- city: #<an instance of String>,|
403
- expected_line %|- state: "CA",|
404
- expected_line %|- zip: "91234"|
405
- expected_line %|- )>,|
406
- expected_line %|- order_ids: #<a collection including (|
407
- expected_line %|- 1,|
408
- expected_line %|- 2|
409
- expected_line %|- )>,|
410
- expected_line %|- data: #<a hash including (|
411
- expected_line %|- active: true|
412
- expected_line %|- )>,|
413
- expected_line %|- created_at: #<a value within 1 of #<Time {|
414
- expected_line %|- year: 2020,|
415
- expected_line %|- month: 4,|
416
- expected_line %|- day: 9,|
417
- expected_line %|- hour: 0,|
418
- expected_line %|- min: 0,|
419
- expected_line %|- sec: 0,|
420
- expected_line %|- subsec: 0,|
421
- expected_line %|- zone: "UTC",|
422
- expected_line %|- utc_offset: 0|
423
- expected_line %|- }>>|
424
- plain_line %| }|
425
- },
436
+ expect(program).to produce_output_when_run(expected_output).in_color(
437
+ color_enabled
426
438
  )
427
-
428
- expect(program).
429
- to produce_output_when_run(expected_output).
430
- in_color(color_enabled)
431
439
  end
432
440
  end
433
441
  end