super_diff 0.2.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +108 -74
  3. data/lib/super_diff.rb +20 -11
  4. data/lib/super_diff/active_record.rb +21 -23
  5. data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +3 -3
  6. data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -5
  7. data/lib/super_diff/active_record/monkey_patches.rb +9 -0
  8. data/lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb +32 -22
  9. data/lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb +17 -7
  10. data/lib/super_diff/active_record/operation_tree_builders.rb +14 -0
  11. data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_model.rb +2 -2
  12. data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_relation.rb +4 -4
  13. data/lib/super_diff/active_record/{operation_sequences.rb → operation_trees.rb} +2 -2
  14. data/lib/super_diff/active_record/{operation_sequences → operation_trees}/active_record_relation.rb +2 -2
  15. data/lib/super_diff/active_support.rb +16 -19
  16. data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +3 -3
  17. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -5
  18. data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +17 -7
  19. data/lib/super_diff/active_support/operation_tree_builders.rb +10 -0
  20. data/lib/super_diff/active_support/{operational_sequencers → operation_tree_builders}/hash_with_indifferent_access.rb +2 -2
  21. data/lib/super_diff/active_support/{operation_sequences.rb → operation_trees.rb} +2 -2
  22. data/lib/super_diff/active_support/{operation_sequences → operation_trees}/hash_with_indifferent_access.rb +2 -2
  23. data/lib/super_diff/configuration.rb +60 -0
  24. data/lib/super_diff/csi.rb +4 -0
  25. data/lib/super_diff/diff_formatters.rb +3 -3
  26. data/lib/super_diff/diff_formatters/array.rb +3 -3
  27. data/lib/super_diff/diff_formatters/base.rb +3 -2
  28. data/lib/super_diff/diff_formatters/collection.rb +2 -2
  29. data/lib/super_diff/diff_formatters/custom_object.rb +3 -3
  30. data/lib/super_diff/diff_formatters/default_object.rb +6 -8
  31. data/lib/super_diff/diff_formatters/defaults.rb +10 -0
  32. data/lib/super_diff/diff_formatters/hash.rb +3 -3
  33. data/lib/super_diff/diff_formatters/main.rb +41 -0
  34. data/lib/super_diff/diff_formatters/multiline_string.rb +3 -3
  35. data/lib/super_diff/differs.rb +4 -9
  36. data/lib/super_diff/differs/array.rb +2 -11
  37. data/lib/super_diff/differs/base.rb +20 -3
  38. data/lib/super_diff/differs/custom_object.rb +2 -11
  39. data/lib/super_diff/differs/default_object.rb +2 -8
  40. data/lib/super_diff/differs/defaults.rb +12 -0
  41. data/lib/super_diff/differs/hash.rb +2 -11
  42. data/lib/super_diff/differs/main.rb +48 -0
  43. data/lib/super_diff/differs/multiline_string.rb +2 -14
  44. data/lib/super_diff/differs/time_like.rb +15 -0
  45. data/lib/super_diff/equality_matchers.rb +3 -9
  46. data/lib/super_diff/equality_matchers/array.rb +1 -7
  47. data/lib/super_diff/equality_matchers/base.rb +1 -1
  48. data/lib/super_diff/equality_matchers/default.rb +2 -8
  49. data/lib/super_diff/equality_matchers/defaults.rb +12 -0
  50. data/lib/super_diff/equality_matchers/hash.rb +1 -7
  51. data/lib/super_diff/equality_matchers/main.rb +21 -0
  52. data/lib/super_diff/equality_matchers/multiline_string.rb +1 -7
  53. data/lib/super_diff/errors.rb +16 -0
  54. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +21 -0
  55. data/lib/super_diff/errors/no_differ_available_error.rb +24 -0
  56. data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +22 -0
  57. data/lib/super_diff/implementation_checks.rb +19 -0
  58. data/lib/super_diff/object_inspection.rb +1 -10
  59. data/lib/super_diff/object_inspection/inspection_tree.rb +6 -2
  60. data/lib/super_diff/object_inspection/inspectors.rb +5 -0
  61. data/lib/super_diff/object_inspection/inspectors/array.rb +20 -10
  62. data/lib/super_diff/object_inspection/inspectors/base.rb +36 -0
  63. data/lib/super_diff/object_inspection/inspectors/custom_object.rb +24 -14
  64. data/lib/super_diff/object_inspection/inspectors/default_object.rb +44 -30
  65. data/lib/super_diff/object_inspection/inspectors/defaults.rb +15 -0
  66. data/lib/super_diff/object_inspection/inspectors/hash.rb +20 -10
  67. data/lib/super_diff/object_inspection/inspectors/main.rb +35 -0
  68. data/lib/super_diff/object_inspection/inspectors/primitive.rb +20 -5
  69. data/lib/super_diff/object_inspection/inspectors/string.rb +15 -5
  70. data/lib/super_diff/object_inspection/inspectors/time_like.rb +23 -0
  71. data/lib/super_diff/object_inspection/nodes/inspection.rb +9 -2
  72. data/lib/super_diff/operation_tree_builders.rb +18 -0
  73. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/array.rb +38 -59
  74. data/lib/super_diff/operation_tree_builders/base.rb +98 -0
  75. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/custom_object.rb +3 -3
  76. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/default_object.rb +8 -3
  77. data/lib/super_diff/operation_tree_builders/defaults.rb +5 -0
  78. data/lib/super_diff/operation_tree_builders/hash.rb +226 -0
  79. data/lib/super_diff/operation_tree_builders/main.rb +42 -0
  80. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/multiline_string.rb +3 -3
  81. data/lib/super_diff/operation_tree_builders/time_like.rb +34 -0
  82. data/lib/super_diff/operation_trees.rb +13 -0
  83. data/lib/super_diff/{operation_sequences → operation_trees}/array.rb +5 -1
  84. data/lib/super_diff/operation_trees/base.rb +31 -0
  85. data/lib/super_diff/{operation_sequences → operation_trees}/custom_object.rb +5 -1
  86. data/lib/super_diff/{operation_sequences → operation_trees}/default_object.rb +10 -8
  87. data/lib/super_diff/operation_trees/defaults.rb +5 -0
  88. data/lib/super_diff/{operation_sequences → operation_trees}/hash.rb +5 -1
  89. data/lib/super_diff/operation_trees/main.rb +35 -0
  90. data/lib/super_diff/operation_trees/multiline_string.rb +18 -0
  91. data/lib/super_diff/operations/unary_operation.rb +3 -0
  92. data/lib/super_diff/rspec.rb +54 -22
  93. data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
  94. data/lib/super_diff/rspec/differ.rb +2 -17
  95. data/lib/super_diff/rspec/differs.rb +9 -3
  96. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -8
  97. data/lib/super_diff/rspec/differs/collection_including.rb +18 -0
  98. data/lib/super_diff/rspec/differs/hash_including.rb +18 -0
  99. data/lib/super_diff/rspec/differs/object_having_attributes.rb +17 -0
  100. data/lib/super_diff/rspec/matcher_text_builders.rb +4 -0
  101. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +26 -7
  102. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +61 -0
  103. data/lib/super_diff/rspec/matcher_text_builders/match.rb +1 -1
  104. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +13 -1
  105. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +1 -1
  106. data/lib/super_diff/rspec/matcher_text_template.rb +1 -1
  107. data/lib/super_diff/rspec/monkey_patches.rb +226 -115
  108. data/lib/super_diff/rspec/object_inspection.rb +0 -1
  109. data/lib/super_diff/rspec/object_inspection/inspectors.rb +22 -6
  110. data/lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb +17 -8
  111. data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +28 -0
  112. data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +31 -0
  113. data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +23 -0
  114. data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +23 -0
  115. data/lib/super_diff/rspec/object_inspection/inspectors/object_having_attributes.rb +31 -0
  116. data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +13 -0
  117. data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +29 -0
  118. data/lib/super_diff/rspec/operation_tree_builders.rb +22 -0
  119. data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/collection_containing_exactly.rb +6 -6
  120. data/lib/super_diff/rspec/{operational_sequencers/partial_array.rb → operation_tree_builders/collection_including.rb} +4 -3
  121. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +25 -0
  122. data/lib/super_diff/rspec/{operational_sequencers/partial_object.rb → operation_tree_builders/object_having_attributes.rb} +5 -11
  123. data/lib/super_diff/version.rb +1 -1
  124. data/spec/examples.txt +397 -328
  125. data/spec/integration/rails/active_record_spec.rb +1 -1
  126. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +1 -1
  127. data/spec/integration/rspec/be_predicate_matcher_spec.rb +111 -59
  128. data/spec/integration/rspec/eq_matcher_spec.rb +139 -3
  129. data/spec/integration/rspec/have_attributes_matcher_spec.rb +354 -227
  130. data/spec/integration/rspec/have_predicate_matcher_spec.rb +484 -0
  131. data/spec/integration/rspec/include_matcher_spec.rb +2 -2
  132. data/spec/integration/rspec/match_array_matcher_spec.rb +372 -0
  133. data/spec/integration/rspec/match_matcher_spec.rb +8 -8
  134. data/spec/integration/rspec/raise_error_matcher_spec.rb +605 -226
  135. data/spec/integration/rspec/third_party_matcher_spec.rb +241 -0
  136. data/spec/integration/rspec/unhandled_errors_spec.rb +110 -58
  137. data/spec/spec_helper.rb +18 -7
  138. data/spec/support/command_runner.rb +3 -0
  139. data/spec/support/integration/helpers.rb +14 -90
  140. data/spec/support/integration/matchers.rb +143 -0
  141. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +14 -29
  142. data/spec/support/integration/test_programs/base.rb +120 -0
  143. data/spec/support/integration/test_programs/plain.rb +13 -0
  144. data/spec/support/integration/test_programs/rspec_active_record.rb +17 -0
  145. data/spec/support/integration/test_programs/rspec_rails.rb +17 -0
  146. data/spec/support/models/active_record/person.rb +4 -11
  147. data/spec/support/models/active_record/query.rb +15 -0
  148. data/spec/support/models/active_record/shipping_address.rb +10 -14
  149. data/spec/support/object_id.rb +27 -0
  150. data/spec/support/ruby_versions.rb +4 -0
  151. data/spec/support/shared_examples/active_record.rb +71 -0
  152. data/spec/support/shared_examples/hash_with_indifferent_access.rb +724 -208
  153. data/spec/tmp/integration_spec.rb +15 -0
  154. data/spec/unit/{equality_matcher_spec.rb → equality_matchers/main_spec.rb} +165 -9
  155. data/spec/unit/object_inspection_spec.rb +94 -18
  156. data/spec/unit/rspec/matchers/have_predicate_spec.rb +21 -0
  157. data/spec/unit/rspec/matchers/match_array_spec.rb +11 -0
  158. data/spec/unit/rspec/matchers/raise_error_spec.rb +16 -0
  159. data/super_diff.gemspec +3 -6
  160. metadata +99 -91
  161. data/lib/super_diff/active_record/object_inspection/map_extension.rb +0 -18
  162. data/lib/super_diff/active_record/operational_sequencers.rb +0 -14
  163. data/lib/super_diff/active_support/object_inspection/map_extension.rb +0 -15
  164. data/lib/super_diff/active_support/operational_sequencers.rb +0 -10
  165. data/lib/super_diff/diff_formatter.rb +0 -32
  166. data/lib/super_diff/differ.rb +0 -51
  167. data/lib/super_diff/equality_matcher.rb +0 -32
  168. data/lib/super_diff/no_differ_available_error.rb +0 -22
  169. data/lib/super_diff/no_operational_sequencer_available_error.rb +0 -20
  170. data/lib/super_diff/object_inspection/inspector.rb +0 -27
  171. data/lib/super_diff/object_inspection/map.rb +0 -28
  172. data/lib/super_diff/operation_sequences.rb +0 -9
  173. data/lib/super_diff/operation_sequences/base.rb +0 -11
  174. data/lib/super_diff/operational_sequencer.rb +0 -48
  175. data/lib/super_diff/operational_sequencers.rb +0 -16
  176. data/lib/super_diff/operational_sequencers/base.rb +0 -89
  177. data/lib/super_diff/operational_sequencers/hash.rb +0 -85
  178. data/lib/super_diff/rspec/configuration.rb +0 -31
  179. data/lib/super_diff/rspec/differs/partial_array.rb +0 -22
  180. data/lib/super_diff/rspec/differs/partial_hash.rb +0 -22
  181. data/lib/super_diff/rspec/differs/partial_object.rb +0 -22
  182. data/lib/super_diff/rspec/object_inspection/inspectors/partial_array.rb +0 -22
  183. data/lib/super_diff/rspec/object_inspection/inspectors/partial_hash.rb +0 -21
  184. data/lib/super_diff/rspec/object_inspection/inspectors/partial_object.rb +0 -21
  185. data/lib/super_diff/rspec/object_inspection/map_extension.rb +0 -23
  186. data/lib/super_diff/rspec/operational_sequencers.rb +0 -22
  187. data/lib/super_diff/rspec/operational_sequencers/partial_hash.rb +0 -32
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe "Integration with Rails's ActiveRecord class", type: :integration do
3
+ RSpec.describe "Integration with Rails's ActiveRecord class", type: :integration, active_record: true do
4
4
  context "when using 'super_diff/rspec-rails'" do
