super_diff 0.12.1 → 0.15.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 (272) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -19
  3. data/lib/super_diff/active_record/differs/active_record_relation.rb +2 -0
  4. data/lib/super_diff/active_record/differs.rb +3 -1
  5. data/lib/super_diff/active_record/inspection_tree_builders/active_record_model.rb +7 -5
  6. data/lib/super_diff/active_record/inspection_tree_builders/active_record_relation.rb +12 -10
  7. data/lib/super_diff/active_record/inspection_tree_builders.rb +4 -2
  8. data/lib/super_diff/active_record/monkey_patches.rb +4 -2
  9. data/lib/super_diff/active_record/object_inspection.rb +6 -4
  10. data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +3 -1
  11. data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +3 -1
  12. data/lib/super_diff/active_record/operation_tree_builders.rb +4 -2
  13. data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +4 -2
  14. data/lib/super_diff/active_record/operation_tree_flatteners.rb +3 -1
  15. data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +2 -0
  16. data/lib/super_diff/active_record/operation_trees.rb +3 -1
  17. data/lib/super_diff/active_record.rb +10 -8
  18. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +2 -0
  19. data/lib/super_diff/active_support/differs.rb +3 -1
  20. data/lib/super_diff/active_support/inspection_tree_builders/hash_with_indifferent_access.rb +16 -14
  21. data/lib/super_diff/active_support/inspection_tree_builders/ordered_options.rb +16 -14
  22. data/lib/super_diff/active_support/inspection_tree_builders.rb +4 -2
  23. data/lib/super_diff/active_support/object_inspection.rb +6 -4
  24. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +6 -4
  25. data/lib/super_diff/active_support/operation_tree_builders.rb +3 -1
  26. data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +4 -2
  27. data/lib/super_diff/active_support/operation_tree_flatteners.rb +3 -1
  28. data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +2 -0
  29. data/lib/super_diff/active_support/operation_trees.rb +3 -1
  30. data/lib/super_diff/active_support.rb +8 -6
  31. data/lib/super_diff/basic/diff_formatters/collection.rb +18 -18
  32. data/lib/super_diff/basic/diff_formatters/multiline_string.rb +2 -0
  33. data/lib/super_diff/basic/diff_formatters.rb +4 -2
  34. data/lib/super_diff/basic/differs/array.rb +2 -0
  35. data/lib/super_diff/basic/differs/custom_object.rb +3 -1
  36. data/lib/super_diff/basic/differs/date_like.rb +2 -0
  37. data/lib/super_diff/basic/differs/default_object.rb +3 -1
  38. data/lib/super_diff/basic/differs/hash.rb +2 -0
  39. data/lib/super_diff/basic/differs/multiline_string.rb +2 -0
  40. data/lib/super_diff/basic/differs/time_like.rb +2 -0
  41. data/lib/super_diff/basic/differs.rb +11 -9
  42. data/lib/super_diff/basic/inspection_tree_builders/array.rb +5 -3
  43. data/lib/super_diff/basic/inspection_tree_builders/custom_object.rb +5 -3
  44. data/lib/super_diff/basic/inspection_tree_builders/data_object.rb +42 -0
  45. data/lib/super_diff/basic/inspection_tree_builders/date_like.rb +7 -5
  46. data/lib/super_diff/basic/inspection_tree_builders/default_object.rb +7 -5
  47. data/lib/super_diff/basic/inspection_tree_builders/hash.rb +7 -5
  48. data/lib/super_diff/basic/inspection_tree_builders/primitive.rb +3 -1
  49. data/lib/super_diff/basic/inspection_tree_builders/range_object.rb +19 -0
  50. data/lib/super_diff/basic/inspection_tree_builders/time_like.rb +8 -8
  51. data/lib/super_diff/basic/inspection_tree_builders.rb +18 -8
  52. data/lib/super_diff/basic/operation_tree_builders/array.rb +6 -4
  53. data/lib/super_diff/basic/operation_tree_builders/custom_object.rb +3 -1
  54. data/lib/super_diff/basic/operation_tree_builders/data_object.rb +20 -0
  55. data/lib/super_diff/basic/operation_tree_builders/date_like.rb +2 -0
  56. data/lib/super_diff/basic/operation_tree_builders/default_object.rb +32 -31
  57. data/lib/super_diff/basic/operation_tree_builders/hash.rb +49 -46
  58. data/lib/super_diff/basic/operation_tree_builders/multiline_string.rb +5 -3
  59. data/lib/super_diff/basic/operation_tree_builders/time_like.rb +5 -3
  60. data/lib/super_diff/basic/operation_tree_builders.rb +15 -9
  61. data/lib/super_diff/basic/operation_tree_flatteners/array.rb +4 -2
  62. data/lib/super_diff/basic/operation_tree_flatteners/collection.rb +11 -11
  63. data/lib/super_diff/basic/operation_tree_flatteners/custom_object.rb +5 -3
  64. data/lib/super_diff/basic/operation_tree_flatteners/default_object.rb +6 -5
  65. data/lib/super_diff/basic/operation_tree_flatteners/hash.rb +5 -3
  66. data/lib/super_diff/basic/operation_tree_flatteners/multiline_string.rb +3 -1
  67. data/lib/super_diff/basic/operation_tree_flatteners.rb +8 -6
  68. data/lib/super_diff/basic/operation_trees/array.rb +2 -0
  69. data/lib/super_diff/basic/operation_trees/custom_object.rb +2 -0
  70. data/lib/super_diff/basic/operation_trees/default_object.rb +6 -4
  71. data/lib/super_diff/basic/operation_trees/hash.rb +2 -0
  72. data/lib/super_diff/basic/operation_trees/multiline_string.rb +3 -1
  73. data/lib/super_diff/basic/operation_trees.rb +9 -7
  74. data/lib/super_diff/basic.rb +12 -7
  75. data/lib/super_diff/core/abstract_differ.rb +2 -0
  76. data/lib/super_diff/core/abstract_inspection_tree_builder.rb +2 -0
  77. data/lib/super_diff/core/abstract_operation_tree.rb +4 -2
  78. data/lib/super_diff/core/abstract_operation_tree_builder.rb +15 -18
  79. data/lib/super_diff/core/abstract_operation_tree_flattener.rb +5 -3
  80. data/lib/super_diff/core/binary_operation.rb +3 -1
  81. data/lib/super_diff/core/colorized_document_extensions.rb +2 -0
  82. data/lib/super_diff/core/configuration.rb +23 -43
  83. data/lib/super_diff/core/differ_dispatcher.rb +4 -2
  84. data/lib/super_diff/core/gem_version.rb +2 -0
  85. data/lib/super_diff/core/helpers.rb +14 -12
  86. data/lib/super_diff/core/implementation_checks.rb +6 -2
  87. data/lib/super_diff/core/inspection_tree.rb +38 -38
  88. data/lib/super_diff/core/inspection_tree_builder_dispatcher.rb +5 -5
  89. data/lib/super_diff/core/inspection_tree_nodes/as_lines_when_rendering_to_lines.rb +3 -1
  90. data/lib/super_diff/core/inspection_tree_nodes/as_prefix_when_rendering_to_lines.rb +2 -0
  91. data/lib/super_diff/core/inspection_tree_nodes/as_prelude_when_rendering_to_lines.rb +2 -0
  92. data/lib/super_diff/core/inspection_tree_nodes/as_single_line.rb +2 -0
  93. data/lib/super_diff/core/inspection_tree_nodes/base.rb +9 -9
  94. data/lib/super_diff/core/inspection_tree_nodes/inspection.rb +2 -0
  95. data/lib/super_diff/core/inspection_tree_nodes/nesting.rb +2 -0
  96. data/lib/super_diff/core/inspection_tree_nodes/only_when.rb +5 -1
  97. data/lib/super_diff/core/inspection_tree_nodes/text.rb +2 -0
  98. data/lib/super_diff/core/inspection_tree_nodes/when_empty.rb +3 -1
  99. data/lib/super_diff/core/inspection_tree_nodes/when_non_empty.rb +3 -1
  100. data/lib/super_diff/core/inspection_tree_nodes/when_rendering_to_lines.rb +3 -1
  101. data/lib/super_diff/core/inspection_tree_nodes/when_rendering_to_string.rb +2 -0
  102. data/lib/super_diff/core/inspection_tree_nodes.rb +16 -14
  103. data/lib/super_diff/core/line.rb +9 -7
  104. data/lib/super_diff/core/no_differ_available_error.rb +7 -5
  105. data/lib/super_diff/core/no_inspection_tree_builder_available_error.rb +5 -3
  106. data/lib/super_diff/core/no_operation_tree_available_error.rb +4 -2
  107. data/lib/super_diff/core/no_operation_tree_builder_available_error.rb +7 -5
  108. data/lib/super_diff/core/operation_tree_builder_dispatcher.rb +3 -3
  109. data/lib/super_diff/core/operation_tree_finder.rb +8 -8
  110. data/lib/super_diff/core/prefix_for_next_inspection_tree_node.rb +2 -0
  111. data/lib/super_diff/core/prelude_for_next_inspection_tree_node.rb +2 -0
  112. data/lib/super_diff/core/recursion_guard.rb +6 -4
  113. data/lib/super_diff/core/tiered_lines.rb +2 -0
  114. data/lib/super_diff/core/tiered_lines_elider.rb +53 -54
  115. data/lib/super_diff/core/tiered_lines_formatter.rb +6 -4
  116. data/lib/super_diff/core/unary_operation.rb +2 -0
  117. data/lib/super_diff/core.rb +31 -29
  118. data/lib/super_diff/csi/bold_sequence.rb +2 -0
  119. data/lib/super_diff/csi/color.rb +4 -4
  120. data/lib/super_diff/csi/color_sequence_block.rb +3 -1
  121. data/lib/super_diff/csi/colorized_document.rb +7 -9
  122. data/lib/super_diff/csi/document.rb +15 -18
  123. data/lib/super_diff/csi/eight_bit_color.rb +32 -37
  124. data/lib/super_diff/csi/four_bit_color.rb +12 -9
  125. data/lib/super_diff/csi/reset_sequence.rb +2 -0
  126. data/lib/super_diff/csi/twenty_four_bit_color.rb +22 -21
  127. data/lib/super_diff/csi/uncolorized_document.rb +2 -0
  128. data/lib/super_diff/csi.rb +12 -42
  129. data/lib/super_diff/differs.rb +6 -4
  130. data/lib/super_diff/equality_matchers/array.rb +18 -16
  131. data/lib/super_diff/equality_matchers/base.rb +6 -4
  132. data/lib/super_diff/equality_matchers/default.rb +5 -3
  133. data/lib/super_diff/equality_matchers/defaults.rb +3 -1
  134. data/lib/super_diff/equality_matchers/hash.rb +18 -16
  135. data/lib/super_diff/equality_matchers/main.rb +3 -1
  136. data/lib/super_diff/equality_matchers/multiline_string.rb +18 -16
  137. data/lib/super_diff/equality_matchers/primitive.rb +15 -13
  138. data/lib/super_diff/equality_matchers/singleline_string.rb +16 -14
  139. data/lib/super_diff/equality_matchers.rb +11 -9
  140. data/lib/super_diff/errors.rb +4 -2
  141. data/lib/super_diff/object_inspection.rb +17 -15
  142. data/lib/super_diff/operation_tree_builders.rb +6 -4
  143. data/lib/super_diff/operation_tree_flatteners.rb +6 -4
  144. data/lib/super_diff/operation_trees.rb +6 -4
  145. data/lib/super_diff/operations.rb +4 -2
  146. data/lib/super_diff/rails.rb +4 -2
  147. data/lib/super_diff/rspec/augmented_matcher.rb +3 -1
  148. data/lib/super_diff/rspec/differ.rb +16 -7
  149. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +2 -0
  150. data/lib/super_diff/rspec/differs/collection_including.rb +2 -0
  151. data/lib/super_diff/rspec/differs/hash_including.rb +2 -0
  152. data/lib/super_diff/rspec/differs/object_having_attributes.rb +2 -0
  153. data/lib/super_diff/rspec/differs.rb +6 -4
  154. data/lib/super_diff/rspec/inspection_tree_builders/collection_containing_exactly.rb +12 -10
  155. data/lib/super_diff/rspec/inspection_tree_builders/collection_including.rb +10 -8
  156. data/lib/super_diff/rspec/inspection_tree_builders/double.rb +20 -18
  157. data/lib/super_diff/rspec/inspection_tree_builders/generic_describable_matcher.rb +2 -0
  158. data/lib/super_diff/rspec/inspection_tree_builders/hash_including.rb +10 -8
  159. data/lib/super_diff/rspec/inspection_tree_builders/instance_of.rb +2 -0
  160. data/lib/super_diff/rspec/inspection_tree_builders/kind_of.rb +2 -0
  161. data/lib/super_diff/rspec/inspection_tree_builders/object_having_attributes.rb +12 -10
  162. data/lib/super_diff/rspec/inspection_tree_builders/primitive.rb +2 -0
  163. data/lib/super_diff/rspec/inspection_tree_builders/value_within.rb +6 -4
  164. data/lib/super_diff/rspec/inspection_tree_builders.rb +12 -10
  165. data/lib/super_diff/rspec/matcher_text_builders/base.rb +12 -12
  166. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +19 -17
  167. data/lib/super_diff/rspec/matcher_text_builders/contain_exactly.rb +3 -1
  168. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +7 -5
  169. data/lib/super_diff/rspec/matcher_text_builders/match.rb +6 -4
  170. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +5 -3
  171. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +20 -18
  172. data/lib/super_diff/rspec/matcher_text_builders.rb +9 -7
  173. data/lib/super_diff/rspec/matcher_text_template.rb +34 -39
  174. data/lib/super_diff/rspec/monkey_patches.rb +129 -56
  175. data/lib/super_diff/rspec/object_inspection.rb +7 -5
  176. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +4 -4
  177. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +2 -0
  178. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +2 -0
  179. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +2 -0
  180. data/lib/super_diff/rspec/operation_tree_builders.rb +6 -4
  181. data/lib/super_diff/rspec-rails.rb +4 -2
  182. data/lib/super_diff/rspec.rb +27 -14
  183. data/lib/super_diff/version.rb +3 -1
  184. data/lib/super_diff.rb +24 -27
  185. data/super_diff.gemspec +20 -18
  186. metadata +15 -182
  187. data/spec/examples.txt +0 -704
  188. data/spec/integration/rails/active_record_spec.rb +0 -21
  189. data/spec/integration/rails/active_support_spec.rb +0 -19
  190. data/spec/integration/rails/engines_spec.rb +0 -25
  191. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +0 -21
  192. data/spec/integration/rspec/be_falsey_matcher_spec.rb +0 -58
  193. data/spec/integration/rspec/be_matcher_spec.rb +0 -605
  194. data/spec/integration/rspec/be_nil_matcher_spec.rb +0 -57
  195. data/spec/integration/rspec/be_predicate_matcher_spec.rb +0 -615
  196. data/spec/integration/rspec/be_truthy_matcher_spec.rb +0 -62
  197. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +0 -377
  198. data/spec/integration/rspec/eq_matcher_spec.rb +0 -1066
  199. data/spec/integration/rspec/generic_describable_matchers_spec.rb +0 -177
  200. data/spec/integration/rspec/have_attributes_matcher_spec.rb +0 -443
  201. data/spec/integration/rspec/have_predicate_matcher_spec.rb +0 -478
  202. data/spec/integration/rspec/include_matcher_spec.rb +0 -452
  203. data/spec/integration/rspec/magic_metadata_spec.rb +0 -51
  204. data/spec/integration/rspec/match_array_matcher_spec.rb +0 -424
  205. data/spec/integration/rspec/match_matcher_spec.rb +0 -1359
  206. data/spec/integration/rspec/raise_error_matcher_spec.rb +0 -1488
  207. data/spec/integration/rspec/respond_to_matcher_spec.rb +0 -999
  208. data/spec/integration/rspec/third_party_matcher_spec.rb +0 -245
  209. data/spec/integration/rspec/unhandled_errors_spec.rb +0 -150
  210. data/spec/internal/log/test.log +0 -0
  211. data/spec/spec_helper.rb +0 -90
  212. data/spec/support/colorizer.rb +0 -9
  213. data/spec/support/command_runner.rb +0 -253
  214. data/spec/support/helpers.rb +0 -21
  215. data/spec/support/integration/helpers.rb +0 -124
  216. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +0 -104
  217. data/spec/support/integration/matchers.rb +0 -177
  218. data/spec/support/integration/test_programs/base.rb +0 -143
  219. data/spec/support/integration/test_programs/plain.rb +0 -19
  220. data/spec/support/integration/test_programs/rspec_active_record.rb +0 -20
  221. data/spec/support/integration/test_programs/rspec_active_support.rb +0 -20
  222. data/spec/support/integration/test_programs/rspec_rails.rb +0 -20
  223. data/spec/support/integration/test_programs/rspec_rails_engine.rb +0 -20
  224. data/spec/support/models/a.rb +0 -11
  225. data/spec/support/models/active_record/person.rb +0 -28
  226. data/spec/support/models/active_record/query.rb +0 -15
  227. data/spec/support/models/active_record/shipping_address.rb +0 -24
  228. data/spec/support/models/customer.rb +0 -22
  229. data/spec/support/models/empty_class.rb +0 -6
  230. data/spec/support/models/item.rb +0 -10
  231. data/spec/support/models/order.rb +0 -9
  232. data/spec/support/models/person.rb +0 -20
  233. data/spec/support/models/player.rb +0 -30
  234. data/spec/support/models/shipping_address.rb +0 -25
  235. data/spec/support/shared_examples/active_record.rb +0 -428
  236. data/spec/support/shared_examples/active_support.rb +0 -188
  237. data/spec/support/shared_examples/elided_diffs.rb +0 -938
  238. data/spec/support/shared_examples/hash_with_indifferent_access.rb +0 -749
  239. data/spec/support/shared_examples/key.rb +0 -123
  240. data/spec/support/unit/helpers.rb +0 -24
  241. data/spec/support/unit/matchers/be_deprecated_in_favor_of.rb +0 -39
  242. data/spec/support/unit/matchers/match_output.rb +0 -40
  243. data/spec/unit/active_record/object_inspection_spec.rb +0 -289
  244. data/spec/unit/active_support/object_inspection_spec.rb +0 -170
  245. data/spec/unit/basic/operation_tree_flatteners/array_spec.rb +0 -637
  246. data/spec/unit/basic/operation_tree_flatteners/custom_object_spec.rb +0 -685
  247. data/spec/unit/basic/operation_tree_flatteners/default_object_spec.rb +0 -685
  248. data/spec/unit/basic/operation_tree_flatteners/hash_spec.rb +0 -671
  249. data/spec/unit/basic/operation_tree_flatteners/multiline_string_spec.rb +0 -131
  250. data/spec/unit/core/helpers_spec.rb +0 -68
  251. data/spec/unit/core/tiered_lines_elider_spec.rb +0 -6328
  252. data/spec/unit/core/tiered_lines_formatter_spec.rb +0 -131
  253. data/spec/unit/deprecations_spec.rb +0 -176
  254. data/spec/unit/equality_matchers/main_spec.rb +0 -1842
  255. data/spec/unit/rspec/matchers/be_compared_to_spec.rb +0 -23
  256. data/spec/unit/rspec/matchers/be_falsey_spec.rb +0 -9
  257. data/spec/unit/rspec/matchers/be_nil_spec.rb +0 -9
  258. data/spec/unit/rspec/matchers/be_predicate_spec.rb +0 -31
  259. data/spec/unit/rspec/matchers/be_spec.rb +0 -17
  260. data/spec/unit/rspec/matchers/be_truthy_spec.rb +0 -9
  261. data/spec/unit/rspec/matchers/contain_exactly_spec.rb +0 -11
  262. data/spec/unit/rspec/matchers/eq_spec.rb +0 -9
  263. data/spec/unit/rspec/matchers/have_attributes_spec.rb +0 -11
  264. data/spec/unit/rspec/matchers/have_predicate_spec.rb +0 -21
  265. data/spec/unit/rspec/matchers/include_spec.rb +0 -21
  266. data/spec/unit/rspec/matchers/match_array_spec.rb +0 -11
  267. data/spec/unit/rspec/matchers/match_spec.rb +0 -9
  268. data/spec/unit/rspec/matchers/raise_error_spec.rb +0 -77
  269. data/spec/unit/rspec/matchers/respond_to_spec.rb +0 -85
  270. data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +0 -91
  271. data/spec/unit/rspec/object_inspection_spec.rb +0 -471
  272. data/spec/unit/super_diff_spec.rb +0 -2115
