super_diff 0.13.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (276) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  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 +6 -4
  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 +2 -0
  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 +15 -9
  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 +4 -2
  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 +12 -10
  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 +9 -6
  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 +14 -38
  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 +13 -11
  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 -10
  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 +2 -0
  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 -26
  185. data/super_diff.gemspec +20 -19
  186. metadata +6 -185
  187. data/spec/examples.txt +0 -450
  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/spec_helper.rb +0 -91
  211. data/spec/support/colorizer.rb +0 -9
  212. data/spec/support/command_runner.rb +0 -253
  213. data/spec/support/helpers.rb +0 -21
  214. data/spec/support/integration/helpers.rb +0 -124
  215. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +0 -104
  216. data/spec/support/integration/matchers.rb +0 -177
  217. data/spec/support/integration/test_programs/base.rb +0 -143
  218. data/spec/support/integration/test_programs/plain.rb +0 -19
  219. data/spec/support/integration/test_programs/rspec_active_record.rb +0 -20
  220. data/spec/support/integration/test_programs/rspec_active_support.rb +0 -20
  221. data/spec/support/integration/test_programs/rspec_rails.rb +0 -20
  222. data/spec/support/integration/test_programs/rspec_rails_engine.rb +0 -20
  223. data/spec/support/models/a.rb +0 -11
  224. data/spec/support/models/active_record/person.rb +0 -28
  225. data/spec/support/models/active_record/query.rb +0 -15
  226. data/spec/support/models/active_record/shipping_address.rb +0 -24
  227. data/spec/support/models/customer.rb +0 -22
  228. data/spec/support/models/empty_class.rb +0 -6
  229. data/spec/support/models/item.rb +0 -10
  230. data/spec/support/models/order.rb +0 -9
  231. data/spec/support/models/person.rb +0 -20
  232. data/spec/support/models/player.rb +0 -30
  233. data/spec/support/models/point.rb +0 -7
  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/inspection_tree_builders/data_object_spec.rb +0 -146
  246. data/spec/unit/basic/operation_tree_builders/data_object_spec.rb +0 -82
  247. data/spec/unit/basic/operation_tree_flatteners/array_spec.rb +0 -637
  248. data/spec/unit/basic/operation_tree_flatteners/custom_object_spec.rb +0 -685
  249. data/spec/unit/basic/operation_tree_flatteners/default_object_spec.rb +0 -685
  250. data/spec/unit/basic/operation_tree_flatteners/hash_spec.rb +0 -671
  251. data/spec/unit/basic/operation_tree_flatteners/multiline_string_spec.rb +0 -131
  252. data/spec/unit/core/configuration_no_rspec_spec.rb +0 -58
  253. data/spec/unit/core/configuration_spec.rb +0 -176
  254. data/spec/unit/core/helpers_spec.rb +0 -68
  255. data/spec/unit/core/tiered_lines_elider_spec.rb +0 -6328
  256. data/spec/unit/core/tiered_lines_formatter_spec.rb +0 -131
  257. data/spec/unit/deprecations_spec.rb +0 -176
  258. data/spec/unit/equality_matchers/main_spec.rb +0 -1842
  259. data/spec/unit/rspec/matchers/be_compared_to_spec.rb +0 -23
  260. data/spec/unit/rspec/matchers/be_falsey_spec.rb +0 -9
  261. data/spec/unit/rspec/matchers/be_nil_spec.rb +0 -9
  262. data/spec/unit/rspec/matchers/be_predicate_spec.rb +0 -31
  263. data/spec/unit/rspec/matchers/be_spec.rb +0 -17
  264. data/spec/unit/rspec/matchers/be_truthy_spec.rb +0 -9
  265. data/spec/unit/rspec/matchers/contain_exactly_spec.rb +0 -11
  266. data/spec/unit/rspec/matchers/eq_spec.rb +0 -9
  267. data/spec/unit/rspec/matchers/have_attributes_spec.rb +0 -11
  268. data/spec/unit/rspec/matchers/have_predicate_spec.rb +0 -21
  269. data/spec/unit/rspec/matchers/include_spec.rb +0 -21
  270. data/spec/unit/rspec/matchers/match_array_spec.rb +0 -11
  271. data/spec/unit/rspec/matchers/match_spec.rb +0 -9
  272. data/spec/unit/rspec/matchers/raise_error_spec.rb +0 -77
  273. data/spec/unit/rspec/matchers/respond_to_spec.rb +0 -85
  274. data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +0 -91
  275. data/spec/unit/rspec/object_inspection_spec.rb +0 -471
  276. data/spec/unit/super_diff_spec.rb +0 -2115