5
5
  include_context "integration with ActiveRecord"
6
6
 
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe "Integration with Rails's HashWithIndifferentAccess", type: :integration do
3
+ RSpec.describe "Integration with Rails's HashWithIndifferentAccess", type: :integration, active_record: true do
4
4
  context "when using 'super_diff/rspec-rails'" do
5
5
  include_context "integration with HashWithIndifferentAccess"
6
6
 
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe "Integration with RSpec's #be_* matcher", type: :integration do
3
+ RSpec.describe "Integration with RSpec's #be_<predicate> matcher", type: :integration do
4
4
  # rubocop:disable Metrics/BlockLength
5
5
  ["be", "be_a", "be_an"].each do |prefix|
6
6
  # rubocop:enable Metrics/BlockLength
@@ -23,9 +23,9 @@ RSpec.describe "Integration with RSpec's #be_* matcher", type: :integration do
23
23
  plain "Expected "
24
24
  beta %|:foo|
25
25
  plain " to respond to "
26
- alpha %|`strong?`|
26
+ alpha %|strong?|
27
27
  plain " or "
28
- alpha %|`strongs?`|
28
+ alpha %|strongs?|
29
29
  plain "."
30
30
  end
31
31
  },
@@ -42,7 +42,7 @@ RSpec.describe "Integration with RSpec's #be_* matcher", type: :integration do
42
42
  it "produces the correct failure message" do