@@ -1,1359 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
4
- context "when the expected value is a hash-including-<something>" do
5
- context "that is small" do
6
- it "produces the correct failure message when used in the positive" do
7
- as_both_colored_and_uncolored do |color_enabled|
8
- snippet = <<~TEST.strip
9
- actual = { city: "Burbank" }
10
- expected = a_hash_including(city: "Hill Valley")
11
- expect(actual).to match(expected)
12
- TEST
13
- program =
14
- make_plain_test_program(snippet, color_enabled: color_enabled)
15
-
16
- expected_output =
17
- build_expected_output(
18
- color_enabled: color_enabled,
19
- snippet: "expect(actual).to match(expected)",
20
- expectation:
21
- proc do
22
- line do
23
- plain "Expected "
24
- actual %|{ city: "Burbank" }|
25
- plain " to match "
26
- expected %|#<a hash including (city: "Hill Valley")>|
27
- plain "."
28
- end
29
- end,
30
- diff:
31
- proc do
32
- plain_line " {"
33
- expected_line %|- city: "Hill Valley"|
34
- actual_line %|+ city: "Burbank"|
35
- plain_line " }"
36
- end
37
- )
38
-
39
- expect(program).to produce_output_when_run(expected_output).in_color(
40
- color_enabled
41
- )
42
- end
43
- end
44
-
45
- it "produces the correct failure message when used in the negative" do
46
- as_both_colored_and_uncolored do |color_enabled|
47
- snippet = <<~TEST.strip
48
- actual = { city: "Burbank" }
49
- expected = a_hash_including(city: "Burbank")
50
- expect(actual).not_to match(expected)
51
- TEST
52
- program =
53
- make_plain_test_program(snippet, color_enabled: color_enabled)
54
-
55
- expected_output =
56
- build_expected_output(
57
- color_enabled: color_enabled,
58
- snippet: "expect(actual).not_to match(expected)",
59
- expectation:
60
- proc do
61
- line do
62
- plain "Expected "
63
- actual %|{ city: "Burbank" }|
64
- plain " not to match "
65
- expected %|#<a hash including (city: "Burbank")>|
66
- plain "."
67
- end
68
- end
69
- )
70
-
71
- expect(program).to produce_output_when_run(expected_output).in_color(
72
- color_enabled
73
- )
74
- end
75
- end
76
- end
77
-
78
- context "that is large" do
79
- it "produces the correct failure message when used in the positive" do
80
- as_both_colored_and_uncolored do |color_enabled|
81
- snippet = <<~TEST.strip
82
- actual = {
83
- line_1: "123 Main St.",
84
- city: "Burbank",
85
- state: "CA",
86
- zip: "90210"
87
- }
88
- expected = a_hash_including(
89
- city: "Hill Valley",
90
- zip: "90382"
91
- )
92
- expect(actual).to match(expected)
93
- TEST
94
- program =
95
- make_plain_test_program(snippet, color_enabled: color_enabled)
96
-
97
- expected_output =
98
- build_expected_output(
99
- color_enabled: color_enabled,
100
- snippet: "expect(actual).to match(expected)",
101
- expectation:
102
- proc do
103
- line do
104
- plain "Expected "
105
- actual %|{ line_1: "123 Main St.", city: "Burbank", state: "CA", zip: "90210" }|
106
- end
107
-
108
- line do
109
- plain "to match "
110
- expected %|#<a hash including (city: "Hill Valley", zip: "90382")>|
111
- end
112
- end,
113
- diff:
114
- proc do
115
- plain_line " {"
116
- plain_line %| line_1: "123 Main St.",|
117
- expected_line %|- city: "Hill Valley",|
118
- actual_line %|+ city: "Burbank",|
119
- plain_line %| state: "CA",|
120
- expected_line %|- zip: "90382"|
121
- actual_line %|+ zip: "90210"|
122
- plain_line " }"
123
- end
124
- )
125
-
126
- expect(program).to produce_output_when_run(expected_output).in_color(
127
- color_enabled
128
- )
129
- end
130
- end
131
-
132
- it "produces the correct failure message when used in the negative" do
133
- as_both_colored_and_uncolored do |color_enabled|
134
- snippet = <<~TEST.strip
135
- actual = {
136
- line_1: "123 Main St.",
137
- city: "Burbank",
138
- state: "CA",
139
- zip: "90210"
140
- }
141
- expected = a_hash_including(
142
- city: "Burbank",
143
- zip: "90210"
144
- )
145
- expect(actual).not_to match(expected)
146
- TEST
147
- program =
148
- make_plain_test_program(snippet, color_enabled: color_enabled)
149
-
150
- expected_output =
151
- build_expected_output(
152
- color_enabled: color_enabled,
153
- snippet: "expect(actual).not_to match(expected)",
154
- newline_before_expectation: true,
155
- expectation:
156
- proc do
157
- line do
158
- plain " Expected "
159
- actual %|{ line_1: "123 Main St.", city: "Burbank", state: "CA", zip: "90210" }|
160
- end
161
-
162
- line do
163
- plain "not to match "
164
- expected %|#<a hash including (city: "Burbank", zip: "90210")>|
165
- end
166
- end
167
- )
168
-
169
- expect(program).to produce_output_when_run(expected_output).in_color(
170
- color_enabled
171
- )
172
- end
173
- end
174
- end
175
- end
176
-
177
- context "when the expected value includes a hash-including-<something>" do
178
- context "and the corresponding actual value is a hash" do
179
- it "produces the correct failure message when used in the positive" do
180
- as_both_colored_and_uncolored do |color_enabled|
181
- snippet = <<~TEST.strip
182
- actual = {
183
- name: "Marty McFly",
184
- address: {
185
- line_1: "123 Main St.",
186
- city: "Burbank",
187
- state: "CA",
188
- zip: "90210"
189
- }
190
- }
191
- expected = {
192
- name: "Marty McFly",
193
- address: a_hash_including(
194
- city: "Hill Valley",
195
- zip: "90382"
196
- )
197
- }
198
- expect(actual).to match(expected)
199
- TEST
200
- program =
201
- make_plain_test_program(snippet, color_enabled: color_enabled)
202
-
203
- expected_output =
204
- build_expected_output(
205
- color_enabled: color_enabled,
206
- snippet: "expect(actual).to match(expected)",
207
- expectation:
208
- proc do
209
- line do
210
- plain "Expected "
211
- actual %|{ name: "Marty McFly", address: { line_1: "123 Main St.", city: "Burbank", state: "CA", zip: "90210" } }|
212
- end
213
-
214
- line do
215
- plain "to match "
216
- expected %|{ name: "Marty McFly", address: #<a hash including (city: "Hill Valley", zip: "90382")> }|
217
- end
218
- end,
219
- diff:
220
- proc do
221
- plain_line " {"
222
- plain_line %| name: "Marty McFly",|
223
- plain_line " address: {"
224
- plain_line %| line_1: "123 Main St.",|
225
- expected_line %|- city: "Hill Valley",|
226
- actual_line %|+ city: "Burbank",|
227
- plain_line %| state: "CA",|
228
- expected_line %|- zip: "90382"|
229
- actual_line %|+ zip: "90210"|
230
- plain_line " }"
231
- plain_line " }"
232
- end
233
- )
234
-
235
- expect(program).to produce_output_when_run(expected_output).in_color(
236
- color_enabled
237
- )
238
- end
239
- end
240
-
241
- it "produces the correct failure message when used in the negative" do
242
- as_both_colored_and_uncolored do |color_enabled|
243
- snippet = <<~TEST.strip
244
- actual = {
245
- name: "Marty McFly",
246
- address: {
247
- line_1: "123 Main St.",
248
- city: "Burbank",
249
- state: "CA",
250
- zip: "90210"
251
- }
252
- }
253
- expected = {
254
- name: "Marty McFly",
255
- address: a_hash_including(
256
- city: "Burbank",
257
- zip: "90210"
258
- )
259
- }
260
- expect(actual).not_to match(expected)
261
- TEST
262
- program =
263
- make_plain_test_program(snippet, color_enabled: color_enabled)
264
-
265
- expected_output =
266
- build_expected_output(
267
- color_enabled: color_enabled,
268
- snippet: "expect(actual).not_to match(expected)",
269
- newline_before_expectation: true,
270
- expectation:
271
- proc do
272
- line do
273
- plain " Expected "
274
- actual %|{ name: "Marty McFly", address: { line_1: "123 Main St.", city: "Burbank", state: "CA", zip: "90210" } }|
275
- end
276
-
277
- line do
278
- plain "not to match "
279
- expected %|{ name: "Marty McFly", address: #<a hash including (city: "Burbank", zip: "90210")> }|
280
- end
281
- end
282
- )
283
-
284
- expect(program).to produce_output_when_run(expected_output).in_color(
285
- color_enabled
286
- )
287
- end
288
- end
289
- end
290
-
291
- context "and the corresponding actual value is not a hash" do
292
- it "produces the correct failure message" do
293
- as_both_colored_and_uncolored do |color_enabled|
294
- snippet = <<~TEST.strip
295
- actual = {
296
- name: "Marty McFly",
297
- address: nil
298
- }
299
- expected = {
300
- name: "Marty McFly",
301
- address: a_hash_including(
302
- city: "Hill Valley",
303
- zip: "90382"
304
- )
305
- }
306
- expect(actual).to match(expected)
307
- TEST
308
- program =
309
- make_plain_test_program(snippet, color_enabled: color_enabled)
310
-
311
- expected_output =
312
- build_expected_output(
313
- color_enabled: color_enabled,
314
- snippet: "expect(actual).to match(expected)",
315
- expectation:
316
- proc do
317
- line do
318
- plain "Expected "
319
- actual %|{ name: "Marty McFly", address: nil }|
320
- end
321
-
322
- line do
323
- plain "to match "
324
- expected %|{ name: "Marty McFly", address: #<a hash including (city: "Hill Valley", zip: "90382")> }|
325
- end
326
- end,
327
- diff:
328
- proc do
329
- plain_line " {"
330
- plain_line %! name: "Marty McFly",!
331
- expected_line "- address: #<a hash including ("
332
- expected_line %!- city: "Hill Valley",!
333
- expected_line %!- zip: "90382"!
334
- expected_line "- )>"
335
- actual_line "+ address: nil"
336
- plain_line " }"
337
- end
338
- )
339
-
340
- expect(program).to produce_output_when_run(expected_output).in_color(
341
- color_enabled
342
- )
343
- end
344
- end
345
- end
346
- end
347
-
348
- # HINT: `a_hash_including` is an alias of `include` in the rspec-expectations gem.
349
- # `hash_including` is an argument matcher in the rspec-mocks gem.
350
- context "when the expected value is `hash-including-<something>`, not `a-hash-including-<something>`" do
351
- it "produces the correct failure message" do
352
- as_both_colored_and_uncolored do |color_enabled|
353
- snippet = <<~TEST.strip
354
- actual = { city: "Burbank" }
355
- expected = hash_including(city: "Hill Valley")
356
- expect(actual).to match(expected)
357
- TEST
358
- program = make_plain_test_program(snippet, color_enabled: color_enabled)
359
-
360
- expected_output =
361
- build_expected_output(
362
- color_enabled: color_enabled,
363
- snippet: "expect(actual).to match(expected)",
364
- expectation:
365
- proc do
366
- line do
367
- plain "Expected "
368
- actual %|{ city: "Burbank" }|
369
- plain " to match "
370
- expected %|#<a hash including (city: "Hill Valley")>|
371
- plain "."
372
- end
373
- end,
374
- diff:
375
- proc do
376
- plain_line " {"
377
- expected_line %|- city: "Hill Valley"|
378
- actual_line %|+ city: "Burbank"|
379
- plain_line " }"
380
- end
381
- )
382
-
383
- expect(program).to produce_output_when_run(expected_output).in_color(
384
- color_enabled
385
- )
386
- end
387
- end
388
- end
389
-
390
- context "when the expected value is a collection-including-<something>" do
391
- context "that is small" do
392
- it "produces the correct failure message when used in the positive" do
393
- as_both_colored_and_uncolored do |color_enabled|
394
- snippet = <<~TEST.strip
395
- actual = ["b"]
396
- expected = a_collection_including("a")
397
- expect(actual).to match(expected)
398
- TEST
399
- program =
400
- make_plain_test_program(snippet, color_enabled: color_enabled)
401
-
402
- expected_output =
403
- build_expected_output(
404
- color_enabled: color_enabled,
405
- snippet: "expect(actual).to match(expected)",
406
- expectation:
407
- proc do
408
- line do
409
- plain "Expected "
410
- actual %|["b"]|
411
- plain " to match "
412
- expected %|#<a collection including ("a")>|
413
- plain "."
414
- end
415
- end,
416
- diff:
417
- proc do
418
- plain_line " ["
419
- plain_line %| "b"|
420
- # expected_line %|- "a",| # FIXME
421
- expected_line %|- "a"|
422
- plain_line " ]"
423
- end
424
- )
425
-
426
- expect(program).to produce_output_when_run(expected_output).in_color(
427
- color_enabled
428
- )
429
- end
430
- end
431
-
432
- it "produces the correct failure message when used in the negative" do
433
- as_both_colored_and_uncolored do |color_enabled|
434
- snippet = <<~TEST.strip
435
- actual = ["b"]
436
- expected = a_collection_including("b")
437
- expect(actual).not_to match(expected)
438
- TEST
439
- program =
440
- make_plain_test_program(snippet, color_enabled: color_enabled)
441
-
442
- expected_output =
443
- build_expected_output(
444
- color_enabled: color_enabled,
445
- snippet: "expect(actual).not_to match(expected)",
446
- expectation:
447
- proc do
448
- line do
449
- plain "Expected "
450
- actual %|["b"]|
451
- plain " not to match "
452
- expected %|#<a collection including ("b")>|
453
- plain "."
454
- end
455
- end
456
- )
457
-
458
- expect(program).to produce_output_when_run(expected_output).in_color(
459
- color_enabled
460
- )
461
- end
462
- end
463
- end
464
-
465
- context "that is large" do
466
- it "produces the correct failure message when used in the positive" do
467
- as_both_colored_and_uncolored do |color_enabled|
468
- snippet = <<~TEST.strip
469
- actual = ["milk", "toast", "eggs", "cheese", "English muffins"]
470
- expected = a_collection_including("milk", "bread")
471
- expect(actual).to match(expected)
472
- TEST
473
- program =
474
- make_plain_test_program(snippet, color_enabled: color_enabled)
475
-
476
- expected_output =
477
- build_expected_output(
478
- color_enabled: color_enabled,
479
- snippet: "expect(actual).to match(expected)",
480
- expectation:
481
- proc do
482
- line do
483
- plain "Expected "
484
- actual %|["milk", "toast", "eggs", "cheese", "English muffins"]|
485
- end
486
-
487
- line do
488
- plain "to match "
489
- expected %|#<a collection including ("milk", "bread")>|
490
- end
491
- end,
492
- diff:
493
- proc do
494
- plain_line " ["
495
- plain_line %| "milk",|
496
- plain_line %| "toast",|
497
- plain_line %| "eggs",|
498
- plain_line %| "cheese",|
499
- # plain_line %| "English muffins",| # FIXME
500
- plain_line %| "English muffins"|
501
- expected_line %|- "bread"|
502
- plain_line " ]"
503
- end
504
- )
505
-
506
- expect(program).to produce_output_when_run(expected_output).in_color(
507
- color_enabled
508
- )
509
- end
510
- end
511
-
512
- it "produces the correct failure message when used in the negative" do
513
- as_both_colored_and_uncolored do |color_enabled|
514
- snippet = <<~TEST.strip
515
- actual = ["milk", "toast", "eggs", "cheese", "English muffins"]
516
- expected = a_collection_including("milk", "toast")
517
- expect(actual).not_to match(expected)
518
- TEST
519
- program =
520
- make_plain_test_program(snippet, color_enabled: color_enabled)
521
-
522
- expected_output =
523
- build_expected_output(
524
- color_enabled: color_enabled,
525
- snippet: "expect(actual).not_to match(expected)",
526
- newline_before_expectation: true,
527
- expectation:
528
- proc do
529
- line do
530
- plain " Expected "
531
- actual %|["milk", "toast", "eggs", "cheese", "English muffins"]|
532
- end
533
-
534
- line do
535
- plain "not to match "
536
- expected %|#<a collection including ("milk", "toast")>|
537
- end
538
- end
539
- )
540
-
541
- expect(program).to produce_output_when_run(expected_output).in_color(
542
- color_enabled
543
- )
544
- end
545
- end
546
- end
547
- end
548
-
549
- context "when the expected value includes a collection-including-<something>" do
550
- context "and the corresponding actual value is an array" do
551
- it "produces the correct failure message when used in the positive" do
552
- as_both_colored_and_uncolored do |color_enabled|
553
- snippet = <<~TEST.strip
554
- actual = {
555
- name: "shopping list",
556
- contents: ["milk", "toast", "eggs"]
557
- }
558
- expected = {
559
- name: "shopping list",
560
- contents: a_collection_including("milk", "bread")
561
- }
562
- expect(actual).to match(expected)
563
- TEST
564
- program =
565
- make_plain_test_program(snippet, color_enabled: color_enabled)
566
-
567
- expected_output =
568
- build_expected_output(
569
- color_enabled: color_enabled,
570
- snippet: "expect(actual).to match(expected)",
571
- expectation:
572
- proc do
573
- line do
574
- plain "Expected "
575
- actual %|{ name: "shopping list", contents: ["milk", "toast", "eggs"] }|
576
- end
577
-
578
- line do
579
- plain "to match "
580
- expected %|{ name: "shopping list", contents: #<a collection including ("milk", "bread")> }|
581
- end
582
- end,
583
- diff:
584
- proc do
585
- plain_line " {"
586
- plain_line %| name: "shopping list",|
587
- plain_line " contents: ["
588
- plain_line %| "milk",|
589
- plain_line %| "toast",|
590
- # plain_line %| "eggs",| # FIXME
591
- plain_line %| "eggs"|
592
- expected_line %|- "bread"|
593
- plain_line " ]"
594
- plain_line " }"
595
- end
596
- )
597
-
598
- expect(program).to produce_output_when_run(expected_output).in_color(
599
- color_enabled
600
- )
601
- end
602
- end
603
-
604
- it "produces the correct failure message when used in the negative" do
605
- as_both_colored_and_uncolored do |color_enabled|
606
- snippet = <<~TEST.strip
607
- actual = {
608
- name: "shopping list",
609
- contents: ["milk", "toast", "eggs"]
610
- }
611
- expected = {
612
- name: "shopping list",
613
- contents: a_collection_including("milk", "toast")
614
- }
615
- expect(actual).not_to match(expected)
616
- TEST
617
- program =
618
- make_plain_test_program(snippet, color_enabled: color_enabled)
619
-
620
- expected_output =
621
- build_expected_output(
622
- color_enabled: color_enabled,
623
- snippet: "expect(actual).not_to match(expected)",
624
- newline_before_expectation: true,
625
- expectation:
626
- proc do
627
- line do
628
- plain " Expected "
629
- actual %|{ name: "shopping list", contents: ["milk", "toast", "eggs"] }|
630
- end
631
-
632
- line do
633
- plain "not to match "
634
- expected %|{ name: "shopping list", contents: #<a collection including ("milk", "toast")> }|
635
- end
636
- end
637
- )
638
-
639
- expect(program).to produce_output_when_run(expected_output).in_color(
640
- color_enabled
641
- )
642
- end
643
- end
644
- end
645
-
646
- context "when the corresponding actual value is not an array" do
647
- it "produces the correct failure message" do
648
- as_both_colored_and_uncolored do |color_enabled|
649
- snippet = <<~TEST.strip
650
- actual = {
651
- name: "shopping list",
652
- contents: nil
653
- }
654
- expected = {
655
- name: "shopping list",
656
- contents: a_collection_including("milk", "bread")
657
- }
658
- expect(actual).to match(expected)
659
- TEST
660
- program =
661
- make_plain_test_program(snippet, color_enabled: color_enabled)
662
-
663
- expected_output =
664
- build_expected_output(
665
- color_enabled: color_enabled,
666
- snippet: "expect(actual).to match(expected)",
667
- expectation:
668
- proc do
669
- line do
670
- plain "Expected "
671
- actual %|{ name: "shopping list", contents: nil }|
672
- end
673
-
674
- line do
675
- plain "to match "
676
- expected %|{ name: "shopping list", contents: #<a collection including ("milk", "bread")> }|
677
- end
678
- end,
679
- diff:
680
- proc do
681
- plain_line " {"
682
- plain_line %! name: "shopping list",!
683
- expected_line "- contents: #<a collection including ("
684
- expected_line %!- "milk",!
685
- expected_line %!- "bread"!
686
- expected_line "- )>"
687
- actual_line "+ contents: nil"
688
- plain_line " }"
689
- end
690
- )
691
-
692
- expect(program).to produce_output_when_run(expected_output).in_color(
693
- color_enabled
694
- )
695
- end
696
- end
697
- end
698
- end
699
-
700
- context "when the expected value is an array-including-<something>" do
701
- it "produces the correct failure message" do
702
- as_both_colored_and_uncolored do |color_enabled|
703
- snippet = <<~TEST.strip
704
- actual = ["b"]
705
- expected = array_including("a")
706
- expect(actual).to match(expected)
707
- TEST
708
- program = make_plain_test_program(snippet, color_enabled: color_enabled)
709
-
710
- expected_output =
711
- build_expected_output(
712
- color_enabled: color_enabled,
713
- snippet: "expect(actual).to match(expected)",
714
- expectation:
715
- proc do
716
- line do
717
- plain "Expected "
718
- actual %|["b"]|
719
- plain " to match "
720
- expected %|#<a collection including ("a")>|
721
- plain "."
722
- end
723
- end,
724
- diff:
725
- proc do
726
- plain_line " ["
727
- plain_line %| "b"|
728
- # expected_line %|- "a",| # FIXME
729
- expected_line %|- "a"|
730
- plain_line " ]"
731
- end
732
- )
733
-
734
- expect(program).to produce_output_when_run(expected_output).in_color(
735
- color_enabled
736
- )
737
- end
738
- end
739
- end
740
-
741
- context "when the expected value is an object-having-attributes" do
742
- context "that is small" do
743
- it "produces the correct failure message when used in the positive" do
744
- as_both_colored_and_uncolored do |color_enabled|
745
- snippet = <<~TEST.strip
746
- actual = A.new("a")
747
- expected = an_object_having_attributes(name: "b")
748
- expect(actual).to match(expected)
749
- TEST
750
- program =
751
- make_plain_test_program(snippet, color_enabled: color_enabled)
752
-
753
- expected_output =
754
- build_expected_output(
755
- color_enabled: color_enabled,
756
- snippet: "expect(actual).to match(expected)",
757
- expectation:
758
- proc do
759
- line do
760
- plain "Expected "
761
- actual %|#<A name: "a">|
762
- plain " to match "
763
- expected %|#<an object having attributes (name: "b")>|
764
- plain "."
765
- end
766
- end,
767
- diff:
768
- proc do
769
- plain_line " #<A {"
770
- # expected_line %|- name: "b",| # FIXME
771
- expected_line %|- name: "b"|
772
- actual_line %|+ name: "a"|
773
- plain_line " }>"
774
- end
775
- )
776
-
777
- expect(program).to produce_output_when_run(expected_output).in_color(
778
- color_enabled
779
- )
780
- end
781
- end
782
-
783
- it "produces the correct failure message when used in the negative" do
784
- as_both_colored_and_uncolored do |color_enabled|
785
- snippet = <<~TEST.strip
786
- actual = A.new("b")
787
- expected = an_object_having_attributes(name: "b")
788
- expect(actual).not_to match(expected)
789
- TEST
790
- program =
791
- make_plain_test_program(snippet, color_enabled: color_enabled)
792
-
793
- expected_output =
794
- build_expected_output(
795
- color_enabled: color_enabled,
796
- snippet: "expect(actual).not_to match(expected)",
797
- expectation:
798
- proc do
799
- line do
800
- plain "Expected "
801
- actual %|#<A name: "b">|
802
- plain " not to match "
803
- expected %|#<an object having attributes (name: "b")>|
804
- plain "."
805
- end
806
- end
807
- )
808
-
809
- expect(program).to produce_output_when_run(expected_output).in_color(
810
- color_enabled
811
- )
812
- end
813
- end
814
- end
815
-
816
- context "that is large" do
817
- it "produces the correct failure message when used in the positive" do
818
- as_both_colored_and_uncolored do |color_enabled|
819
- snippet = <<~TEST.strip
820
- actual = SuperDiff::Test::ShippingAddress.new(
821
- line_1: "456 Ponderosa Ct.",
822
- line_2: nil,
823
- city: "Hill Valley",
824
- state: "CA",
825
- zip: "90382"
826
- )
827
- expected = an_object_having_attributes(
828
- line_1: "123 Main St.",
829
- city: "Oakland",
830
- zip: "91234",
831
- state: "CA",
832
- something_else: "blah"
833
- )
834
- expect(actual).to match(expected)
835
- TEST
836
- program =
837
- make_plain_test_program(snippet, color_enabled: color_enabled)
838
-
839
- expected_output =
840
- build_expected_output(
841
- color_enabled: color_enabled,
842
- snippet: "expect(actual).to match(expected)",
843
- expectation:
844
- proc do
845
- line do
846
- plain "Expected "
847
- actual %|#<SuperDiff::Test::ShippingAddress line_1: "456 Ponderosa Ct.", line_2: nil, city: "Hill Valley", state: "CA", zip: "90382">|
848
- end
849
-
850
- line do
851
- plain "to match "
852
- expected %|#<an object having attributes (line_1: "123 Main St.", city: "Oakland", zip: "91234", state: "CA", something_else: "blah")>|
853
- end
854
- end,
855
- diff:
856
- proc do
857
- plain_line " #<SuperDiff::Test::ShippingAddress {"
858
- expected_line %|- line_1: "123 Main St.",|
859
- actual_line %|+ line_1: "456 Ponderosa Ct.",|
860
- plain_line " line_2: nil,"
861
- expected_line %|- city: "Oakland",|
862
- actual_line %|+ city: "Hill Valley",|
863
- plain_line %| state: "CA",|
864
- # expected_line %|- zip: "91234",| # FIXME
865
- # actual_line %|+ zip: "90382",| # FIXME
866
- expected_line %|- zip: "91234"|
867
- actual_line %|+ zip: "90382"|
868
- # expected_line %|- something_else: "blah"| # TODO
869
- expected_line %|- something_else: "blah",|
870
- plain_line " }>"
871
- end
872
- )
873
-
874
- expect(program).to produce_output_when_run(expected_output).in_color(
875
- color_enabled
876
- )
877
- end
878
- end
879
-
880
- it "produces the correct failure message when used in the negative" do
881
- as_both_colored_and_uncolored do |color_enabled|
882
- snippet = <<~TEST.strip
883
- actual = SuperDiff::Test::ShippingAddress.new(
884
- line_1: "123 Main St.",
885
- line_2: nil,
886
- city: "Oakland",
887
- zip: "91234",
888
- state: "CA"
889
- )
890
- expected = an_object_having_attributes(
891
- line_1: "123 Main St.",
892
- city: "Oakland",
893
- zip: "91234"
894
- )
895
- expect(actual).not_to match(expected)
896
- TEST
897
- program =
898
- make_plain_test_program(snippet, color_enabled: color_enabled)
899
-
900
- expected_output =
901
- build_expected_output(
902
- color_enabled: color_enabled,
903
- snippet: "expect(actual).not_to match(expected)",
904
- newline_before_expectation: true,
905
- expectation:
906
- proc do
907
- line do
908
- plain " Expected "
909
- actual %|#<SuperDiff::Test::ShippingAddress line_1: "123 Main St.", line_2: nil, city: "Oakland", state: "CA", zip: "91234">|
910
- end
911
-
912
- line do
913
- plain "not to match "
914
- expected %|#<an object having attributes (line_1: "123 Main St.", city: "Oakland", zip: "91234")>|
915
- end
916
- end
917
- )
918
-
919
- expect(program).to produce_output_when_run(expected_output).in_color(
920
- color_enabled
921
- )
922
- end
923
- end
924
- end
925
- end
926
-
927
- context "when the expected value includes an object-having-attributes" do
928
- it "produces the correct failure message when used in the positive" do
929
- as_both_colored_and_uncolored do |color_enabled|
930
- snippet = <<~TEST.strip
931
- actual = {
932
- name: "Marty McFly",
933
- shipping_address: SuperDiff::Test::ShippingAddress.new(
934
- line_1: "456 Ponderosa Ct.",
935
- line_2: nil,
936
- city: "Hill Valley",
937
- state: "CA",
938
- zip: "90382"
939
- )
940
- }
941
- expected = {
942
- name: "Marty McFly",
943
- shipping_address: an_object_having_attributes(
944
- line_1: "123 Main St.",
945
- city: "Oakland",
946
- state: "CA",
947
- zip: "91234",
948
- something_else: "blah"
949
- )
950
- }
951
- expect(actual).to match(expected)
952
- TEST
953
- program = make_plain_test_program(snippet, color_enabled: color_enabled)
954
-
955
- expected_output =
956
- build_expected_output(
957
- color_enabled: color_enabled,
958
- snippet: "expect(actual).to match(expected)",
959
- expectation:
960
- proc do
961
- line do
962
- plain "Expected "
963
- actual %|{ name: "Marty McFly", shipping_address: #<SuperDiff::Test::ShippingAddress line_1: "456 Ponderosa Ct.", line_2: nil, city: "Hill Valley", state: "CA", zip: "90382"> }|
964
- end
965
-
966
- line do
967
- plain "to match "
968
- expected %|{ name: "Marty McFly", shipping_address: #<an object having attributes (line_1: "123 Main St.", city: "Oakland", state: "CA", zip: "91234", something_else: "blah")> }|
969
- end
970
- end,
971
- diff:
972
- proc do
973
- plain_line " {"
974
- plain_line %| name: "Marty McFly",|
975
- plain_line " shipping_address: #<SuperDiff::Test::ShippingAddress {"
976
- expected_line %|- line_1: "123 Main St.",|
977
- actual_line %|+ line_1: "456 Ponderosa Ct.",|
978
- plain_line " line_2: nil,"
979
- expected_line %|- city: "Oakland",|
980
- actual_line %|+ city: "Hill Valley",|
981
- plain_line %| state: "CA",|
982
- # expected_line %|- zip: "91234",| # FIXME
983
- expected_line %|- zip: "91234"|
984
- actual_line %|+ zip: "90382"|
985
- # expected_line %|- something_else: "blah"| # TODO
986
- expected_line %|- something_else: "blah",|
987
- plain_line " }>"
988
- plain_line " }"
989
- end
990
- )
991
-
992
- expect(program).to produce_output_when_run(expected_output).in_color(
993
- color_enabled
994
- )
995
- end
996
- end
997
-
998
- it "produces the correct failure message when used the negative" do
999
- as_both_colored_and_uncolored do |color_enabled|
1000
- snippet = <<~TEST.strip
1001
- actual = {
1002
- name: "Marty McFly",
1003
- shipping_address: SuperDiff::Test::ShippingAddress.new(
1004
- line_1: "123 Main St.",
1005
- line_2: nil,
1006
- city: "Oakland",
1007
- state: "CA",
1008
- zip: "91234",
1009
- )
1010
- }
1011
- expected = {
1012
- name: "Marty McFly",
1013
- shipping_address: an_object_having_attributes(
1014
- line_1: "123 Main St.",
1015
- city: "Oakland",
1016
- state: "CA",
1017
- zip: "91234"
1018
- )
1019
- }
1020
- expect(actual).not_to match(expected)
1021
- TEST
1022
- program = make_plain_test_program(snippet, color_enabled: color_enabled)
1023
-
1024
- expected_output =
1025
- build_expected_output(
1026
- color_enabled: color_enabled,
1027
- snippet: "expect(actual).not_to match(expected)",
1028
- newline_before_expectation: true,
1029
- expectation:
1030
- proc do
1031
- line do
1032
- plain " Expected "
1033
- actual %|{ name: "Marty McFly", shipping_address: #<SuperDiff::Test::ShippingAddress line_1: "123 Main St.", line_2: nil, city: "Oakland", state: "CA", zip: "91234"> }|
1034
- end
1035
-
1036
- line do
1037
- plain "not to match "
1038
- expected %|{ name: "Marty McFly", shipping_address: #<an object having attributes (line_1: "123 Main St.", city: "Oakland", state: "CA", zip: "91234")> }|
1039
- end
1040
- end
1041
- )
1042
-
1043
- expect(program).to produce_output_when_run(expected_output).in_color(
1044
- color_enabled
1045
- )
1046
- end
1047
- end
1048
- end
1049
-
1050
- context "when the expected value is a collection-containing-exactly-<something>" do
1051
- context "that is small" do
1052
- it "produces the correct failure message when used in the positive" do
1053
- as_both_colored_and_uncolored do |color_enabled|
1054
- snippet = <<~TEST.strip
1055
- actual = ["b"]
1056
- expected = a_collection_containing_exactly("a")
1057
- expect(actual).to match(expected)
1058
- TEST
1059
- program =
1060
- make_plain_test_program(snippet, color_enabled: color_enabled)
1061
-
1062
- expected_output =
1063
- build_expected_output(
1064
- color_enabled: color_enabled,
1065
- snippet: "expect(actual).to match(expected)",
1066
- expectation:
1067
- proc do
1068
- line do
1069
- plain "Expected "
1070
- actual %|["b"]|
1071
- plain " to match "
1072
- expected %|#<a collection containing exactly ("a")>|
1073
- plain "."
1074
- end
1075
- end,
1076
- diff:
1077
- proc do
1078
- plain_line " ["
1079
- actual_line %|+ "b",|
1080
- # expected_line %|- "a"| # TODO
1081
- expected_line %|- "a",|
1082
- plain_line " ]"
1083
- end
1084
- )
1085
-
1086
- expect(program).to produce_output_when_run(expected_output).in_color(
1087
- color_enabled
1088
- )
1089
- end
1090
- end
1091
-
1092
- it "produces the correct failure message when used in the negative" do
1093
- as_both_colored_and_uncolored do |color_enabled|
1094
- snippet = <<~TEST.strip
1095
- actual = ["b"]
1096
- expected = a_collection_containing_exactly("b")
1097
- expect(actual).not_to match(expected)
1098
- TEST
1099
- program =
1100
- make_plain_test_program(snippet, color_enabled: color_enabled)
1101
-
1102
- expected_output =
1103
- build_expected_output(
1104
- color_enabled: color_enabled,
1105
- snippet: "expect(actual).not_to match(expected)",
1106
- expectation:
1107
- proc do
1108
- line do
1109
- plain "Expected "
1110
- actual %|["b"]|
1111
- plain " not to match "
1112
- expected %|#<a collection containing exactly ("b")>|
1113
- plain "."
1114
- end
1115
- end
1116
- )
1117
-
1118
- expect(program).to produce_output_when_run(expected_output).in_color(
1119
- color_enabled
1120
- )
1121
- end
1122
- end
1123
- end
1124
-
1125
- context "that is large" do
1126
- it "produces the correct failure message when used in the positive" do
1127
- as_both_colored_and_uncolored do |color_enabled|
1128
- snippet = <<~TEST.strip
1129
- actual = ["milk", "toast", "eggs", "cheese", "English muffins"]
1130
- expected = a_collection_containing_exactly("milk", "bread")
1131
- expect(actual).to match(expected)
1132
- TEST
1133
- program =
1134
- make_plain_test_program(snippet, color_enabled: color_enabled)
1135
-
1136
- expected_output =
1137
- build_expected_output(
1138
- color_enabled: color_enabled,
1139
- snippet: "expect(actual).to match(expected)",
1140
- expectation:
1141
- proc do
1142
- line do
1143
- plain "Expected "
1144
- actual %|["milk", "toast", "eggs", "cheese", "English muffins"]|
1145
- end
1146
-
1147
- line do
1148
- plain "to match "
1149
- expected %|#<a collection containing exactly ("milk", "bread")>|
1150
- end
1151
- end,
1152
- diff:
1153
- proc do
1154
- plain_line " ["
1155
- plain_line %| "milk",|
1156
- actual_line %|+ "toast",|
1157
- actual_line %|+ "eggs",|
1158
- actual_line %|+ "cheese",|
1159
- actual_line %|+ "English muffins",|
1160
- # expected_line %|- "bread"| # TODO
1161
- expected_line %|- "bread",|
1162
- plain_line " ]"
1163
- end
1164
- )
1165
-
1166
- expect(program).to produce_output_when_run(expected_output).in_color(
1167
- color_enabled
1168
- )
1169
- end
1170
- end
1171
-
1172
- it "produces the correct failure message when used in the negative" do
1173
- as_both_colored_and_uncolored do |color_enabled|
1174
- snippet = <<~TEST.strip
1175
- actual = ["milk", "toast", "eggs"]
1176
- expected = a_collection_containing_exactly("milk", "eggs", "toast")
1177
- expect(actual).not_to match(expected)
1178
- TEST
1179
- program =
1180
- make_plain_test_program(snippet, color_enabled: color_enabled)
1181
-
1182
- expected_output =
1183
- build_expected_output(
1184
- color_enabled: color_enabled,
1185
- snippet: "expect(actual).not_to match(expected)",
1186
- newline_before_expectation: true,
1187
- expectation:
1188
- proc do
1189
- line do
1190
- plain " Expected "
1191
- actual %|["milk", "toast", "eggs"]|
1192
- end
1193
-
1194
- line do
1195
- plain "not to match "
1196
- expected %|#<a collection containing exactly ("milk", "eggs", "toast")>|
1197
- end
1198
- end
1199
- )
1200
-
1201
- expect(program).to produce_output_when_run(expected_output).in_color(
1202
- color_enabled
1203
- )
1204
- end
1205
- end
1206
- end
1207
- end
1208
-
1209
- context "when the expected value includes a collection-containing-exactly-<something>" do
1210
- context "and the corresponding actual value is an array" do
1211
- it "produces the correct failure message when used in the positive" do
1212
- as_both_colored_and_uncolored do |color_enabled|
1213
- snippet = <<~TEST.strip
1214
- actual = {
1215
- name: "shopping list",
1216
- contents: ["milk", "toast", "eggs"]
1217
- }
1218
- expected = {
1219
- name: "shopping list",
1220
- contents: a_collection_containing_exactly("milk", "bread")
1221
- }
1222
- expect(actual).to match(expected)
1223
- TEST
1224
- program =
1225
- make_plain_test_program(snippet, color_enabled: color_enabled)
1226
-
1227
- expected_output =
1228
- build_expected_output(
1229
- color_enabled: color_enabled,
1230
- snippet: "expect(actual).to match(expected)",
1231
- expectation:
1232
- proc do
1233
- line do
1234
- plain "Expected "
1235
- actual %|{ name: "shopping list", contents: ["milk", "toast", "eggs"] }|
1236
- end
1237
-
1238
- line do
1239
- plain "to match "
1240
- expected %|{ name: "shopping list", contents: #<a collection containing exactly ("milk", "bread")> }|
1241
- end
1242
- end,
1243
- diff:
1244
- proc do
1245
- plain_line " {"
1246
- plain_line %| name: "shopping list",|
1247
- plain_line " contents: ["
1248
- plain_line %| "milk",|
1249
- actual_line %|+ "toast",|
1250
- actual_line %|+ "eggs",|
1251
- # expected_line %|- "bread"| # TODO
1252
- expected_line %|- "bread",|
1253
- plain_line " ]"
1254
- plain_line " }"
1255
- end
1256
- )
1257
-
1258
- expect(program).to produce_output_when_run(expected_output).in_color(
1259
- color_enabled
1260
- )
1261
- end
1262
- end
1263
-
1264
- it "produces the correct failure message when used in the negative" do
1265
- as_both_colored_and_uncolored do |color_enabled|
1266
- snippet = <<~TEST.strip
1267
- actual = {
1268
- name: "shopping list",
1269
- contents: ["milk", "toast", "eggs"]
1270
- }
1271
- expected = {
1272
- name: "shopping list",
1273
- contents: a_collection_containing_exactly("milk", "eggs", "toast")
1274
- }
1275
- expect(actual).not_to match(expected)
1276
- TEST
1277
- program =
1278
- make_plain_test_program(snippet, color_enabled: color_enabled)
1279
-
1280
- expected_output =
1281
- build_expected_output(
1282
- color_enabled: color_enabled,
1283
- snippet: "expect(actual).not_to match(expected)",
1284
- newline_before_expectation: true,
1285
- expectation:
1286
- proc do
1287
- line do
1288
- plain " Expected "
1289
- actual %|{ name: "shopping list", contents: ["milk", "toast", "eggs"] }|
1290
- end
1291
-
1292
- line do
1293
- plain "not to match "
1294
- expected %|{ name: "shopping list", contents: #<a collection containing exactly ("milk", "eggs", "toast")> }|
1295
- end
1296
- end
1297
- )
1298
-
1299
- expect(program).to produce_output_when_run(expected_output).in_color(
1300
- color_enabled
1301
- )
1302
- end
1303
- end
1304
- end
1305
-
1306
- context "when the corresponding actual value is not an array" do
1307
- it "produces the correct failure message" do
1308
- as_both_colored_and_uncolored do |color_enabled|
1309
- snippet = <<~TEST.strip
1310
- actual = {
1311
- name: "shopping list",
1312
- contents: nil
1313
- }
1314
- expected = {
1315
- name: "shopping list",
1316
- contents: a_collection_containing_exactly("milk", "bread")
1317
- }
1318
- expect(actual).to match(expected)
1319
- TEST
1320
- program =
1321
- make_plain_test_program(snippet, color_enabled: color_enabled)
1322
-
1323
- expected_output =
1324
- build_expected_output(
1325
- color_enabled: color_enabled,
1326
- snippet: "expect(actual).to match(expected)",
1327
- expectation:
1328
- proc do
1329
- line do
1330
- plain "Expected "
1331
- actual %|{ name: "shopping list", contents: nil }|
1332
- end
1333
-
1334
- line do
1335
- plain "to match "
1336
- expected %|{ name: "shopping list", contents: #<a collection containing exactly ("milk", "bread")> }|
1337
- end
1338
- end,
1339
- diff:
1340
- proc do
1341
- plain_line " {"
1342
- plain_line %! name: "shopping list",!
1343
- expected_line "- contents: #<a collection containing exactly ("
1344
- expected_line %!- "milk",!
1345
- expected_line %!- "bread"!
1346
- expected_line "- )>"
1347
- actual_line "+ contents: nil"
1348
- plain_line " }"
1349
- end
1350
- )
1351
-
1352
- expect(program).to produce_output_when_run(expected_output).in_color(
1353
- color_enabled
1354
- )
1355
- end
1356
- end
1357
- end
1358
- end
1359
- end