super_diff 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) 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 +5 -13
  6. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +1 -3
  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 +3 -9
  18. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +1 -1
  19. data/lib/super_diff/active_support/object_inspection.rb +1 -1
  20. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
  21. data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
  22. data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
  23. data/lib/super_diff/active_support/operation_trees.rb +1 -1
  24. data/lib/super_diff/active_support.rb +6 -11
  25. data/lib/super_diff/colorized_document_extensions.rb +2 -4
  26. data/lib/super_diff/configuration.rb +14 -8
  27. data/lib/super_diff/csi/color.rb +4 -4
  28. data/lib/super_diff/csi/colorized_document.rb +12 -16
  29. data/lib/super_diff/csi/document.rb +8 -19
  30. data/lib/super_diff/csi/eight_bit_color.rb +19 -19
  31. data/lib/super_diff/csi/four_bit_color.rb +82 -31
  32. data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
  33. data/lib/super_diff/csi/uncolorized_document.rb +2 -6
  34. data/lib/super_diff/csi.rb +10 -14
  35. data/lib/super_diff/diff_formatters/collection.rb +35 -41
  36. data/lib/super_diff/differs/default_object.rb +1 -1
  37. data/lib/super_diff/differs/defaults.rb +1 -1
  38. data/lib/super_diff/differs/main.rb +2 -13
  39. data/lib/super_diff/equality_matchers/array.rb +10 -12
  40. data/lib/super_diff/equality_matchers/base.rb +1 -1
  41. data/lib/super_diff/equality_matchers/default.rb +2 -4
  42. data/lib/super_diff/equality_matchers/defaults.rb +1 -1
  43. data/lib/super_diff/equality_matchers/hash.rb +10 -12
  44. data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
  45. data/lib/super_diff/equality_matchers/primitive.rb +10 -12
  46. data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
  47. data/lib/super_diff/equality_matchers.rb +1 -1
  48. data/lib/super_diff/errors.rb +3 -3
  49. data/lib/super_diff/gem_version.rb +3 -3
  50. data/lib/super_diff/helpers.rb +10 -10
  51. data/lib/super_diff/implementation_checks.rb +2 -2
  52. data/lib/super_diff/line.rb +3 -3
  53. data/lib/super_diff/object_inspection/inspection_tree.rb +46 -60
  54. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +2 -6
  55. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +3 -9
  56. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +5 -14
  57. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +1 -1
  58. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +4 -12
  59. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +6 -23
  60. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +9 -9
  61. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +8 -20
  62. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
  63. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
  64. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
  65. data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
  66. data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
  67. data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
  68. data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
  69. data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
  70. data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
  71. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
  72. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
  73. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
  74. data/lib/super_diff/object_inspection/nodes.rb +7 -7
  75. data/lib/super_diff/object_inspection.rb +3 -3
  76. data/lib/super_diff/operation_tree_builders/array.rb +12 -11
  77. data/lib/super_diff/operation_tree_builders/base.rb +17 -15
  78. data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
  79. data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
  80. data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
  81. data/lib/super_diff/operation_tree_builders/main.rb +4 -11
  82. data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
  83. data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
  84. data/lib/super_diff/operation_tree_builders.rb +1 -1
  85. data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
  86. data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
  87. data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
  88. data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
  89. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
  90. data/lib/super_diff/operation_tree_flatteners.rb +3 -3
  91. data/lib/super_diff/operation_trees/base.rb +3 -5
  92. data/lib/super_diff/operation_trees/default_object.rb +1 -3
  93. data/lib/super_diff/operations/binary_operation.rb +2 -2
  94. data/lib/super_diff/operations/unary_operation.rb +1 -1
  95. data/lib/super_diff/rails.rb +2 -1
  96. data/lib/super_diff/recursion_guard.rb +5 -4
  97. data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
  98. data/lib/super_diff/rspec/differ.rb +6 -13
  99. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
  100. data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
  101. data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
  102. data/lib/super_diff/rspec/differs.rb +3 -3
  103. data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
  104. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
  105. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
  106. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -5
  107. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
  108. data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
  109. data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
  110. data/lib/super_diff/rspec/monkey_patches.rb +122 -116
  111. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +8 -6
  112. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +11 -16
  113. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +2 -1
  114. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +8 -6
  115. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +8 -6
  116. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +9 -9
  117. data/lib/super_diff/rspec/object_inspection.rb +1 -1
  118. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
  119. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
  120. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
  121. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
  122. data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
  123. data/lib/super_diff/rspec.rb +11 -13
  124. data/lib/super_diff/tiered_lines_elider.rb +87 -115
  125. data/lib/super_diff/tiered_lines_formatter.rb +5 -9
  126. data/lib/super_diff/version.rb +1 -1
  127. data/lib/super_diff.rb +4 -9
  128. data/spec/examples.txt +493 -485
  129. data/spec/integration/rails/active_record_spec.rb +3 -1
  130. data/spec/integration/rails/engines_spec.rb +20 -0
  131. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
  132. data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
  133. data/spec/integration/rspec/be_matcher_spec.rb +360 -320
  134. data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
  135. data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
  136. data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
  137. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +242 -239
  138. data/spec/integration/rspec/eq_matcher_spec.rb +595 -557
  139. data/spec/integration/rspec/have_attributes_matcher_spec.rb +294 -286
  140. data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
  141. data/spec/integration/rspec/include_matcher_spec.rb +317 -215
  142. data/spec/integration/rspec/match_array_matcher_spec.rb +276 -273
  143. data/spec/integration/rspec/match_matcher_spec.rb +847 -834
  144. data/spec/integration/rspec/raise_error_matcher_spec.rb +468 -453
  145. data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
  146. data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
  147. data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
  148. data/spec/spec_helper.rb +17 -20
  149. data/spec/support/command_runner.rb +34 -57
  150. data/spec/support/integration/helpers.rb +35 -28
  151. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
  152. data/spec/support/integration/test_programs/base.rb +12 -17
  153. data/spec/support/integration/test_programs/plain.rb +6 -0
  154. data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
  155. data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
  156. data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
  157. data/spec/support/integration/test_programs/rspec_rails_engine.rb +30 -0
  158. data/spec/support/models/active_record/person.rb +6 -4
  159. data/spec/support/models/active_record/shipping_address.rb +9 -10
  160. data/spec/support/models/customer.rb +2 -4
  161. data/spec/support/models/player.rb +3 -6
  162. data/spec/support/models/shipping_address.rb +4 -13
  163. data/spec/support/shared_examples/active_record.rb +232 -214
  164. data/spec/support/shared_examples/active_support.rb +53 -51
  165. data/spec/support/shared_examples/elided_diffs.rb +405 -381
  166. data/spec/support/shared_examples/hash_with_indifferent_access.rb +424 -388
  167. data/spec/support/shared_examples/key.rb +123 -0
  168. data/spec/support/unit/helpers.rb +1 -3
  169. data/spec/support/unit/matchers/match_output.rb +12 -13
  170. data/spec/unit/active_record/object_inspection_spec.rb +222 -206
  171. data/spec/unit/equality_matchers/main_spec.rb +1049 -984
  172. data/spec/unit/helpers_spec.rb +14 -21
  173. data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
  174. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
  175. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
  176. data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
  177. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
  178. data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
  179. data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
  180. data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
  181. data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
  182. data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
  183. data/spec/unit/rspec/matchers/include_spec.rb +2 -2
  184. data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
  185. data/spec/unit/rspec/matchers/raise_error_spec.rb +5 -5
  186. data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
  187. data/spec/unit/rspec/object_inspection_spec.rb +349 -324
  188. data/spec/unit/super_diff_spec.rb +1542 -1449
  189. data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
  190. data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
  191. data/super_diff.gemspec +13 -12
  192. metadata +73 -73
  193. data/spec/tmp/warnings_logger/all_warnings.txt +0 -2