43
43
  as_both_colored_and_uncolored do |color_enabled|
44
44
  snippet = <<~TEST.strip
45
- hash = { foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz" }
45
+ hash = { foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz", aaaaaa: "bbbbbb" }
46
46
  expect(hash).to #{prefix}_strong
47
47
  TEST
48
48
  program = make_plain_test_program(
@@ -57,14 +57,14 @@ RSpec.describe "Integration with RSpec's #be_* matcher", type: :integration do
57
57
  expectation: proc {
58
58
  line do
59
59
  plain " Expected "
60
- beta %|{ foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz" }|
60
+ beta %|{ foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz", aaaaaa: "bbbbbb" }|
61
61
  end
62
62
 
63
63
  line do
64
64
  plain "to respond to "
65
- alpha %|`strong?`|
65
+ alpha %|strong?|
66
66
  plain " or "
67
- alpha %|`strongs?`|
67
+ alpha %|strongs?|
68
68
  end
69
69
  },
70
70
  )
@@ -102,9 +102,9 @@ RSpec.describe "Integration with RSpec's #be_* matcher", type: :integration do
102
102
  plain "Expected "
103
103
  beta %|#<Foo>|
104
104
  plain " to have a public method "
105
- alpha %|`strong?`|
105
+ alpha %|strong?|
106
106
  plain " or "
107
- alpha %|`strongs?`|
107
+ alpha %|strongs?|
108
108
  plain "."
109
109
  end
110
110
  },
@@ -147,9 +147,9 @@ RSpec.describe "Integration with RSpec's #be_* matcher", type: :integration do
147
147
 
148
148
  line do
149
149
  plain "to have a public method "
150
- alpha %|`strong?`|
150
+ alpha %|strong?|
151
151
  plain " or "
152
- alpha %|`strongs?`|
152
+ alpha %|strongs?|
153
153
  end
154
154
  },
155
155
  )
@@ -190,9 +190,9 @@ RSpec.describe "Integration with RSpec's #be_* matcher", type: :integration do
190
190
  plain "Expected "
191
191
  beta %|#<Foo>|
192
192
  plain " to return a truthy result for "
193
- alpha %|`true?`|
193
+ alpha %|true?|
194
194
  plain " or "
195
- alpha %|`trues?`|
195
+ alpha %|trues?|
196
196
  plain "."
197
197
  end
198
198
 
@@ -200,9 +200,9 @@ RSpec.describe "Integration with RSpec's #be_* matcher", type: :integration do
200
200
 
201
201
  line do
202
202
  plain "(Perhaps you want to use "
203
- blue "`be(true)`"
203
+ blue "be(true)"
204
204
  plain " or "
205
- blue "`be_truthy`"
205
+ blue "be_truthy"
206
206
  plain " instead?)"
207
207
  end
208
208
  },