@@ -1,749 +0,0 @@
1
- shared_examples_for "integration with HashWithIndifferentAccess" do
2
- describe "and RSpec's #eq matcher" do
3
- context "when the actual value is a HashWithIndifferentAccess" do
4
- context "and both hashes are one-dimensional" do
5
- context "and the expected hash contains symbol keys" do
6
- it "produces the correct output" do
7
- as_both_colored_and_uncolored do |color_enabled|
8
- snippet = <<~TEST.strip
9
- actual = HashWithIndifferentAccess.new({
10
- line_1: "456 Ponderosa Ct.",
11
- city: "Oakland",
12
- state: "CA",
13
- zip: "91234",
14
- })
15
- expected = {
16
- line_1: "123 Main St.",
17
- city: "Hill Valley",
18
- state: "CA",
19
- zip: "90382",
20
- }
21
- expect(actual).to eq(expected)
22
- TEST
23
- program = make_program(snippet, color_enabled: color_enabled)
24
-
25
- expected_output =
26
- build_expected_output(
27
- color_enabled: color_enabled,
28
- snippet: "expect(actual).to eq(expected)",
29
- expectation:
30
- proc do
31
- line do
32
- plain "Expected "
33
- actual %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
34
- end
35
-
36
- line do
37
- plain " to eq "
38
- expected %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
39
- end
40
- end,
41
- diff:
42
- proc do
43
- plain_line " #<HashWithIndifferentAccess {"
44
- expected_line %|- "line_1" => "123 Main St.",|
45
- actual_line %|+ "line_1" => "456 Ponderosa Ct.",|
46
- expected_line %|- "city" => "Hill Valley",|
47
- actual_line %|+ "city" => "Oakland",|
48
- plain_line %| "state" => "CA",|
49
- expected_line %|- "zip" => "90382"|
50
- actual_line %|+ "zip" => "91234"|
51
- plain_line " }>"
52
- end
53
- )
54
-
55
- expect(program).to produce_output_when_run(
56
- expected_output
57
- ).in_color(color_enabled)
58
- end
59
- end
60
- end
61
-
62
- context "and the expected hash contains string keys" do
63
- it "produces the correct output" do
64
- as_both_colored_and_uncolored do |color_enabled|
65
- snippet = <<~TEST.strip
66
- actual = HashWithIndifferentAccess.new({
67
- line_1: "456 Ponderosa Ct.",
68
- city: "Oakland",
69
- state: "CA",
70
- zip: "91234",
71
- })
72
- expected = {
73
- "line_1" => "123 Main St.",
74
- "city" => "Hill Valley",
75
- "state" => "CA",
76
- "zip" => "90382",
77
- }
78
- expect(actual).to eq(expected)
79
- TEST
80
- program = make_program(snippet, color_enabled: color_enabled)
81
-
82
- expected_output =
83
- build_expected_output(
84
- color_enabled: color_enabled,
85
- snippet: "expect(actual).to eq(expected)",
86
- expectation:
87
- proc do
88
- line do
89
- plain "Expected "
90
- actual %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
91
- end
92
-
93
- line do
94
- plain " to eq "
95
- expected %|{ "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }|
96
- end
97
- end,
98
- diff:
99
- proc do
100
- plain_line " #<HashWithIndifferentAccess {"
101
- expected_line %|- "line_1" => "123 Main St.",|
102
- actual_line %|+ "line_1" => "456 Ponderosa Ct.",|
103
- expected_line %|- "city" => "Hill Valley",|
104
- actual_line %|+ "city" => "Oakland",|
105
- plain_line %| "state" => "CA",|
106
- expected_line %|- "zip" => "90382"|
107
- actual_line %|+ "zip" => "91234"|
108
- plain_line " }>"
109
- end
110
- )
111
-
112
- expect(program).to produce_output_when_run(
113
- expected_output
114
- ).in_color(color_enabled)
115
- end
116
- end
117
- end
118
- end
119
- end
120
-
121
- context "when the expected value is a HashWithIndifferentAccess" do
122
- context "and both hashes are one-dimensional" do
123
- context "and the actual hash contains symbol keys" do
124
- it "produces the correct output" do
125
- as_both_colored_and_uncolored do |color_enabled|
126
- snippet = <<~TEST.strip
127
- actual = {
128
- line_1: "123 Main St.",
129
- city: "Hill Valley",
130
- state: "CA",
131
- zip: "90382",
132
- }
133
- expected = HashWithIndifferentAccess.new({
134
- line_1: "456 Ponderosa Ct.",
135
- city: "Oakland",
136
- state: "CA",
137
- zip: "91234",
138
- })
139
- expect(actual).to eq(expected)
140
- TEST
141
- program = make_program(snippet, color_enabled: color_enabled)
142
-
143
- expected_output =
144
- build_expected_output(
145
- color_enabled: color_enabled,
146
- snippet: "expect(actual).to eq(expected)",
147
- expectation:
148
- proc do
149
- line do
150
- plain "Expected "
151
- actual %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
152
- end
153
-
154
- line do
155
- plain " to eq "
156
- expected %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
157
- end
158
- end,
159
- diff:
160
- proc do
161
- plain_line " #<HashWithIndifferentAccess {"
162
- expected_line %|- "line_1" => "456 Ponderosa Ct.",|
163
- actual_line %|+ "line_1" => "123 Main St.",|
164
- expected_line %|- "city" => "Oakland",|
165
- actual_line %|+ "city" => "Hill Valley",|
166
- plain_line %| "state" => "CA",|
167
- expected_line %|- "zip" => "91234"|
168
- actual_line %|+ "zip" => "90382"|
169
- plain_line " }>"
170
- end
171
- )
172
-
173
- expect(program).to produce_output_when_run(
174
- expected_output
175
- ).in_color(color_enabled)
176
- end
177
- end
178
- end
179
-
180
- context "and the actual hash contains string keys" do
181
- it "produces the correct output" do
182
- as_both_colored_and_uncolored do |color_enabled|
183
- snippet = <<~TEST.strip
184
- actual = {
185
- "line_1" => "123 Main St.",
186
- "city" => "Hill Valley",
187
- "state" => "CA",
188
- "zip" => "90382",
189
- }
190
- expected = HashWithIndifferentAccess.new({
191
- line_1: "456 Ponderosa Ct.",
192
- city: "Oakland",
193
- state: "CA",
194
- zip: "91234",
195
- })
196
- expect(actual).to eq(expected)
197
- TEST
198
- program = make_program(snippet, color_enabled: color_enabled)
199
-
200
- expected_output =
201
- build_expected_output(
202
- color_enabled: color_enabled,
203
- snippet: "expect(actual).to eq(expected)",
204
- expectation:
205
- proc do
206
- line do
207
- plain "Expected "
208
- actual %|{ "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }|
209
- end
210
-
211
- line do
212
- plain " to eq "
213
- expected %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
214
- end
215
- end,
216
- diff:
217
- proc do
218
- plain_line " #<HashWithIndifferentAccess {"
219
- expected_line %|- "line_1" => "456 Ponderosa Ct.",|
220
- actual_line %|+ "line_1" => "123 Main St.",|
221
- expected_line %|- "city" => "Oakland",|
222
- actual_line %|+ "city" => "Hill Valley",|
223
- plain_line %| "state" => "CA",|
224
- expected_line %|- "zip" => "91234"|
225
- actual_line %|+ "zip" => "90382"|
226
- plain_line " }>"
227
- end
228
- )
229
-
230
- expect(program).to produce_output_when_run(
231
- expected_output
232
- ).in_color(color_enabled)
233
- end
234
- end
235
- end
236
- end
237
-
238
- context "and both hashes are multi-dimensional" do
239
- context "and the actual hash contains symbol keys" do
240
- it "produces the correct output" do
241
- as_both_colored_and_uncolored do |color_enabled|
242
- snippet = <<~TEST.strip
243
- actual = {
244
- shipments: [
245
- {
246
- estimated_delivery: {
247
- from: '2019-05-06',
248
- to: '2019-05-09'
249
- }
250
- }
251
- ]
252
- }
253
- expected = HashWithIndifferentAccess.new({
254
- shipments: [
255
- HashWithIndifferentAccess.new({
256
- estimated_delivery: HashWithIndifferentAccess.new({
257
- from: '2019-05-06',
258
- to: '2019-05-06'
259
- })
260
- })
261
- ]
262
- })
263
- expect(actual).to eq(expected)
264
- TEST
265
- program = make_program(snippet, color_enabled: color_enabled)
266
-
267
- expected_output =
268
- build_expected_output(
269
- color_enabled: color_enabled,
270
- snippet: "expect(actual).to eq(expected)",
271
- expectation:
272
- proc do
273
- line do
274
- plain "Expected "
275
- actual %|{ shipments: [{ estimated_delivery: { from: "2019-05-06", to: "2019-05-09" } }] }|
276
- end
277
-
278
- line do
279
- plain " to eq "
280
- expected %|#<HashWithIndifferentAccess { "shipments" => [#<HashWithIndifferentAccess { "estimated_delivery" => #<HashWithIndifferentAccess { "from" => "2019-05-06", "to" => "2019-05-06" }> }>] }>|
281
- end
282
- end,
283
- diff:
284
- proc do
285
- plain_line " #<HashWithIndifferentAccess {"
286
- plain_line %| "shipments" => [|
287
- plain_line " #<HashWithIndifferentAccess {"
288
- plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
289
- plain_line %| "from" => "2019-05-06",|
290
- expected_line %|- "to" => "2019-05-06"|
291
- actual_line %|+ "to" => "2019-05-09"|
292
- plain_line " }>"
293
- plain_line " }>"
294
- plain_line " ]"
295
- plain_line " }>"
296
- end
297
- )
298
-
299
- expect(program).to produce_output_when_run(
300
- expected_output
301
- ).in_color(color_enabled)
302
- end
303
- end
304
- end
305
-
306
- context "and the actual hash contains string keys" do
307
- it "produces the correct output" do
308
- as_both_colored_and_uncolored do |color_enabled|
309
- snippet = <<~TEST.strip
310
- actual = {
311
- 'shipments' => [
312
- {
313
- 'estimated_delivery' => {
314
- 'from' => '2019-05-06',
315
- 'to' => '2019-05-09'
316
- }
317
- }
318
- ]
319
- }
320
- expected = HashWithIndifferentAccess.new({
321
- shipments: [
322
- HashWithIndifferentAccess.new({
323
- estimated_delivery: HashWithIndifferentAccess.new({
324
- from: '2019-05-06',
325
- to: '2019-05-06'
326
- })
327
- })
328
- ]
329
- })
330
- expect(actual).to eq(expected)
331
- TEST
332
- program = make_program(snippet, color_enabled: color_enabled)
333
-
334
- expected_output =
335
- build_expected_output(
336
- color_enabled: color_enabled,
337
- snippet: "expect(actual).to eq(expected)",
338
- expectation:
339
- proc do
340
- line do
341
- plain "Expected "
342
- actual %|{ "shipments" => [{ "estimated_delivery" => { "from" => "2019-05-06", "to" => "2019-05-09" } }] }|
343
- end
344
-
345
- line do
346
- plain " to eq "
347
- expected %|#<HashWithIndifferentAccess { "shipments" => [#<HashWithIndifferentAccess { "estimated_delivery" => #<HashWithIndifferentAccess { "from" => "2019-05-06", "to" => "2019-05-06" }> }>] }>|
348
- end
349
- end,
350
- diff:
351
- proc do
352
- plain_line " #<HashWithIndifferentAccess {"
353
- plain_line %| "shipments" => [|
354
- plain_line " #<HashWithIndifferentAccess {"
355
- plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
356
- plain_line %| "from" => "2019-05-06",|
357
- expected_line %|- "to" => "2019-05-06"|
358
- actual_line %|+ "to" => "2019-05-09"|
359
- plain_line " }>"
360
- plain_line " }>"
361
- plain_line " ]"
362
- plain_line " }>"
363
- end
364
- )
365
-
366
- expect(program).to produce_output_when_run(
367
- expected_output
368
- ).in_color(color_enabled)
369
- end
370
- end
371
- end
372
- end
373
- end
374
- end
375
-
376
- describe "and RSpec's #match matcher" do
377
- context "when the actual value is a HashWithIndifferentAccess" do
378
- context "and both hashes are one-dimensional" do
379
- context "and the expected hash contains symbol keys" do
380
- it "produces the correct output" do
381
- as_both_colored_and_uncolored do |color_enabled|
382
- snippet = <<~TEST.strip
383
- actual = HashWithIndifferentAccess.new({
384
- line_1: "456 Ponderosa Ct.",
385
- city: "Oakland",
386
- state: "CA",
387
- zip: "91234",
388
- })
389
- expected = {
390
- line_1: "123 Main St.",
391
- city: "Hill Valley",
392
- state: "CA",
393
- zip: "90382",
394
- }
395
- expect(actual).to match(expected)
396
- TEST
397
- program = make_program(snippet, color_enabled: color_enabled)
398
-
399
- expected_output =
400
- build_expected_output(
401
- color_enabled: color_enabled,
402
- snippet: "expect(actual).to match(expected)",
403
- expectation:
404
- proc do
405
- line do
406
- plain "Expected "
407
- actual %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
408
- end
409
-
410
- line do
411
- plain "to match "
412
- expected %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
413
- end
414
- end,
415
- diff:
416
- proc do
417
- plain_line " #<HashWithIndifferentAccess {"
418
- expected_line %|- "line_1" => "123 Main St.",|
419
- actual_line %|+ "line_1" => "456 Ponderosa Ct.",|
420
- expected_line %|- "city" => "Hill Valley",|
421
- actual_line %|+ "city" => "Oakland",|
422
- plain_line %| "state" => "CA",|
423
- expected_line %|- "zip" => "90382"|
424
- actual_line %|+ "zip" => "91234"|
425
- plain_line " }>"
426
- end
427
- )
428
-
429
- expect(program).to produce_output_when_run(
430
- expected_output
431
- ).in_color(color_enabled)
432
- end
433
- end
434
- end
435
-
436
- context "and the expected hash contains string keys" do
437
- it "produces the correct output" do
438
- as_both_colored_and_uncolored do |color_enabled|
439
- snippet = <<~TEST.strip
440
- actual = HashWithIndifferentAccess.new({
441
- line_1: "456 Ponderosa Ct.",
442
- city: "Oakland",
443
- state: "CA",
444
- zip: "91234",
445
- })
446
- expected = {
447
- "line_1" => "123 Main St.",
448
- "city" => "Hill Valley",
449
- "state" => "CA",
450
- "zip" => "90382",
451
- }
452
- expect(actual).to match(expected)
453
- TEST
454
- program = make_program(snippet, color_enabled: color_enabled)
455
-
456
- expected_output =
457
- build_expected_output(
458
- color_enabled: color_enabled,
459
- snippet: "expect(actual).to match(expected)",
460
- expectation:
461
- proc do
462
- line do
463
- plain "Expected "
464
- actual %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
465
- end
466
-
467
- line do
468
- plain "to match "
469
- expected %|{ "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }|
470
- end
471
- end,
472
- diff:
473
- proc do
474
- plain_line " #<HashWithIndifferentAccess {"
475
- expected_line %|- "line_1" => "123 Main St.",|
476
- actual_line %|+ "line_1" => "456 Ponderosa Ct.",|
477
- expected_line %|- "city" => "Hill Valley",|
478
- actual_line %|+ "city" => "Oakland",|
479
- plain_line %| "state" => "CA",|
480
- expected_line %|- "zip" => "90382"|
481
- actual_line %|+ "zip" => "91234"|
482
- plain_line " }>"
483
- end
484
- )
485
-
486
- expect(program).to produce_output_when_run(
487
- expected_output
488
- ).in_color(color_enabled)
489
- end
490
- end
491
- end
492
- end
493
- end
494
-
495
- context "when the expected value is a HashWithIndifferentAccess" do
496
- context "and both hashes are one-dimensional" do
497
- context "and the actual hash contains symbol keys" do
498
- it "produces the correct output" do
499
- as_both_colored_and_uncolored do |color_enabled|
500
- snippet = <<~TEST.strip
501
- actual = {
502
- line_1: "123 Main St.",
503
- city: "Hill Valley",
504
- state: "CA",
505
- zip: "90382",
506
- }
507
- expected = HashWithIndifferentAccess.new({
508
- line_1: "456 Ponderosa Ct.",
509
- city: "Oakland",
510
- state: "CA",
511
- zip: "91234",
512
- })
513
- expect(actual).to match(expected)
514
- TEST
515
- program = make_program(snippet, color_enabled: color_enabled)
516
-
517
- expected_output =
518
- build_expected_output(
519
- color_enabled: color_enabled,
520
- snippet: "expect(actual).to match(expected)",
521
- expectation:
522
- proc do
523
- line do
524
- plain "Expected "
525
- actual %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
526
- end
527
-
528
- line do
529
- plain "to match "
530
- expected %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
531
- end
532
- end,
533
- diff:
534
- proc do
535
- plain_line " #<HashWithIndifferentAccess {"
536
- expected_line %|- "line_1" => "456 Ponderosa Ct.",|
537
- actual_line %|+ "line_1" => "123 Main St.",|
538
- expected_line %|- "city" => "Oakland",|
539
- actual_line %|+ "city" => "Hill Valley",|
540
- plain_line %| "state" => "CA",|
541
- expected_line %|- "zip" => "91234"|
542
- actual_line %|+ "zip" => "90382"|
543
- plain_line " }>"
544
- end
545
- )
546
-
547
- expect(program).to produce_output_when_run(
548
- expected_output
549
- ).in_color(color_enabled)
550
- end
551
- end
552
- end
553
-
554
- context "and the actual hash contains string keys" do
555
- it "produces the correct output" do
556
- as_both_colored_and_uncolored do |color_enabled|
557
- snippet = <<~TEST.strip
558
- actual = {
559
- "line_1" => "123 Main St.",
560
- "city" => "Hill Valley",
561
- "state" => "CA",
562
- "zip" => "90382",
563
- }
564
- expected = HashWithIndifferentAccess.new({
565
- line_1: "456 Ponderosa Ct.",
566
- city: "Oakland",
567
- state: "CA",
568
- zip: "91234",
569
- })
570
- expect(actual).to match(expected)
571
- TEST
572
- program = make_program(snippet, color_enabled: color_enabled)
573
-
574
- expected_output =
575
- build_expected_output(
576
- color_enabled: color_enabled,
577
- snippet: "expect(actual).to match(expected)",
578
- expectation:
579
- proc do
580
- line do
581
- plain "Expected "
582
- actual %|{ "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }|
583
- end
584
-
585
- line do
586
- plain "to match "
587
- expected %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
588
- end
589
- end,
590
- diff:
591
- proc do
592
- plain_line " #<HashWithIndifferentAccess {"
593
- expected_line %|- "line_1" => "456 Ponderosa Ct.",|
594
- actual_line %|+ "line_1" => "123 Main St.",|
595
- expected_line %|- "city" => "Oakland",|
596
- actual_line %|+ "city" => "Hill Valley",|
597
- plain_line %| "state" => "CA",|
598
- expected_line %|- "zip" => "91234"|
599
- actual_line %|+ "zip" => "90382"|
600
- plain_line " }>"
601
- end
602
- )
603
-
604
- expect(program).to produce_output_when_run(
605
- expected_output
606
- ).in_color(color_enabled)
607
- end
608
- end
609
- end
610
- end
611
-
612
- context "and both hashes are multi-dimensional" do
613
- context "and the actual hash contains symbol keys" do
614
- it "produces the correct output" do
615
- as_both_colored_and_uncolored do |color_enabled|
616
- snippet = <<~TEST.strip
617
- actual = {
618
- shipments: [
619
- {
620
- estimated_delivery: {
621
- from: '2019-05-06',
622
- to: '2019-05-09'
623
- }
624
- }
625
- ]
626
- }
627
- expected = HashWithIndifferentAccess.new({
628
- shipments: [
629
- HashWithIndifferentAccess.new({
630
- estimated_delivery: HashWithIndifferentAccess.new({
631
- from: '2019-05-06',
632
- to: '2019-05-06'
633
- })
634
- })
635
- ]
636
- })
637
- expect(actual).to match(expected)
638
- TEST
639
- program = make_program(snippet, color_enabled: color_enabled)
640
-
641
- expected_output =
642
- build_expected_output(
643
- color_enabled: color_enabled,
644
- snippet: "expect(actual).to match(expected)",
645
- expectation:
646
- proc do
647
- line do
648
- plain "Expected "
649
- actual %|{ shipments: [{ estimated_delivery: { from: "2019-05-06", to: "2019-05-09" } }] }|
650
- end
651
-
652
- line do
653
- plain "to match "
654
- expected %|#<HashWithIndifferentAccess { "shipments" => [#<HashWithIndifferentAccess { "estimated_delivery" => #<HashWithIndifferentAccess { "from" => "2019-05-06", "to" => "2019-05-06" }> }>] }>|
655
- end
656
- end,
657
- diff:
658
- proc do
659
- plain_line " #<HashWithIndifferentAccess {"
660
- plain_line %| "shipments" => [|
661
- plain_line " #<HashWithIndifferentAccess {"
662
- plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
663
- plain_line %| "from" => "2019-05-06",|
664
- expected_line %|- "to" => "2019-05-06"|
665
- actual_line %|+ "to" => "2019-05-09"|
666
- plain_line " }>"
667
- plain_line " }>"
668
- plain_line " ]"
669
- plain_line " }>"
670
- end
671
- )
672
-
673
- expect(program).to produce_output_when_run(
674
- expected_output
675
- ).in_color(color_enabled)
676
- end
677
- end
678
- end
679
-
680
- context "and the actual hash contains string keys" do
681
- it "produces the correct output" do
682
- as_both_colored_and_uncolored do |color_enabled|
683
- snippet = <<~TEST.strip
684
- actual = {
685
- 'shipments' => [
686
- {
687
- 'estimated_delivery' => {
688
- 'from' => '2019-05-06',
689
- 'to' => '2019-05-09'
690
- }
691
- }
692
- ]
693
- }
694
- expected = HashWithIndifferentAccess.new({
695
- shipments: [
696
- HashWithIndifferentAccess.new({
697
- estimated_delivery: HashWithIndifferentAccess.new({
698
- from: '2019-05-06',
699
- to: '2019-05-06'
700
- })
701
- })
702
- ]
703
- })
704
- expect(actual).to match(expected)
705
- TEST
706
- program = make_program(snippet, color_enabled: color_enabled)
707
-
708
- expected_output =
709
- build_expected_output(
710
- color_enabled: color_enabled,
711
- snippet: "expect(actual).to match(expected)",
712
- expectation:
713
- proc do
714
- line do
715
- plain "Expected "
716
- actual %|{ "shipments" => [{ "estimated_delivery" => { "from" => "2019-05-06", "to" => "2019-05-09" } }] }|
717
- end
718
-
719
- line do
720
- plain "to match "
721
- expected %|#<HashWithIndifferentAccess { "shipments" => [#<HashWithIndifferentAccess { "estimated_delivery" => #<HashWithIndifferentAccess { "from" => "2019-05-06", "to" => "2019-05-06" }> }>] }>|
722
- end
723
- end,
724
- diff:
725
- proc do
726
- plain_line " #<HashWithIndifferentAccess {"
727
- plain_line %| "shipments" => [|
728
- plain_line " #<HashWithIndifferentAccess {"
729
- plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
730
- plain_line %| "from" => "2019-05-06",|
731
- expected_line %|- "to" => "2019-05-06"|
732
- actual_line %|+ "to" => "2019-05-09"|
733
- plain_line " }>"
734
- plain_line " }>"
735
- plain_line " ]"
736
- plain_line " }>"
737
- end
738
- )
739
-
740
- expect(program).to produce_output_when_run(
741
- expected_output
742
- ).in_color(color_enabled)
743
- end
744
- end
745
- end
746
- end
747
- end
748
- end
749
- end