super_diff 0.10.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (260) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -166
  3. data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -1
  4. data/lib/super_diff/active_record/inspection_tree_builders/active_record_model.rb +57 -0
  5. data/lib/super_diff/active_record/inspection_tree_builders/active_record_relation.rb +34 -0
  6. data/lib/super_diff/active_record/inspection_tree_builders.rb +14 -0
  7. data/lib/super_diff/active_record/monkey_patches.rb +6 -3
  8. data/lib/super_diff/active_record/object_inspection.rb +16 -4
  9. data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +6 -2
  10. data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -1
  11. data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +1 -1
  12. data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +1 -1
  13. data/lib/super_diff/active_record.rb +12 -16
  14. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +1 -1
  15. data/lib/super_diff/active_support/inspection_tree_builders/hash_with_indifferent_access.rb +44 -0
  16. data/lib/super_diff/active_support/inspection_tree_builders/ordered_options.rb +44 -0
  17. data/lib/super_diff/active_support/inspection_tree_builders.rb +14 -0
  18. data/lib/super_diff/active_support/object_inspection.rb +16 -4
  19. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +1 -1
  20. data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +1 -1
  21. data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +1 -1
  22. data/lib/super_diff/active_support.rb +11 -14
  23. data/lib/super_diff/basic/diff_formatters/collection.rb +135 -0
  24. data/lib/super_diff/basic/diff_formatters/multiline_string.rb +34 -0
  25. data/lib/super_diff/basic/diff_formatters.rb +11 -0
  26. data/lib/super_diff/basic/differs/array.rb +17 -0
  27. data/lib/super_diff/basic/differs/custom_object.rb +19 -0
  28. data/lib/super_diff/basic/differs/date_like.rb +17 -0
  29. data/lib/super_diff/basic/differs/default_object.rb +24 -0
  30. data/lib/super_diff/basic/differs/hash.rb +17 -0
  31. data/lib/super_diff/basic/differs/multiline_string.rb +18 -0
  32. data/lib/super_diff/basic/differs/time_like.rb +17 -0
  33. data/lib/super_diff/basic/differs.rb +24 -0
  34. data/lib/super_diff/basic/inspection_tree_builders/array.rb +53 -0
  35. data/lib/super_diff/basic/inspection_tree_builders/custom_object.rb +41 -0
  36. data/lib/super_diff/basic/inspection_tree_builders/date_like.rb +51 -0
  37. data/lib/super_diff/basic/inspection_tree_builders/default_object.rb +77 -0
  38. data/lib/super_diff/basic/inspection_tree_builders/hash.rb +63 -0
  39. data/lib/super_diff/basic/inspection_tree_builders/primitive.rb +19 -0
  40. data/lib/super_diff/basic/inspection_tree_builders/time_like.rb +58 -0
  41. data/lib/super_diff/basic/inspection_tree_builders.rb +20 -0
  42. data/lib/super_diff/basic/operation_tree_builders/array.rb +111 -0
  43. data/lib/super_diff/basic/operation_tree_builders/custom_object.rb +42 -0
  44. data/lib/super_diff/basic/operation_tree_builders/date_like.rb +17 -0
  45. data/lib/super_diff/basic/operation_tree_builders/default_object.rb +117 -0
  46. data/lib/super_diff/basic/operation_tree_builders/hash.rb +222 -0
  47. data/lib/super_diff/basic/operation_tree_builders/multiline_string.rb +90 -0
  48. data/lib/super_diff/basic/operation_tree_builders/time_like.rb +26 -0
  49. data/lib/super_diff/basic/operation_tree_builders.rb +34 -0
  50. data/lib/super_diff/basic/operation_tree_flatteners/array.rb +17 -0
  51. data/lib/super_diff/basic/operation_tree_flatteners/collection.rb +140 -0
  52. data/lib/super_diff/basic/operation_tree_flatteners/custom_object.rb +30 -0
  53. data/lib/super_diff/basic/operation_tree_flatteners/default_object.rb +32 -0
  54. data/lib/super_diff/basic/operation_tree_flatteners/hash.rb +35 -0
  55. data/lib/super_diff/basic/operation_tree_flatteners/multiline_string.rb +20 -0
  56. data/lib/super_diff/basic/operation_tree_flatteners.rb +24 -0
  57. data/lib/super_diff/basic/operation_trees/array.rb +17 -0
  58. data/lib/super_diff/basic/operation_trees/custom_object.rb +17 -0
  59. data/lib/super_diff/basic/operation_trees/default_object.rb +42 -0
  60. data/lib/super_diff/basic/operation_trees/hash.rb +17 -0
  61. data/lib/super_diff/basic/operation_trees/multiline_string.rb +17 -0
  62. data/lib/super_diff/basic/operation_trees.rb +25 -0
  63. data/lib/super_diff/basic.rb +48 -0
  64. data/lib/super_diff/{differs/base.rb → core/abstract_differ.rb} +2 -2
  65. data/lib/super_diff/core/abstract_inspection_tree_builder.rb +26 -0
  66. data/lib/super_diff/{operation_trees/base.rb → core/abstract_operation_tree.rb} +6 -2
  67. data/lib/super_diff/{operation_tree_builders/base.rb → core/abstract_operation_tree_builder.rb} +4 -8
  68. data/lib/super_diff/{operation_tree_flatteners/base.rb → core/abstract_operation_tree_flattener.rb} +2 -2
  69. data/lib/super_diff/{operations → core}/binary_operation.rb +1 -1
  70. data/lib/super_diff/core/colorized_document_extensions.rb +20 -0
  71. data/lib/super_diff/core/configuration.rb +192 -0
  72. data/lib/super_diff/core/differ_dispatcher.rb +31 -0
  73. data/lib/super_diff/core/gem_version.rb +47 -0
  74. data/lib/super_diff/core/helpers.rb +88 -0
  75. data/lib/super_diff/core/implementation_checks.rb +21 -0
  76. data/lib/super_diff/{object_inspection → core}/inspection_tree.rb +32 -26
  77. data/lib/super_diff/core/inspection_tree_builder_dispatcher.rb +23 -0
  78. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_lines_when_rendering_to_lines.rb +12 -5
  79. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_prefix_when_rendering_to_lines.rb +3 -3
  80. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_prelude_when_rendering_to_lines.rb +3 -3
  81. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_single_line.rb +3 -3
  82. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/base.rb +2 -2
  83. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/inspection.rb +7 -11
  84. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/nesting.rb +2 -2
  85. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/only_when.rb +2 -2
  86. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/text.rb +2 -2
  87. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_empty.rb +2 -2
  88. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_non_empty.rb +2 -2
  89. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_rendering_to_lines.rb +2 -2
  90. data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_rendering_to_string.rb +2 -2
  91. data/lib/super_diff/core/inspection_tree_nodes.rb +55 -0
  92. data/lib/super_diff/core/line.rb +85 -0
  93. data/lib/super_diff/{errors → core}/no_differ_available_error.rb +1 -1
  94. data/lib/super_diff/core/no_inspection_tree_builder_available_error.rb +21 -0
  95. data/lib/super_diff/core/no_operation_tree_available_error.rb +20 -0
  96. data/lib/super_diff/{errors/no_operational_sequencer_available_error.rb → core/no_operation_tree_builder_available_error.rb} +6 -4
  97. data/lib/super_diff/{operation_tree_builders/main.rb → core/operation_tree_builder_dispatcher.rb} +9 -13
  98. data/lib/super_diff/core/operation_tree_finder.rb +27 -0
  99. data/lib/super_diff/core/prefix_for_next_inspection_tree_node.rb +6 -0
  100. data/lib/super_diff/core/prelude_for_next_inspection_tree_node.rb +6 -0
  101. data/lib/super_diff/core/recursion_guard.rb +52 -0
  102. data/lib/super_diff/core/tiered_lines.rb +6 -0
  103. data/lib/super_diff/core/tiered_lines_elider.rb +472 -0
  104. data/lib/super_diff/core/tiered_lines_formatter.rb +77 -0
  105. data/lib/super_diff/{operations → core}/unary_operation.rb +1 -1
  106. data/lib/super_diff/core.rb +69 -0
  107. data/lib/super_diff/differs.rb +19 -11
  108. data/lib/super_diff/equality_matchers/array.rb +3 -3
  109. data/lib/super_diff/equality_matchers/default.rb +8 -3
  110. data/lib/super_diff/equality_matchers/hash.rb +3 -3
  111. data/lib/super_diff/equality_matchers/multiline_string.rb +3 -3
  112. data/lib/super_diff/equality_matchers/primitive.rb +3 -3
  113. data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
  114. data/lib/super_diff/errors.rb +12 -12
  115. data/lib/super_diff/object_inspection.rb +63 -14
  116. data/lib/super_diff/operation_tree_builders.rb +19 -14
  117. data/lib/super_diff/operation_tree_flatteners.rb +19 -16
  118. data/lib/super_diff/operation_trees.rb +19 -9
  119. data/lib/super_diff/operations.rb +12 -2
  120. data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
  121. data/lib/super_diff/rspec/differ.rb +4 -5
  122. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +1 -1
  123. data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
  124. data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
  125. data/lib/super_diff/rspec/differs/object_having_attributes.rb +1 -1
  126. data/lib/super_diff/rspec/inspection_tree_builders/collection_containing_exactly.rb +34 -0
  127. data/lib/super_diff/rspec/inspection_tree_builders/collection_including.rb +40 -0
  128. data/lib/super_diff/rspec/inspection_tree_builders/double.rb +100 -0
  129. data/lib/super_diff/rspec/inspection_tree_builders/generic_describable_matcher.rb +17 -0
  130. data/lib/super_diff/rspec/inspection_tree_builders/hash_including.rb +40 -0
  131. data/lib/super_diff/rspec/inspection_tree_builders/instance_of.rb +25 -0
  132. data/lib/super_diff/rspec/inspection_tree_builders/kind_of.rb +25 -0
  133. data/lib/super_diff/rspec/inspection_tree_builders/object_having_attributes.rb +34 -0
  134. data/lib/super_diff/rspec/inspection_tree_builders/primitive.rb +9 -0
  135. data/lib/super_diff/rspec/inspection_tree_builders/value_within.rb +30 -0
  136. data/lib/super_diff/rspec/inspection_tree_builders.rb +40 -0
  137. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +3 -7
  138. data/lib/super_diff/rspec/monkey_patches.rb +59 -8
  139. data/lib/super_diff/rspec/object_inspection.rb +14 -4
  140. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +4 -4
  141. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +1 -1
  142. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +1 -1
  143. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +2 -2
  144. data/lib/super_diff/rspec.rb +28 -25
  145. data/lib/super_diff/version.rb +1 -1
  146. data/lib/super_diff.rb +78 -21
  147. data/spec/examples.txt +704 -493
  148. data/spec/integration/rails/engines_spec.rb +8 -3
  149. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +19 -19
  150. data/spec/integration/rspec/eq_matcher_spec.rb +111 -39
  151. data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
  152. data/spec/integration/rspec/have_attributes_matcher_spec.rb +25 -25
  153. data/spec/integration/rspec/include_matcher_spec.rb +23 -23
  154. data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
  155. data/spec/integration/rspec/match_array_matcher_spec.rb +30 -30
  156. data/spec/integration/rspec/match_matcher_spec.rb +93 -93
  157. data/spec/integration/rspec/raise_error_matcher_spec.rb +813 -69
  158. data/spec/internal/log/test.log +0 -0
  159. data/spec/spec_helper.rb +3 -0
  160. data/spec/support/integration/helpers.rb +19 -11
  161. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +1 -1
  162. data/spec/support/integration/matchers.rb +34 -0
  163. data/spec/support/integration/test_programs/base.rb +6 -6
  164. data/spec/support/integration/test_programs/rspec_rails_engine.rb +3 -13
  165. data/spec/support/models/active_record/person.rb +8 -1
  166. data/spec/support/shared_examples/active_record.rb +38 -38
  167. data/spec/support/shared_examples/active_support.rb +125 -4
  168. data/spec/support/shared_examples/elided_diffs.rb +48 -48
  169. data/spec/support/shared_examples/hash_with_indifferent_access.rb +88 -88
  170. data/spec/support/shared_examples/key.rb +10 -10
  171. data/spec/support/unit/helpers.rb +12 -1
  172. data/spec/support/unit/matchers/be_deprecated_in_favor_of.rb +39 -0
  173. data/spec/unit/active_record/object_inspection_spec.rb +5 -5
  174. data/spec/unit/active_support/object_inspection_spec.rb +170 -0
  175. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/array_spec.rb +8 -8
  176. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/custom_object_spec.rb +9 -9
  177. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/default_object_spec.rb +9 -9
  178. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/hash_spec.rb +8 -8
  179. data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/multiline_string_spec.rb +4 -4
  180. data/spec/unit/{helpers_spec.rb → core/helpers_spec.rb} +2 -2
  181. data/spec/unit/{tiered_lines_elider_spec.rb → core/tiered_lines_elider_spec.rb} +2 -2
  182. data/spec/unit/{tiered_lines_formatter_spec.rb → core/tiered_lines_formatter_spec.rb} +1 -1
  183. data/spec/unit/deprecations_spec.rb +176 -0
  184. data/spec/unit/equality_matchers/main_spec.rb +5 -5
  185. data/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
  186. data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
  187. data/spec/unit/rspec/object_inspection_spec.rb +2 -2
  188. data/spec/unit/super_diff_spec.rb +64 -0
  189. data/super_diff.gemspec +6 -0
  190. metadata +137 -112
  191. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +0 -39
  192. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +0 -27
  193. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +0 -16
  194. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +0 -31
  195. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +0 -12
  196. data/lib/super_diff/colorized_document_extensions.rb +0 -18
  197. data/lib/super_diff/configuration.rb +0 -149
  198. data/lib/super_diff/diff_formatters/collection.rb +0 -132
  199. data/lib/super_diff/diff_formatters/multiline_string.rb +0 -31
  200. data/lib/super_diff/differs/array.rb +0 -15
  201. data/lib/super_diff/differs/custom_object.rb +0 -17
  202. data/lib/super_diff/differs/default_object.rb +0 -19
  203. data/lib/super_diff/differs/defaults.rb +0 -12
  204. data/lib/super_diff/differs/empty.rb +0 -13
  205. data/lib/super_diff/differs/hash.rb +0 -15
  206. data/lib/super_diff/differs/main.rb +0 -31
  207. data/lib/super_diff/differs/multiline_string.rb +0 -16
  208. data/lib/super_diff/differs/time_like.rb +0 -15
  209. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +0 -21
  210. data/lib/super_diff/gem_version.rb +0 -45
  211. data/lib/super_diff/helpers.rb +0 -86
  212. data/lib/super_diff/implementation_checks.rb +0 -19
  213. data/lib/super_diff/line.rb +0 -83
  214. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +0 -34
  215. data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +0 -27
  216. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +0 -31
  217. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +0 -54
  218. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +0 -14
  219. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +0 -38
  220. data/lib/super_diff/object_inspection/inspection_tree_builders/main.rb +0 -30
  221. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +0 -21
  222. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +0 -47
  223. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +0 -44
  224. data/lib/super_diff/object_inspection/nodes.rb +0 -50
  225. data/lib/super_diff/object_inspection/prefix_for_next_node.rb +0 -6
  226. data/lib/super_diff/object_inspection/prelude_for_next_node.rb +0 -6
  227. data/lib/super_diff/operation_tree_builders/array.rb +0 -107
  228. data/lib/super_diff/operation_tree_builders/custom_object.rb +0 -40
  229. data/lib/super_diff/operation_tree_builders/default_object.rb +0 -119
  230. data/lib/super_diff/operation_tree_builders/defaults.rb +0 -5
  231. data/lib/super_diff/operation_tree_builders/hash.rb +0 -218
  232. data/lib/super_diff/operation_tree_builders/multiline_string.rb +0 -86
  233. data/lib/super_diff/operation_tree_builders/time_like.rb +0 -24
  234. data/lib/super_diff/operation_tree_flatteners/array.rb +0 -15
  235. data/lib/super_diff/operation_tree_flatteners/collection.rb +0 -136
  236. data/lib/super_diff/operation_tree_flatteners/custom_object.rb +0 -28
  237. data/lib/super_diff/operation_tree_flatteners/default_object.rb +0 -31
  238. data/lib/super_diff/operation_tree_flatteners/hash.rb +0 -33
  239. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +0 -18
  240. data/lib/super_diff/operation_trees/array.rb +0 -15
  241. data/lib/super_diff/operation_trees/custom_object.rb +0 -15
  242. data/lib/super_diff/operation_trees/default_object.rb +0 -40
  243. data/lib/super_diff/operation_trees/defaults.rb +0 -5
  244. data/lib/super_diff/operation_trees/hash.rb +0 -15
  245. data/lib/super_diff/operation_trees/main.rb +0 -35
  246. data/lib/super_diff/operation_trees/multiline_string.rb +0 -15
  247. data/lib/super_diff/recursion_guard.rb +0 -50
  248. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +0 -29
  249. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +0 -36
  250. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +0 -98
  251. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +0 -37
  252. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +0 -28
  253. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +0 -28
  254. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +0 -29
  255. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +0 -10
  256. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +0 -33
  257. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +0 -44
  258. data/lib/super_diff/tiered_lines.rb +0 -4
  259. data/lib/super_diff/tiered_lines_elider.rb +0 -462
  260. data/lib/super_diff/tiered_lines_formatter.rb +0 -75