@@ -250,18 +250,18 @@ RSpec.describe "Integration with RSpec's #be_* matcher", type: :integration do
250
250
 
251
251
  line do
252
252
  plain "to return a truthy result for "
253
- alpha %|`true?`|
253
+ alpha %|true?|
254
254
  plain " or "
255
- alpha %|`trues?`|
255
+ alpha %|trues?|
256
256
  end
257
257
 
258
258
  newline
259
259
 
260
260
  line do
261
261
  plain "(Perhaps you want to use "
262
- blue "`be(true)`"
262
+ blue "be(true)"
263
263
  plain " or "
264
- blue "`be_truthy`"
264
+ blue "be_truthy"
265
265
  plain " instead?)"
266
266
  end
267
267
  },
@@ -300,9 +300,9 @@ RSpec.describe "Integration with RSpec's #be_* matcher", type: :integration do
300
300
  plain "Expected "
301
301
  beta %|#<X>|
302
302
  plain " to return a truthy result for "
303
- alpha %|`false?`|
303
+ alpha %|false?|
304
304
  plain " or "
305
- alpha %|`falses?`|
305
+ alpha %|falses?|
306
306
  plain "."
307
307
  end
308
308
  },
@@ -341,9 +341,9 @@ RSpec.describe "Integration with RSpec's #be_* matcher", type: :integration do
341
341
  plain "Expected "
