super_diff 0.10.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of super_diff might be problematic. Click here for more details.

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 +33 -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
File without changes
data/spec/spec_helper.rb CHANGED
@@ -65,6 +65,9 @@ RSpec.configure do |config|
65
65
  config.default_formatter = "documentation" if !%w[true 1].include?(ENV["CI"])
66
66
 
67
67
  config.filter_run_excluding active_record: true unless active_record_available
68
+ unless defined?(ActiveSupport)
69
+ config.filter_run_excluding active_support: true
70
+ end
68
71
 
69
72
  config.order = :random
70
73
  Kernel.srand config.seed
@@ -9,13 +9,13 @@ module SuperDiff
9
9
  def make_plain_test_program(
10
10
  test,
11
11
  color_enabled:,
12
- configuration: {},
12
+ super_diff_configuration: {},
13
13
  preserve_as_whole_file: false
14
14
  )
15
15
  TestPrograms::Plain.new(
16
16
  test,
17
17
  color_enabled: color_enabled,
18
- configuration: configuration,
18
+ super_diff_configuration: super_diff_configuration,
19
19
  preserve_as_whole_file: preserve_as_whole_file
20
20
  )
21
21
  end
@@ -32,15 +32,13 @@ module SuperDiff
32
32
  TestPrograms::RSpecRails.new(test, color_enabled: color_enabled)
33
33
  end
34
34
 