@@ -1,16 +1,21 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe "Integration with Rails engines", type: :integration do
3
+ RSpec.describe "Integration with Rails engines",
4
+ type: :integration,
5
+ active_support: true do
4
6
  context "when ActiveRecord is not loaded via Combustion" do
5
7
  it "does not fail to load" do
6
8
  as_both_colored_and_uncolored do |color_enabled|
7
9
  program =
8
- make_rspec_rails_engine_program(
10
+ make_rspec_rails_engine_with_action_controller_program(
9
11
  "expect(true).to be(true)",
10
- combustion_initialize: [:action_controller],
11
12
  color_enabled: color_enabled
12
13
  )
13
14
 
15
+ expect(program).to produce_output_when_run(
16
+ "1 example, 0 failures"
17
+ ).in_color(color_enabled)
18
+
14
19
  expect(program).not_to produce_output_when_run(
15
20
  "uninitialized constant ActiveRecord"
16
21
  ).in_color(color_enabled)
@@ -6,8 +6,8 @@ RSpec.describe "Integration with RSpec's #contain_exactly matcher",
6
6
  it "produces the correct failure message when used in the positive" do
7
7
  as_both_colored_and_uncolored do |color_enabled|
8
8
  snippet = <<~TEST.strip
9
- expected = ["Einie", "Marty"]
10
9
  actual = ["Marty", "Jennifer", "Doc"]
10
+ expected = ["Einie", "Marty"]
11
11
  expect(actual).to contain_exactly(*expected)
12
12
  TEST
13
13
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -84,6 +84,12 @@ RSpec.describe "Integration with RSpec's #contain_exactly matcher",
84
84
  it "produces the correct failure message when used in the positive" do
85
85
  as_both_colored_and_uncolored do |color_enabled|
86
86
  snippet = <<~TEST.strip
87
+ actual = [
88
+ "Marty McFly",
89
+ "Doc Brown",
90
+ "Einie",
91
+ "Lorraine McFly"
92
+ ]
87
93
  expected = [
88
94
  "Doc Brown",
89
95
  "Marty McFly",
@@ -91,12 +97,6 @@ RSpec.describe "Integration with RSpec's #contain_exactly matcher",
91
97
  "George McFly",
92
98
  "Lorraine McFly"
93
99
  ]
94
- actual = [
95
- "Marty McFly",
96
- "Doc Brown",
97
- "Einie",
98
- "Lorraine McFly"
99
- ]
100
100
  expect(actual).to contain_exactly(*expected)
101
101
  TEST
102
102
  program =
@@ -196,6 +196,12 @@ RSpec.describe "Integration with RSpec's #contain_exactly matcher",
196
196
  it "produces the correct failure message when used in the positive" do
197
197
  as_both_colored_and_uncolored do |color_enabled|
198
198
  snippet = <<~TEST
199
+ actual = [
200
+ "Marty McFly",
201
+ "Doc Brown",
202
+ "Einie",
203
+ "Lorraine McFly"
204
+ ]
199
205
  expected = [
200
206
  / Brown$/,
201
207
  "Marty McFly",
@@ -203,12 +209,6 @@ RSpec.describe "Integration with RSpec's #contain_exactly matcher",
203
209
  /Georg McFly/,
204
210
  /Lorrain McFly/
205
211
  ]
206
- actual = [
207
- "Marty McFly",
208
- "Doc Brown",
209
- "Einie",
210
- "Lorraine McFly"
211
- ]
212
212
  expect(actual).to contain_exactly(*expected)
213
213
  TEST
214
214
  program =
@@ -308,20 +308,20 @@ RSpec.describe "Integration with RSpec's #contain_exactly matcher",
308
308
  end
309
309
  end
310
310
 
311
- context "and some of them are fuzzy objects" do
311
+ context "and some of them are RSpec matchers" do
312
312
  it "produces the correct failure message" do
313
313
  as_both_colored_and_uncolored do |color_enabled|
314
314
  snippet = <<~TEST.strip
315
- expected = [
316
- a_hash_including(foo: "bar"),
317
- a_collection_containing_exactly("zing"),
318
- an_object_having_attributes(baz: "qux"),
319
- ]
320
315
  actual = [
321
316
  { foo: "bar" },
322
317
  double(baz: "qux"),
323
318
  { blargh: "riddle" }
324
319
  ]
320
+ expected = [
321
+ a_hash_including(foo: "bar"),
322
+ a_collection_containing_exactly("zing"),
323
+ an_object_having_attributes(baz: "qux"),
324
+ ]
325
325
  expect(actual).to contain_exactly(*expected)
326
326
  TEST
327
327
  program =
@@ -173,16 +173,16 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
173
173
  it "produces the correct failure message when used in the positive" do
174
174
  as_both_colored_and_uncolored do |color_enabled|
175
175
  snippet = <<~RUBY
176
- expected = Time.utc(2011, 12, 13, 14, 15, 16)
177
- actual = Time.utc(2011, 12, 13, 14, 15, 16, 500_000)
178
- expect(expected).to eq(actual)
176
+ actual = Time.utc(2011, 12, 13, 14, 15, 16)
177
+ expected = Time.utc(2011, 12, 13, 14, 15, 16, 500_000)
178
+ expect(actual).to eq(expected)
179
179
  RUBY
180
180
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
181
181
 
182
182
  expected_output =
183
183
  build_expected_output(
184
184
  color_enabled: color_enabled,
185
- snippet: "expect(expected).to eq(actual)",
185
+ snippet: "expect(actual).to eq(expected)",
186
186
  expectation:
187
187
  proc do
188
188
  line do
@@ -252,12 +252,84 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
252
252
  end
253
253
  end
254
254
 
255
+ context "when comparing two different Date instances" do
256
+ it "produces the correct failure message when used in the positive" do
257
+ as_both_colored_and_uncolored do |color_enabled|
258
+ snippet = <<~RUBY
259
+ actual = Date.new(2023, 10, 14)
260
+ expected = Date.new(2023, 10, 31)
261
+ expect(actual).to eq(expected)
262
+ RUBY
263
+ program = 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).to eq(expected)",
269
+ expectation:
270
+ proc do
271
+ line do
272
+ plain "Expected "
273
+ actual "#<Date 2023-10-14>"
274
+ plain " to eq "
275
+ expected "#<Date 2023-10-31>"
276
+ plain "."
277
+ end
278
+ end,
279
+ diff:
280
+ proc do
281
+ plain_line " #<Date {"
282
+ plain_line " year: 2023,"
283
+ plain_line " month: 10,"
284
+ expected_line "- day: 31"
285
+ actual_line "+ day: 14"
286
+ plain_line " }>"
287
+ end
288
+ )
289
+
290
+ expect(program).to produce_output_when_run(expected_output).in_color(
291
+ color_enabled
292
+ )
293
+ end
294
+ end
295
+
296
+ it "produces the correct failure message when used in the negative" do
297
+ as_both_colored_and_uncolored do |color_enabled|
298
+ snippet = <<~RUBY
299
+ date = Date.new(2023, 10, 14)
300
+ expect(date).not_to eq(date)
301
+ RUBY
302
+ program = make_plain_test_program(snippet, color_enabled: color_enabled)
303
+
304
+ expected_output =
305
+ build_expected_output(
306
+ color_enabled: color_enabled,
307
+ snippet: "expect(date).not_to eq(date)",
308
+ expectation:
309
+ proc do
310
+ line do
311
+ plain "Expected "
312
+ actual "#<Date 2023-10-14>"
313
+ plain " not to eq "
314
+ expected "#<Date 2023-10-14>"
315
+ plain "."
316
+ end
317
+ end
318
+ )
319
+
320
+ expect(program).to produce_output_when_run(expected_output).in_color(
321
+ color_enabled
322
+ )
323
+ end
324
+ end
325
+ end
326
+
255
327
  context "when comparing a single-line string with a multi-line string" do