342
342
  beta %|#<X>|
343
343
  plain " to return a truthy result for "
344
- alpha %|`y?`|
344
+ alpha %|y?|
345
345
  plain " or "
346
- alpha %|`ys?`|
346
+ alpha %|ys?|
347
347
  plain "."
348
348
  end
349
349
  },
@@ -392,9 +392,9 @@ RSpec.describe "Integration with RSpec's #be_* matcher", type: :integration do
392
392
 
393
393
  line do
394
394
  plain "to return a truthy result for "
395
- alpha %|`y?`|
395
+ alpha %|y?|
396
396
  plain " or "
397
- alpha %|`ys?`|
397
+ alpha %|ys?|
398
398
  end
399
399
  },
400
400
  )
@@ -432,9 +432,9 @@ RSpec.describe "Integration with RSpec's #be_* matcher", type: :integration do
432
432
  plain "Expected "
433
433
  beta %|#<X>|
434
434
  plain " to return a truthy result for "
435
- alpha %|`y?`|
435
+ alpha %|y?|
436
436
  plain " or "
437
- alpha %|`ys?`|
437
+ alpha %|ys?|
438
438
  plain "."
439
439
  end
440
440
  },
@@ -483,9 +483,9 @@ RSpec.describe "Integration with RSpec's #be_* matcher", type: :integration do
483
483
 