@@ -1,46 +1,48 @@
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
10
11
  expected = { name: "b" }
11
- actual = SuperDiff::Test::Person.new(name: "a", age: 9)
12
+ 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
 
@@ -48,83 +50,84 @@ RSpec.describe "Integration with RSpec's #have_attributes matcher", type: :integ
48
50
  as_both_colored_and_uncolored do |color_enabled|
49
51
  snippet = <<~TEST.strip
50
52
  expected = { name: "a" }
51
- actual = SuperDiff::Test::Person.new(name: "a", age: 9)
53
+ 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
84
86
  expected = { name: "b", foo: "bar" }
85
- actual = SuperDiff::Test::Person.new(name: "a", age: 9)
87
+ 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
@@ -134,7 +137,7 @@ RSpec.describe "Integration with RSpec's #have_attributes matcher", type: :integ
134
137
  state: "CA",
135
138
  zip: "91234"
136
139
  }
137
- actual = SuperDiff::Test::ShippingAddress.new(
140
+ actual = SuperDiff::Test::ShippingAddress.new(
138
141
  line_1: "456 Ponderosa Ct.",
139
142
  line_2: nil,
140
143
  city: "Hill Valley",
@@ -143,42 +146,43 @@ RSpec.describe "Integration with RSpec's #have_attributes matcher", type: :integ
143
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
 
@@ -191,7 +195,7 @@ RSpec.describe "Integration with RSpec's #have_attributes matcher", type: :integ
191
195
  state: "CA",
192
196
  zip: "91234"
193
197
  }
194
- actual = SuperDiff::Test::ShippingAddress.new(
198
+ actual = SuperDiff::Test::ShippingAddress.new(
195
199
  line_1: "123 Main St.",
196
200
  line_2: nil,
197
201
  city: "Oakland",
@@ -200,36 +204,36 @@ RSpec.describe "Integration with RSpec's #have_attributes matcher", type: :integ
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
@@ -241,7 +245,7 @@ RSpec.describe "Integration with RSpec's #have_attributes matcher", type: :integ
241
245
  foo: "bar",
242
246
  baz: "qux"
243
247
  }
244
- actual = SuperDiff::Test::ShippingAddress.new(
248
+ actual = SuperDiff::Test::ShippingAddress.new(
245
249
  line_1: "456 Ponderosa Ct.",
246
250
  line_2: nil,
247
251
  city: "Hill Valley",
@@ -250,92 +254,96 @@ RSpec.describe "Integration with RSpec's #have_attributes matcher", type: :integ
250
254
  )
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
305
310
  expected = { name: "Elliot", age: 32 }
306
- actual = {}
311
+ 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
 
@@ -357,77 +365,77 @@ RSpec.describe "Integration with RSpec's #have_attributes matcher", type: :integ
357
365
  data: a_hash_including(active: true),
358
366
  created_at: a_value_within(1).of(Time.utc(2020, 4, 9))
359
367
  }
360
-
361
- actual = {}
368
+ actual = {}
362
369
 
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