256
328
  it "produces the correct failure message" do
257
329
  as_both_colored_and_uncolored do |color_enabled|
258
330
  snippet = <<~TEST.strip
259
- expected = "Something entirely different"
260
331
  actual = "This is a line\\nAnd that's another line\\n"
332
+ expected = "Something entirely different"
261
333
  expect(actual).to eq(expected)
262
334
  TEST
263
335
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -295,8 +367,8 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
295
367
  it "produces the correct failure message" do
296
368
  as_both_colored_and_uncolored do |color_enabled|
297
369
  snippet = <<~TEST.strip
298
- expected = "This is a line\\nAnd that's another line\\n"
299
370
  actual = "Something entirely different"
371
+ expected = "This is a line\\nAnd that's another line\\n"
300
372
  expect(actual).to eq(expected)
301
373
  TEST
302
374
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -334,8 +406,8 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
334
406
  it "produces the correct failure message when used in the positive" do
335
407
  as_both_colored_and_uncolored do |color_enabled|
336
408
  snippet = <<~TEST.strip
337
- expected = "This is a line\\nAnd that's a line\\nAnd there's a line too\\n"
338
409
  actual = "This is a line\\nSomething completely different\\nAnd there's a line too\\n"
410
+ expected = "This is a line\\nAnd that's a line\\nAnd there's a line too\\n"
339
411
  expect(actual).to eq(expected)