484
484
  line do
485
485
  plain "to return a truthy result for "
486
- alpha %|`y?`|
486
+ alpha %|y?|
487
487
  plain " or "
488
- alpha %|`ys?`|
488
+ alpha %|ys?|
489
489
  end
490
490
  },
491
491
  )
@@ -502,40 +502,92 @@ RSpec.describe "Integration with RSpec's #be_* matcher", type: :integration do
502
502
  end
503
503
 
504
504
  context "and returns true" do
505
- it "produces the correct failure message when used in the negative" do
506
- as_both_colored_and_uncolored do |color_enabled|
507
- snippet = <<~TEST.strip
508
- class Foo
509
- def strong?; true; end
510
- end
505
+ context "when the inspected version of the actual value is short" do
506
+ it "produces the correct failure message when used in the negative" do
507
+ as_both_colored_and_uncolored do |color_enabled|
508
+ snippet = <<~TEST.strip
509
+ class Foo
510
+ def strong?; true; end
511
+ end
511
512
 
512
- expect(Foo.new).not_to #{prefix}_strong
513
- TEST
514
- program = make_plain_test_program(
515
- snippet,
516
- color_enabled: color_enabled,
517
- )
513
+ expect(Foo.new).not_to #{prefix}_strong
514
+ TEST
515
+ program = make_plain_test_program(
516
+ snippet,
517
+ color_enabled: color_enabled,
518
+ )
518
519
 
519
- expected_output = build_expected_output(
520
- color_enabled: color_enabled,
521
- snippet: %|expect(Foo.new).not_to #{prefix}_strong|,
522
- expectation: proc {
523
- line do
524
- plain "Expected "
525
- beta %|#<Foo>|
526
- plain " not to return a truthy result for "
527
- alpha %|`strong?`|
528
- plain " or "
529
- alpha %|`strongs?`|
530
- plain "."
520
+ expected_output = build_expected_output(
521
+ color_enabled: color_enabled,
522
+ snippet: %|expect(Foo.new).not_to #{prefix}_strong|,
523
+ expectation: proc {
524
+ line do
525
+ plain "Expected "
526
+ beta %|#<Foo>|
527
+ plain " not to return a truthy result for "
528
+ alpha %|strong?|
529
+ plain " or "
530
+ alpha %|strongs?|
531
+ plain "."
532
+ end
533
+ },
534
+ )
535
+
536
+ expect(program).
537
+ to produce_output_when_run(expected_output).
538
+ in_color(color_enabled).
539
+ removing_object_ids
540
+ end
541
+ end
542
+ end
543
+
544
+ context "when the inspected version of the actual value is long" do
545
+ it "produces the correct failure message when used in the negative" do
546
+ as_both_colored_and_uncolored do |color_enabled|
547
+ snippet = <<~TEST.strip
548
+ hash = {
549
+ foo: "bar",
550
+ baz: "qux",
551
+ blargh: "foz",
552
+ fizz: "buzz",
553
+ aaaaaa: "bbbbbb"
554
+ }
555
+
556
+ class << hash
557
+ def ys?; true; end
531
558
  end
532
- },
533
- )
534
559
 