35
- def make_rspec_rails_engine_program(
35
+ def make_rspec_rails_engine_with_action_controller_program(
36
36
  test,
37
- color_enabled:,
38
- combustion_initialize:
37
+ color_enabled:
39
38
  )
40
- TestPrograms::RspecRailsEngine.new(
39
+ TestPrograms::RspecRailsEngineWithActionController.new(
41
40
  test,
42
- color_enabled: color_enabled,
43
- combustion_initialize: combustion_initialize
41
+ color_enabled: color_enabled
44
42
  )
45
43
  end
46
44
 
@@ -48,15 +46,17 @@ module SuperDiff
48
46
  color_enabled:,
49
47
  snippet:,
50
48
  expectation:,
49
+ test_name: "test passes",
51
50
  key_enabled: true,
52
51
  newline_before_expectation: false,
53
52
  indentation: 7,
54
- diff: nil
53
+ diff: nil,
54
+ extra_failure_lines: nil
55
55
  )
56
56
  colored(color_enabled: color_enabled) do
57
57
  line "Failures:\n"
58
58
 
59
- line "1) test passes", indent_by: 2
59
+ line "1) #{test_name}", indent_by: 2
60
60
 
61
61
  line indent_by: 5 do
62
62
  bold "Failure/Error: "
@@ -106,11 +106,19 @@ module SuperDiff
106
106
  newline
107
107
  end
108
108
  end
109
+
110
+ if extra_failure_lines
111
+ newline
112
+ evaluate_block(&extra_failure_lines)
113
+ end
109
114
  end
110
115
  end
111
116
 
112
117
  def colored(color_enabled: true, &block)
113
- SuperDiff::Helpers.style(color_enabled: color_enabled, &block).to_s.chomp
118
+ SuperDiff::Core::Helpers
119
+ .style(color_enabled: color_enabled, &block)
120
+ .to_s
121
+ .chomp
114
122
  end
115
123
  end
116
124
  end
@@ -12,7 +12,7 @@ module SuperDiff
12
12
  end
13
13
 
14
14
  def removing_object_ids
15
- first_replacing(/#<([\w:]+):0x[a-f0-9]+/, '#<\1')
15
+ first_replacing(/#<([\w_:]+):0x[a-f0-9]+/, '#<\1')
16
16
  self
17
17
  end
18
18
 
@@ -32,6 +32,40 @@ module SuperDiff
32
32
  PassWithSinglelineFailureMessageMatcher.new
33
33
  end
34
34
 
35
+ RSpec::Matchers.define :failing_custom_matcher_from_dsl do |value|
36
+ match { false }
37
+
38
+ description do
39
+ "custom matcher defined via the DSL with value #{value.inspect}"
40
+ end
41
+ end
42
+
43
+ def failing_custom_matcher_from_scratch(value)
44
+ FailingCustomMatcherFromScratch.new(value)
45
+ end
46
+
47
+ class FailingCustomMatcherFromScratch
48
+ def initialize(value)
49
+ @value = value
50
+ end
51
+
52
+ def matches?(_)
53
+ false
54
+ end
55
+
56
+ def description
57
+ "custom matcher defined from scratch with value #{value.inspect}"
58
+ end
59
+
60
+ def failure_message
61
+ "Expected custom matcher not to fail, but did"
62
+ end
63
+
64
+ private
65
+
66
+ attr_reader :value
67
+ end
68
+
35
69
  class FailWithIndentedMultilineFailureMessageMatcher
36
70
  def matches?(_)
37
71
  false
@@ -13,12 +13,12 @@ module SuperDiff
13
13
  def initialize(
14
14
  code,
15
15
  color_enabled:,
16
- configuration: {},
16
+ super_diff_configuration: {},
17
17
  preserve_as_whole_file: false
18
18
  )
19
19
  @code = code.strip
20
20
  @color_enabled = color_enabled
21
- @configuration = configuration
21
+ @super_diff_configuration = super_diff_configuration
22
22
  @preserve_as_whole_file = preserve_as_whole_file
23
23
  end
24
24
 
@@ -38,7 +38,7 @@ module SuperDiff
38
38
 
39
39
  private
40
40
 
41
- attr_reader :code, :configuration
41
+ attr_reader :code, :super_diff_configuration
42
42
 
43
43
  def color_enabled?
44
44
  @color_enabled
@@ -74,8 +74,8 @@ module SuperDiff
74
74
  color_option,
75
75
  "--no-pry",
76
76
  tempfile.to_s,
77
- "--configuration",
78
- JSON.generate(configuration)
77
+ "--super-diff-configuration",
78
+ JSON.generate(super_diff_configuration)
79
79
  ]
80
80
  else
81
81
  ["rspec", "--options", "/tmp/dummy-rspec-config", tempfile.to_s]
@@ -110,7 +110,7 @@ module SuperDiff
110
110
  test_plan = TestPlan.new(
111
111
  using_outside_of_zeus: true,
112
112
  color_enabled: #{color_enabled?.inspect},
113
- configuration: #{configuration.inspect}
113
+ super_diff_configuration: #{super_diff_configuration.inspect}
114
114
  )
115
115
  #{test_plan_prelude}
116
116
  test_plan.#{test_plan_command}
@@ -1,29 +1,19 @@
1
1
  module SuperDiff
2
2
  module IntegrationTests
3
3
  module TestPrograms
4
- class RspecRailsEngine < Base
5
- def initialize(*args, combustion_initialize:, **options)
6
- super(*args, **options)
7
- @combustion_initialize = combustion_initialize
8
- end
9
-
4
+ class RspecRailsEngineWithActionController < Base
10
5
  protected
11
6
 
12
7
  def test_plan_prelude
13
8
  <<~PRELUDE.strip
14
- test_plan.boot_rails_engine(
15
- combustion_initialize: #{combustion_initialize.inspect}
16
- )
9
+ test_plan.boot
10
+ test_plan.boot_rails_engine_with_action_controller
17
11
  PRELUDE
18
12
  end
19
13
 
20
14
  def test_plan_command
21
15
  "run_rspec_rails_test"
22
16
  end
23
-
24
- private
25
-
26
- attr_reader :combustion_initialize
27
17
  end
28
18
  end
29
19
  end
@@ -3,6 +3,7 @@ module SuperDiff
3
3
  module Models
4
4
  module ActiveRecord
5
5
  class Person < ::ActiveRecord::Base
6
+ self.primary_key = "person_id"
6
7
  end
7
8
  end
8
9
  end
@@ -13,7 +14,13 @@ RSpec.configure do |config|
13
14
  config.before do
14
15
  ActiveRecord::Base
15
16
  .connection
16
- .create_table(:people, force: true) do |t|
17
+ .create_table(
18
+ :people,
19
+ id: false,
20
+ primary_key: "person_id",
21
+ force: true
22
+ ) do |t|
23
+ t.primary_key :person_id, null: false
17
24
  t.string :name, null: false
18
25
  t.integer :age, null: false
19
26
  end
@@ -4,18 +4,18 @@ shared_examples_for "integration with ActiveRecord" do
4
4
  it "produces the correct output" do
5
5
  as_both_colored_and_uncolored do |color_enabled|
6
6
  snippet = <<~TEST.strip
7
- expected = SuperDiff::Test::Models::ActiveRecord::ShippingAddress.new(
8
- line_1: "123 Main St.",
9
- city: "Hill Valley",
10
- state: "CA",
11
- zip: "90382",
12
- )
13
7
  actual = SuperDiff::Test::Models::ActiveRecord::ShippingAddress.new(
14
8
  line_1: "456 Ponderosa Ct.",
15
9
  city: "Oakland",
16
10
  state: "CA",
17
11
  zip: "91234",
18
12
  )
13
+ expected = SuperDiff::Test::Models::ActiveRecord::ShippingAddress.new(
14
+ line_1: "123 Main St.",
15
+ city: "Hill Valley",
16
+ state: "CA",
17
+ zip: "90382",
18
+ )
19
19
  expect(actual).to eq(expected)
20
20
  TEST
21
21
  program = make_program(snippet, color_enabled: color_enabled)
@@ -63,16 +63,16 @@ shared_examples_for "integration with ActiveRecord" do
63
63
  it "produces the correct output" do
64
64
  as_both_colored_and_uncolored do |color_enabled|
65
65
  snippet = <<~TEST.strip
66
+ actual = SuperDiff::Test::Models::ActiveRecord::Person.new(
67
+ name: "Elliot",
68
+ age: 31,
69
+ )
66
70
  expected = SuperDiff::Test::Models::ActiveRecord::ShippingAddress.new(
67
71
  line_1: "123 Main St.",
68
72
  city: "Hill Valley",
69
73
  state: "CA",
70
74
  zip: "90382",
71
75
  )
72
- actual = SuperDiff::Test::Models::ActiveRecord::Person.new(
73
- name: "Elliot",
74
- age: 31,
75
- )
76
76
  expect(actual).to eq(expected)
77
77
  TEST
78
78
  program = make_program(snippet, color_enabled: color_enabled)
@@ -86,7 +86,7 @@ shared_examples_for "integration with ActiveRecord" do
86
86
  proc do
87
87
  line do
88
88
  plain "Expected "
89
- actual %|#<SuperDiff::Test::Models::ActiveRecord::Person id: nil, age: 31, name: "Elliot">|
89
+ actual %|#<SuperDiff::Test::Models::ActiveRecord::Person person_id: nil, age: 31, name: "Elliot">|
90
90
  end
91
91
 
92
92
  line do
@@ -107,13 +107,13 @@ shared_examples_for "integration with ActiveRecord" do
107
107
  it "produces the correct output" do
108
108
  as_both_colored_and_uncolored do |color_enabled|
109
109
  snippet = <<~TEST.strip
110
+ actual = nil
110
111
  expected = SuperDiff::Test::Models::ActiveRecord::ShippingAddress.new(
111
112
  line_1: "123 Main St.",
112
113
  city: "Hill Valley",
113
114
  state: "CA",
114
115
  zip: "90382"
115
116
  )
116
- actual = nil
117
117
  expect(actual).to eq(expected)
118
118
  TEST
119
119
  program = make_program(snippet, color_enabled: color_enabled)
@@ -148,22 +148,22 @@ shared_examples_for "integration with ActiveRecord" do
148
148
  it "produces the correct output" do
149
149
  as_both_colored_and_uncolored do |color_enabled|
150
150
  snippet = <<~TEST.strip
151
- expected = {
151
+ actual = {
152
152
  name: "Marty McFly",
153
153
  shipping_address: SuperDiff::Test::Models::ActiveRecord::ShippingAddress.new(
154
- line_1: "123 Main St.",
155
- city: "Hill Valley",
154
+ line_1: "456 Ponderosa Ct.",
155
+ city: "Oakland",
156
156
  state: "CA",
157
- zip: "90382",
157
+ zip: "91234",
158
158
  )
159
159
  }
160
- actual = {
160
+ expected = {
161
161
  name: "Marty McFly",
162
162
  shipping_address: SuperDiff::Test::Models::ActiveRecord::ShippingAddress.new(
163
- line_1: "456 Ponderosa Ct.",
164
- city: "Oakland",
163
+ line_1: "123 Main St.",
164
+ city: "Hill Valley",
165
165
  state: "CA",
166
- zip: "91234",
166
+ zip: "90382",
167
167
  )
168
168
  }
169
169
  expect(actual).to eq(expected)
@@ -216,6 +216,13 @@ shared_examples_for "integration with ActiveRecord" do
216
216
  it "produces the correct output" do
217
217
  as_both_colored_and_uncolored do |color_enabled|
218
218
  snippet = <<~TEST.strip
219
+ actual = {
220
+ name: "Marty McFly",
221
+ shipping_address: SuperDiff::Test::Models::ActiveRecord::Person.new(
222
+ name: "Elliot",
223
+ age: 31,
224
+ )
225
+ }
219
226
  expected = {
220
227
  name: "Marty McFly",
221
228
  shipping_address: SuperDiff::Test::Models::ActiveRecord::ShippingAddress.new(
@@ -225,13 +232,6 @@ shared_examples_for "integration with ActiveRecord" do
225
232
  zip: "90382",
226
233
  )
227
234
  }
228
- actual = {
229
- name: "Marty McFly",
230
- shipping_address: SuperDiff::Test::Models::ActiveRecord::Person.new(
231
- name: "Elliot",
232
- age: 31,
233
- )
234
- }
235
235
  expect(actual).to eq(expected)
236
236
  TEST
237
237
  program = make_program(snippet, color_enabled: color_enabled)
@@ -244,7 +244,7 @@ shared_examples_for "integration with ActiveRecord" do
244
244
  proc do
245
245
  line do
246
246
  plain "Expected "
247
- actual %|{ name: "Marty McFly", shipping_address: #<SuperDiff::Test::Models::ActiveRecord::Person id: nil, age: 31, name: "Elliot"> }|
247
+ actual %|{ name: "Marty McFly", shipping_address: #<SuperDiff::Test::Models::ActiveRecord::Person person_id: nil, age: 31, name: "Elliot"> }|
248
248
  end
249
249
 
250
250
  line do
@@ -265,7 +265,7 @@ shared_examples_for "integration with ActiveRecord" do
265
265
  expected_line %|- zip: "90382"|
266
266
  expected_line "- }>"
267
267
  actual_line "+ shipping_address: #<SuperDiff::Test::Models::ActiveRecord::Person {"
268
- actual_line "+ id: nil,"
268
+ actual_line "+ person_id: nil,"
269
269
  actual_line "+ age: 31,"
270
270
  actual_line %|+ name: "Elliot"|
271
271
  actual_line "+ }>"
@@ -299,8 +299,8 @@ shared_examples_for "integration with ActiveRecord" do
299
299
  zip: "91234",
300
300
  )
301
301
  ]
302
- expected = [shipping_addresses.first]
303
302
  actual = SuperDiff::Test::Models::ActiveRecord::ShippingAddress.all
303
+ expected = [shipping_addresses.first]
304
304
  expect(actual).to eq(expected)
305
305
  TEST
306
306
  program = make_program(snippet, color_enabled: color_enabled)
@@ -362,6 +362,12 @@ shared_examples_for "integration with ActiveRecord" do
362
362
  age: 20
363
363
  )
364
364
 
365
+ actual = [
366
+ SuperDiff::Test::Models::ActiveRecord::Query.new(
367
+ results: SuperDiff::Test::Models::ActiveRecord::Person.all
368
+ )
369
+ ]
370
+
365
371
  expected = [
366
372
  an_object_having_attributes(
367
373
  results: [
@@ -370,12 +376,6 @@ shared_examples_for "integration with ActiveRecord" do
370
376
  )
371
377
  ]
372
378
 
373
- actual = [
374
- SuperDiff::Test::Models::ActiveRecord::Query.new(
375
- results: SuperDiff::Test::Models::ActiveRecord::Person.all
376
- )
377
- ]
378
-
379
379
  expect(actual).to match(expected)
380
380
  TEST
381
381
 
@@ -390,7 +390,7 @@ shared_examples_for "integration with ActiveRecord" do
390
390
  proc do
391
391
  line do
392
392
  plain "Expected "
393
- actual %|[#<SuperDiff::Test::Models::ActiveRecord::Query @results=#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person id: 1, age: 20, name: "Murphy">]>>]|
393
+ actual %|[#<SuperDiff::Test::Models::ActiveRecord::Query @results=#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person person_id: 1, age: 20, name: "Murphy">]>>]|
394
394
  end
395
395
 
396
396
  line do
@@ -404,7 +404,7 @@ shared_examples_for "integration with ActiveRecord" do
404
404
  plain_line " #<SuperDiff::Test::Models::ActiveRecord::Query {"
405
405
  plain_line " @results=#<ActiveRecord::Relation ["
406
406
  plain_line " #<SuperDiff::Test::Models::ActiveRecord::Person {"
407
- plain_line " id: 1,"
407
+ plain_line " person_id: 1,"
408
408
  # expected_line %|- age: 19,| # TODO
409
409
  expected_line "- age: 19"
410
410
  actual_line "+ age: 20,"
@@ -4,9 +4,9 @@ shared_examples_for "integration with ActiveSupport" do
4
4
  it "produces the correct failure message when used in the positive" do
5
5
  as_both_colored_and_uncolored do |color_enabled|
6
6
  snippet = <<~RUBY
7
- expected = Time.utc(2011, 12, 13, 14, 15, 16)
8
- actual = Time.utc(2011, 12, 13, 15, 15, 16).in_time_zone("Europe/Stockholm")
9
- expect(expected).to eq(actual)
7
+ actual = Time.utc(2011, 12, 13, 14, 15, 16)
8
+ expected = Time.utc(2011, 12, 13, 15, 15, 16).in_time_zone("Europe/Stockholm")
9
+ expect(actual).to eq(expected)
10
10
  RUBY
11
11
  program =
12
12
  make_rspec_rails_test_program(snippet, color_enabled: color_enabled)
@@ -14,7 +14,7 @@ shared_examples_for "integration with ActiveSupport" do
14
14
  expected_output =
15
15
  build_expected_output(
16
16
  color_enabled: color_enabled,
17
- snippet: "expect(expected).to eq(actual)",
17
+ snippet: "expect(actual).to eq(expected)",
18
18
  expectation:
19
19
  proc do
20
20
  line do
@@ -64,4 +64,125 @@ shared_examples_for "integration with ActiveSupport" do
64
64
  end
65
65
  end
66
66
  end
67
+
68
+ context "when comparing OrderedOptions and Hash instances",
69
+ active_record: true do
70
+ it "produces the correct failure message when used in the positive" do
71
+ as_both_colored_and_uncolored do |color_enabled|
72
+ snippet = <<~RUBY
73
+ actual = {beep: :bip}
74
+ expected = ::ActiveSupport::OrderedOptions[beep: :boop]
75
+ expect(actual).to eq(expected)
76
+ RUBY
77
+ program =
78
+ make_rspec_rails_test_program(snippet, color_enabled: color_enabled)
79
+
80
+ expected_output =
81
+ build_expected_output(
82
+ color_enabled: color_enabled,
83
+ snippet: "expect(actual).to eq(expected)",
84
+ expectation:
85
+ proc do
86
+ line do
87
+ plain "Expected "
88
+ actual "{ beep: :bip }"
89
+ plain " to eq "
90
+ expected "#<OrderedOptions { beep: :boop }>"
91
+ plain "."
92
+ end
93
+ end,
94
+ diff:
95
+ proc do
96
+ plain_line " {"
97
+ expected_line "- beep: :boop"
98
+ actual_line "+ beep: :bip"
99
+ plain_line " }"
100
+ end
101
+ )
102
+
103
+ expect(program).to produce_output_when_run(expected_output).in_color(
104
+ color_enabled
105
+ )
106
+ end
107
+ end
108
+ end
109
+
110
+ context "when comparing Date instance and date-like DateTime instance for same day",
111
+ active_record: true do
112
+ it "produces the correct failure message when used in the positive" do
113
+ as_both_colored_and_uncolored do |color_enabled|
114
+ snippet = <<~RUBY
115
+ actual = Date.new(2023, 10, 14)
116
+ expected = DateTime.new(2023, 10, 14, 18, 22, 26)
117
+ expect(actual).to eq(expected)
118
+ RUBY
119
+ program =
120
+ make_rspec_rails_test_program(snippet, color_enabled: color_enabled)
121
+
122
+ expected_output =
123
+ build_expected_output(
124
+ color_enabled: color_enabled,
125
+ snippet: "expect(actual).to eq(expected)",
126
+ expectation:
127
+ proc do
128
+ line do
129
+ plain "Expected "
130
+ actual "#<Date 2023-10-14>"
131
+ plain " to eq "
132
+ expected "#<DateTime 2023-10-14 18:22:26 +00:00 (+00:00)>"
133
+ plain "."
134
+ end
135
+ end
136
+ )
137
+
138
+ expect(program).to produce_output_when_run(expected_output).in_color(
139
+ color_enabled
140
+ )
141
+ end
142
+ end
143
+ end
144
+
145
+ context "when comparing Date instance and date-like DateTime instance for another day",
146
+ active_record: true do
147
+ it "produces the diff for date like objects comparison" do
148
+ as_both_colored_and_uncolored do |color_enabled|
149
+ snippet = <<~RUBY
150
+ actual = Date.new(2023, 10, 14)
151
+ expected = DateTime.new(2023, 10, 31, 18, 22, 26)
152
+ expect(actual).to eq(expected)
153
+ RUBY
154
+ program =
155
+ make_rspec_rails_test_program(snippet, color_enabled: color_enabled)
156
+
157
+ expected_output =
158
+ build_expected_output(
159
+ color_enabled: color_enabled,
160
+ snippet: "expect(actual).to eq(expected)",
161
+ expectation:
162
+ proc do
163
+ line do
164
+ plain "Expected "
165
+ actual "#<Date 2023-10-14>"
166
+ plain " to eq "
167
+ expected "#<DateTime 2023-10-31 18:22:26 +00:00 (+00:00)>"
168
+ plain "."
169
+ end
170
+ end,
171
+ diff:
172
+ proc do
173
+ plain_line " #<Date {"
174
+ plain_line " year: 2023,"
175
+ plain_line " month: 10,"
176
+ expected_line "- day: 31"
177
+ actual_line "+ day: 14"
178
+ plain_line " }>"
179
+ end
180
+ )
181
+
182
+ expect(program).to produce_output_when_run(expected_output).in_color(
183
+ color_enabled
184
+ )
185
+ end
186
+ end
187
+ end
67
188
  end