340
412
  TEST
341
413
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -409,19 +481,6 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
409
481
  it "produces the correct failure message when used in the positive" do
410
482
  as_both_colored_and_uncolored do |color_enabled|
411
483
  snippet = <<~TEST
412
- expected = [
413
- [
414
- :h1,
415
- [:span, [:text, "Hello world"]],
416
- {
417
- class: "header",
418
- data: {
419
- "sticky" => true,
420
- person: SuperDiff::Test::Person.new(name: "Marty", age: 60)
421
- }
422
- }
423
- ]
424
- ]
425
484
  actual = [
426
485
  [
427
486
  :h2,
@@ -438,6 +497,19 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
438
497
  ],
439
498
  :br
440
499
  ]
500
+ expected = [
501
+ [
502
+ :h1,
503
+ [:span, [:text, "Hello world"]],
504
+ {
505
+ class: "header",
506
+ data: {
507
+ "sticky" => true,
508
+ person: SuperDiff::Test::Person.new(name: "Marty", age: 60)
509
+ }
510
+ }
511
+ ]
512
+ ]
441
513
  expect(actual).to eq(expected)
442
514
  TEST
443
515
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -548,11 +620,11 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
548
620
  it "produces the correct failure message when used in the positive" do
549
621
  as_both_colored_and_uncolored do |color_enabled|