535
- expect(program).
536
- to produce_output_when_run(expected_output).
537
- in_color(color_enabled).
538
- removing_object_ids
560
+ expect(hash).not_to #{prefix}_y
561
+ TEST
562
+ program = make_plain_test_program(
563
+ snippet,
564
+ color_enabled: color_enabled,
565
+ )
566
+
567
+ expected_output = build_expected_output(
568
+ color_enabled: color_enabled,
569
+ snippet: %|expect(hash).not_to #{prefix}_y|,
570
+ newline_before_expectation: true,
571
+ expectation: proc {
572
+ line do
573
+ plain " Expected "
574
+ beta %|{ foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz", aaaaaa: "bbbbbb" }|
575
+ end
576
+
577
+ line do
578
+ plain "not to return a truthy result for "
579
+ alpha %|y?|
580
+ plain " or "
581
+ alpha %|ys?|
582
+ end
583
+ },
584
+ )
585
+
586
+ expect(program).
587
+ to produce_output_when_run(expected_output).
588
+ in_color(color_enabled).
589
+ removing_object_ids
590
+ end
539
591
  end
540
592
  end
541
593
  end
@@ -142,7 +142,7 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
142
142
 
143
143
  it "produces the correct failure message when used in the negative" do
144
144
  as_both_colored_and_uncolored do |color_enabled|
145
- snippet = %|expect("Jennifer").to eq("Marty")|
145
+ snippet = %|expect("Jennifer").not_to eq("Jennifer")|
146
146
  program = make_plain_test_program(
147
147
  snippet,
148
148
  color_enabled: color_enabled,
@@ -150,16 +150,152 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
150
150
 
151
151
  expected_output = build_expected_output(
152
152
  color_enabled: color_enabled,
153
- snippet: %|expect("Jennifer").to eq("Marty")|,
153
+ snippet: %|expect("Jennifer").not_to eq("Jennifer")|,
154
154
  expectation: proc {
155
155
  line do
156
156
  plain "Expected "
157
157
  beta %|"Jennifer"|
158
+ plain " not to eq "
159
+ alpha %|"Jennifer"|
160
+ plain "."
161
+ end
162
+ },
163
+ )
164
+
165
+ expect(program).
166
+ to produce_output_when_run(expected_output).
167
+ in_color(color_enabled)
168
+ end
169
+ end
170
+ end
171
+
172
+ context "when comparing two different Time instances" do
173
+ it "produces the correct failure message when used in the positive" do
174
+ as_both_colored_and_uncolored do |color_enabled|
175
+ snippet = <<~RUBY
176
+ expected = Time.utc(2011, 12, 13, 14, 15, 16)
177
+ actual = Time.utc(2011, 12, 13, 14, 15, 16, 500_000)
178
+ expect(expected).to eq(actual)
179
+ RUBY
180
+ program = make_plain_test_program(
181
+ snippet,
182
+ color_enabled: color_enabled,
183
+ )
184
+
185
+ expected_output = build_expected_output(
186
+ color_enabled: color_enabled,
187
+ snippet: %|expect(expected).to eq(actual)|,
188
+ expectation: proc {
189
+ line do
190
+ plain "Expected "
191
+ beta %|2011-12-13 14:15:16.000 UTC +00:00 (Time)|
158
192
  plain " to eq "
159
- alpha %|"Marty"|
193
+ alpha %|2011-12-13 14:15:16.500 UTC +00:00 (Time)|
160
194
  plain "."
161
195
  end
162
196
  },
197
+ diff: proc {
198
+ plain_line " #<Time {"
199
+ plain_line " year: 2011,"
200
+ plain_line " month: 12,"
201
+ plain_line " day: 13,"
202
+ plain_line " hour: 14,"
203
+ plain_line " min: 15,"
204
+ plain_line " sec: 16,"
205
+ alpha_line "- nsec: 500000000,"
206
+ beta_line "+ nsec: 0,"
207
+ plain_line " zone: \"UTC\","
208
+ plain_line " gmt_offset: 0"
209
+ plain_line " }>"
210
+ },
211
+ )
212
+
213
+ expect(program).
214
+ to produce_output_when_run(expected_output).
215
+ in_color(color_enabled)
216
+ end
217
+ end
218
+
219
+ it "produces the correct failure message when used in the negative" do
220
+ as_both_colored_and_uncolored do |color_enabled|
221
+ snippet = <<~RUBY
222
+ time = Time.utc(2011, 12, 13, 14, 15, 16)
223
+ expect(time).not_to eq(time)
224
+ RUBY
225
+ program = make_plain_test_program(
226
+ snippet,
227
+ color_enabled: color_enabled,
228
+ )
229
+
230
+ expected_output = build_expected_output(
231
+ color_enabled: color_enabled,
232
+ snippet: %|expect(time).not_to eq(time)|,
233
+ newline_before_expectation: true,
234
+ expectation: proc {
235
+ line do
236
+ plain " Expected "
237
+ beta %|2011-12-13 14:15:16.000 UTC +00:00 (Time)|
238
+ end
239
+
240
+ line do
241
+ plain "not to eq "
242
+ alpha %|2011-12-13 14:15:16.000 UTC +00:00 (Time)|
243
+ end
244
+ },
245
+ )
246
+
247
+ expect(program).
248
+ to produce_output_when_run(expected_output).
249
+ in_color(color_enabled)
250
+ end
251
+ end
252
+ end
253
+
254
+ context "when comparing two different Time and ActiveSupport::TimeWithZone instances", active_record: true do
255
+ it "produces the correct failure message when used in the positive" do
256
+ as_both_colored_and_uncolored do |color_enabled|
257
+ snippet = <<~RUBY
258
+ expected = Time.utc(2011, 12, 13, 14, 15, 16)
259
+ actual = Time.utc(2011, 12, 13, 15, 15, 16).in_time_zone("Europe/Stockholm")
260
+ expect(expected).to eq(actual)
261
+ RUBY
262
+ program = make_rspec_rails_test_program(
263
+ snippet,
264
+ color_enabled: color_enabled,
265
+ )
266
+
267
+ expected_output = build_expected_output(
268
+ color_enabled: color_enabled,
269
+ snippet: %|expect(expected).to eq(actual)|,
270
+ expectation: proc {
271
+ line do
272
+ plain "Expected "
273
+ beta %|2011-12-13 14:15:16.000 UTC +00:00 (Time)|
274
+ end
275
+
276
+ line do
277
+ plain " to eq "
278
+ alpha %|2011-12-13 16:15:16.000 CET +01:00 (ActiveSupport::TimeWithZone)|
279
+ end
280
+ },
281
+ diff: proc {
282
+ plain_line " #<ActiveSupport::TimeWithZone {"
283
+ plain_line " year: 2011,"
284
+ plain_line " month: 12,"
285
+ plain_line " day: 13,"
286
+ alpha_line "- hour: 16,"
287
+ beta_line "+ hour: 14,"
288
+ plain_line " min: 15,"
289
+ plain_line " sec: 16,"
290
+ plain_line " nsec: 0,"
291
+ alpha_line "- zone: \"CET\","
292
+ beta_line "+ zone: \"UTC\","
293
+ alpha_line "- gmt_offset: 3600,"
294
+ beta_line "+ gmt_offset: 0,"
295
+ alpha_line "- utc: 2011-12-13 15:15:16.000 UTC +00:00 (Time)"
296
+ beta_line "+ utc: 2011-12-13 14:15:16.000 UTC +00:00 (Time)"
297
+ plain_line " }>"
298
+ },
163
299
  )
164
300
 
165
301
  expect(program).