550
622
  snippet = <<~TEST.strip
551
- expected = {
623
+ actual = {
552
624
  customer: {
553
- person: SuperDiff::Test::Person.new(name: "Marty McFly", age: 17),
625
+ person: SuperDiff::Test::Person.new(name: "Marty McFly, Jr.", age: 17),
554
626
  shipping_address: {
555
- line_1: "123 Main St.",
627
+ line_1: "456 Ponderosa Ct.",
556
628
  city: "Hill Valley",
557
629
  state: "CA",
558
630
  zip: "90382"
@@ -564,14 +636,14 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
564
636
  cost: 100_000,
565
637
  options: ["red", "blue", "green"]
566
638
  },
567
- { name: "Chevy 4x4" }
639
+ { name: "Mattel Hoverboard" }
568
640
  ]
569
641
  }
570
- actual = {
642
+ expected = {
571
643
  customer: {
572
- person: SuperDiff::Test::Person.new(name: "Marty McFly, Jr.", age: 17),
644
+ person: SuperDiff::Test::Person.new(name: "Marty McFly", age: 17),
573
645
  shipping_address: {
574
- line_1: "456 Ponderosa Ct.",
646
+ line_1: "123 Main St.",
575
647
  city: "Hill Valley",
576
648
  state: "CA",
577
649
  zip: "90382"
@@ -583,7 +655,7 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
583
655
  cost: 100_000,
584
656
  options: ["red", "blue", "green"]
585
657
  },
586
- { name: "Mattel Hoverboard" }
658
+ { name: "Chevy 4x4" }
587
659
  ]
588
660
  }
589
661
  expect(actual).to eq(expected)
@@ -704,15 +776,15 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
704
776
  it "produces the correct failure message when used in the positive" do
705
777
  as_both_colored_and_uncolored do |color_enabled|
706
778
  snippet = <<~TEST.strip
707
- expected = SuperDiff::Test::Person.new(
708
- name: "Marty",
709
- age: 31,
710
- )
711
779
  actual = SuperDiff::Test::Customer.new(
712
780
  name: "Doc",
713
781
  shipping_address: :some_shipping_address,
714
782
  phone: "1234567890",
715
783
  )
784
+ expected = SuperDiff::Test::Person.new(
785
+ name: "Marty",
786
+ age: 31,
787
+ )
716
788
  expect(actual).to eq(expected)
717
789
  TEST
718
790
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -783,10 +855,6 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
783
855
  it "produces the correct failure message when used in the positive" do
784
856
  as_both_colored_and_uncolored do |color_enabled|
785
857
  snippet = <<~TEST.strip
786
- expected = SuperDiff::Test::Item.new(
787
- name: "camera",
788
- quantity: 3,
789
- )
790
858
  actual = SuperDiff::Test::Player.new(
791
859
  handle: "mcmire",
792
860
  character: "Jon",
@@ -795,6 +863,10 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
795
863
  health: 4,
796
864
  ultimate: true,
797
865
  )
866
+ expected = SuperDiff::Test::Item.new(
867
+ name: "camera",
868
+ quantity: 3,
869
+ )
798
870
  expect(actual).to eq(expected)
799
871
  TEST
800
872
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -865,8 +937,8 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
865
937
  it "formats the array correctly in the diff" do
866
938
  as_both_colored_and_uncolored do |color_enabled|
867
939
  snippet = <<~TEST.strip
868
- expected = { foo: nil }
869
940
  actual = { foo: [] }
941
+ expected = { foo: nil }
870
942
  expect(actual).to eq(expected)
871
943
  TEST
872
944
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -906,8 +978,8 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
906
978
  it "formats the hash correctly in the diff" do
907
979
  as_both_colored_and_uncolored do |color_enabled|
908
980
  snippet = <<~TEST.strip
909
- expected = { foo: nil }
910
981
  actual = { foo: {} }
982
+ expected = { foo: nil }
911
983
  expect(actual).to eq(expected)
912
984
  TEST
913
985
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -947,8 +1019,8 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
947
1019
  it "formats the object correctly in the diff" do
948
1020
  as_both_colored_and_uncolored do |color_enabled|
949
1021
  snippet = <<~TEST.strip
950
- expected = { foo: nil }
951
1022
  actual = { foo: SuperDiff::Test::EmptyClass.new }
1023
+ expected = { foo: nil }
952
1024
  expect(actual).to eq(expected)
953
1025
  TEST
954
1026
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
@@ -0,0 +1,177 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Integration with describable matchers not handled specially",
4
+ type: :integration do
5
+ context "when the expected value contains a built-in matcher (not an aliased matcher)" 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 = {
10
+ number: "not a number"
11
+ }
12
+ expected = hash_including(
13
+ number: be_a(Numeric)
14
+ )
15
+ expect(actual).to match(expected)
16
+ TEST
17
+ program = make_plain_test_program(snippet, color_enabled: color_enabled)
18
+
19
+ expected_output =
20
+ build_expected_output(
21
+ color_enabled: color_enabled,
22
+ snippet: "expect(actual).to match(expected)",
23
+ expectation:
24
+ proc do
25
+ line do
26
+ plain "Expected "
27
+ actual %|{ number: "not a number" }|
28
+ plain " to match "
29
+ expected "#<a hash including (number: #<be a kind of Numeric>)>"
30
+ plain "."
31
+ end
32
+ end,
33
+ diff:
34
+ proc do
35
+ plain_line " {"
36
+ expected_line "- number: #<be a kind of Numeric>"
37
+ actual_line %|+ number: "not a number"|
38
+ plain_line " }"
39
+ end
40
+ )
41
+
42
+ expect(program).to produce_output_when_run(expected_output).in_color(
43
+ color_enabled
44
+ )
45
+ end
46
+ end
47
+
48
+ it "produces the correct failure message when used in the negative" do
49
+ as_both_colored_and_uncolored do |color_enabled|
50
+ snippet = <<~TEST.strip
51
+ actual = {
52
+ number: 4
53
+ }
54
+ expected = hash_including(
55
+ number: be_a(Numeric)
56
+ )
57
+ expect(actual).not_to match(expected)
58
+ TEST
59
+ program = make_plain_test_program(snippet, color_enabled: color_enabled)
60
+
61
+ expected_output =
62
+ build_expected_output(
63
+ color_enabled: color_enabled,
64
+ snippet: "expect(actual).not_to match(expected)",
65
+ expectation:
66
+ proc do
67
+ line do
68
+ plain "Expected "
69
+ actual "{ number: 4 }"
70
+ plain " not to match "
71
+ expected "#<a hash including (number: #<be a kind of Numeric>)>"
72
+ plain "."
73
+ end
74
+ end
75
+ )
76
+
77
+ expect(program).to produce_output_when_run(expected_output).in_color(
78
+ color_enabled
79
+ )
80
+ end
81
+ end
82
+ end
83
+
84
+ context "when the expected value contains a custom matcher defined via RSpec::Matchers::DSL" do
85
+ it "produces the correct failure message" do
86
+ as_both_colored_and_uncolored do |color_enabled|
87
+ snippet = <<~TEST.strip
88
+ actual = {
89
+ number: "something else"
90
+ }
91
+ expected = hash_including(
92
+ number: failing_custom_matcher_from_dsl(42)
93
+ )
94
+ expect(actual).to match(expected)
95
+ TEST
96
+ program = make_plain_test_program(snippet, color_enabled: color_enabled)
97
+
98
+ expected_output =
99
+ build_expected_output(
100
+ color_enabled: color_enabled,
101
+ snippet: "expect(actual).to match(expected)",
102
+ newline_before_expectation: true,
103
+ expectation:
104
+ proc do
105
+ line do
106
+ plain "Expected "
107
+ actual %|{ number: "something else" }|
108
+ end
109
+
110
+ line do
111
+ plain "to match "
112
+ expected "#<a hash including (number: #<custom matcher defined via the DSL with value 42>)>"
113
+ end
114
+ end,
115
+ diff:
116
+ proc do
117
+ plain_line " {"
118
+ expected_line "- number: #<custom matcher defined via the DSL with value 42>"
119
+ actual_line %|+ number: "something else"|
120
+ plain_line " }"
121
+ end
122
+ )
123
+
124
+ expect(program).to produce_output_when_run(expected_output).in_color(
125
+ color_enabled
126
+ )
127
+ end
128
+ end
129
+ end
130
+
131
+ context "when the expected value contains a custom matcher defined from scratch" do
132
+ it "produces the correct failure message" do
133
+ as_both_colored_and_uncolored do |color_enabled|
134
+ snippet = <<~TEST.strip
135
+ actual = {
136
+ number: "something else"
137
+ }
138
+ expected = hash_including(
139
+ number: failing_custom_matcher_from_scratch(42)
140
+ )
141
+ expect(actual).to match(expected)
142
+ TEST
143
+ program = make_plain_test_program(snippet, color_enabled: color_enabled)
144
+
145
+ expected_output =
146
+ build_expected_output(
147
+ color_enabled: color_enabled,
148
+ snippet: "expect(actual).to match(expected)",
149
+ newline_before_expectation: true,
150
+ expectation:
151
+ proc do
152
+ line do
153
+ plain "Expected "
154
+ actual %|{ number: "something else" }|
155
+ end
156
+
157
+ line do
158
+ plain "to match "
159
+ expected "#<a hash including (number: #<custom matcher defined from scratch with value 42>)>"
160
+ end
161
+ end,
162
+ diff:
163
+ proc do
164
+ plain_line " {"
165
+ expected_line "- number: #<custom matcher defined from scratch with value 42>"
166
+ actual_line %|+ number: "something else"|
167
+ plain_line " }"
168
+ end
169
+ )
170
+
171
+ expect(program).to produce_output_when_run(expected_output).in_color(
172
+ color_enabled
173
+ )
174
+ end
175
+ end
176
+ end
177
+ end