super_diff 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +65 -26
  3. data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -2
  4. data/lib/super_diff/active_record/differs.rb +1 -1
  5. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +22 -18
  6. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +14 -7
  7. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +2 -2
  8. data/lib/super_diff/active_record/object_inspection.rb +1 -1
  9. data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +1 -2
  10. data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -2
  11. data/lib/super_diff/active_record/operation_tree_builders.rb +2 -2
  12. data/lib/super_diff/active_record/operation_tree_flatteners.rb +1 -1
  13. data/lib/super_diff/active_record/operation_trees.rb +1 -1
  14. data/lib/super_diff/active_record.rb +7 -15
  15. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +5 -6
  16. data/lib/super_diff/active_support/differs.rb +1 -1
  17. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +20 -11
  18. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +46 -0
  19. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +5 -1
  20. data/lib/super_diff/active_support/object_inspection.rb +1 -1
  21. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
  22. data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
  23. data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
  24. data/lib/super_diff/active_support/operation_trees.rb +1 -1
  25. data/lib/super_diff/active_support.rb +6 -10
  26. data/lib/super_diff/colorized_document_extensions.rb +2 -4
  27. data/lib/super_diff/configuration.rb +14 -8
  28. data/lib/super_diff/csi/color.rb +4 -4
  29. data/lib/super_diff/csi/colorized_document.rb +12 -16
  30. data/lib/super_diff/csi/document.rb +8 -19
  31. data/lib/super_diff/csi/eight_bit_color.rb +19 -19
  32. data/lib/super_diff/csi/four_bit_color.rb +82 -31
  33. data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
  34. data/lib/super_diff/csi/uncolorized_document.rb +2 -6
  35. data/lib/super_diff/csi.rb +10 -14
  36. data/lib/super_diff/diff_formatters/collection.rb +35 -41
  37. data/lib/super_diff/differs/date_like.rb +15 -0
  38. data/lib/super_diff/differs/default_object.rb +1 -1
  39. data/lib/super_diff/differs/defaults.rb +2 -1
  40. data/lib/super_diff/differs/main.rb +2 -13
  41. data/lib/super_diff/differs.rb +1 -0
  42. data/lib/super_diff/equality_matchers/array.rb +10 -12
  43. data/lib/super_diff/equality_matchers/base.rb +1 -1
  44. data/lib/super_diff/equality_matchers/default.rb +2 -4
  45. data/lib/super_diff/equality_matchers/defaults.rb +1 -1
  46. data/lib/super_diff/equality_matchers/hash.rb +10 -12
  47. data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
  48. data/lib/super_diff/equality_matchers/primitive.rb +10 -12
  49. data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
  50. data/lib/super_diff/equality_matchers.rb +1 -1
  51. data/lib/super_diff/errors.rb +2 -6
  52. data/lib/super_diff/gem_version.rb +3 -3
  53. data/lib/super_diff/helpers.rb +10 -10
  54. data/lib/super_diff/implementation_checks.rb +2 -2
  55. data/lib/super_diff/line.rb +3 -3
  56. data/lib/super_diff/object_inspection/inspection_tree.rb +64 -73
  57. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +29 -14
  58. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +17 -13
  59. data/lib/super_diff/object_inspection/inspection_tree_builders/date_like.rb +51 -0
  60. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +43 -27
  61. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +2 -1
  62. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +35 -18
  63. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +3 -5
  64. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +30 -36
  65. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +13 -9
  66. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +11 -22
  67. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
  68. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
  69. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
  70. data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
  71. data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
  72. data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
  73. data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
  74. data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
  75. data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
  76. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
  77. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
  78. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
  79. data/lib/super_diff/object_inspection/nodes.rb +7 -7
  80. data/lib/super_diff/object_inspection.rb +3 -3
  81. data/lib/super_diff/operation_tree_builders/array.rb +12 -11
  82. data/lib/super_diff/operation_tree_builders/base.rb +17 -15
  83. data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
  84. data/lib/super_diff/operation_tree_builders/date_like.rb +15 -0
  85. data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
  86. data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
  87. data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
  88. data/lib/super_diff/operation_tree_builders/main.rb +4 -11
  89. data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
  90. data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
  91. data/lib/super_diff/operation_tree_builders.rb +2 -1
  92. data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
  93. data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
  94. data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
  95. data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
  96. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
  97. data/lib/super_diff/operation_tree_flatteners.rb +3 -3
  98. data/lib/super_diff/operation_trees/base.rb +3 -5
  99. data/lib/super_diff/operation_trees/default_object.rb +1 -3
  100. data/lib/super_diff/operations/binary_operation.rb +2 -2
  101. data/lib/super_diff/operations/unary_operation.rb +1 -1
  102. data/lib/super_diff/rails.rb +2 -1
  103. data/lib/super_diff/recursion_guard.rb +5 -4
  104. data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
  105. data/lib/super_diff/rspec/differ.rb +6 -13
  106. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
  107. data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
  108. data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
  109. data/lib/super_diff/rspec/differs.rb +3 -3
  110. data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
  111. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
  112. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
  113. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +2 -10
  114. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
  115. data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
  116. data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
  117. data/lib/super_diff/rspec/monkey_patches.rb +180 -123
  118. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +14 -7
  119. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +21 -13
  120. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +35 -36
  121. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +19 -0
  122. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +21 -15
  123. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +11 -10
  124. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +11 -10
  125. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +14 -7
  126. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +10 -11
  127. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +13 -9
  128. data/lib/super_diff/rspec/object_inspection.rb +1 -1
  129. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
  130. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
  131. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
  132. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
  133. data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
  134. data/lib/super_diff/rspec.rb +17 -18
  135. data/lib/super_diff/tiered_lines_elider.rb +87 -115
  136. data/lib/super_diff/tiered_lines_formatter.rb +5 -9
  137. data/lib/super_diff/version.rb +1 -1
  138. data/lib/super_diff.rb +13 -9
  139. data/spec/examples.txt +541 -483
  140. data/spec/integration/rails/active_record_spec.rb +3 -1
  141. data/spec/integration/rails/engines_spec.rb +25 -0
  142. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
  143. data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
  144. data/spec/integration/rspec/be_matcher_spec.rb +360 -320
  145. data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
  146. data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
  147. data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
  148. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +257 -254
  149. data/spec/integration/rspec/eq_matcher_spec.rb +695 -585
  150. data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
  151. data/spec/integration/rspec/have_attributes_matcher_spec.rb +312 -304
  152. data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
  153. data/spec/integration/rspec/include_matcher_spec.rb +327 -225
  154. data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
  155. data/spec/integration/rspec/match_array_matcher_spec.rb +294 -291
  156. data/spec/integration/rspec/match_matcher_spec.rb +916 -903
  157. data/spec/integration/rspec/raise_error_matcher_spec.rb +1208 -449
  158. data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
  159. data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
  160. data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
  161. data/spec/internal/log/test.log +0 -0
  162. data/spec/spec_helper.rb +20 -20
  163. data/spec/support/command_runner.rb +34 -57
  164. data/spec/support/integration/helpers.rb +44 -32
  165. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
  166. data/spec/support/integration/matchers.rb +34 -0
  167. data/spec/support/integration/test_programs/base.rb +17 -22
  168. data/spec/support/integration/test_programs/plain.rb +6 -0
  169. data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
  170. data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
  171. data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
  172. data/spec/support/integration/test_programs/rspec_rails_engine.rb +20 -0
  173. data/spec/support/models/active_record/person.rb +6 -4
  174. data/spec/support/models/active_record/shipping_address.rb +9 -10
  175. data/spec/support/models/customer.rb +2 -4
  176. data/spec/support/models/player.rb +3 -6
  177. data/spec/support/models/shipping_address.rb +4 -13
  178. data/spec/support/shared_examples/active_record.rb +258 -240
  179. data/spec/support/shared_examples/active_support.rb +174 -51
  180. data/spec/support/shared_examples/elided_diffs.rb +447 -423
  181. data/spec/support/shared_examples/hash_with_indifferent_access.rb +500 -464
  182. data/spec/support/shared_examples/key.rb +123 -0
  183. data/spec/support/unit/helpers.rb +1 -3
  184. data/spec/support/unit/matchers/match_output.rb +12 -13
  185. data/spec/unit/active_record/object_inspection_spec.rb +222 -206
  186. data/spec/unit/active_support/object_inspection_spec.rb +170 -0
  187. data/spec/unit/equality_matchers/main_spec.rb +1049 -984
  188. data/spec/unit/helpers_spec.rb +14 -21
  189. data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
  190. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
  191. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
  192. data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
  193. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
  194. data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
  195. data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
  196. data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
  197. data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
  198. data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
  199. data/spec/unit/rspec/matchers/include_spec.rb +2 -2
  200. data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
  201. data/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
  202. data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
  203. data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
  204. data/spec/unit/rspec/object_inspection_spec.rb +351 -326
  205. data/spec/unit/super_diff_spec.rb +1594 -1437
  206. data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
  207. data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
  208. data/super_diff.gemspec +13 -12
  209. metadata +88 -75
  210. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +0 -21
  211. data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +0 -22
  212. data/spec/tmp/warnings_logger/all_warnings.txt +0 -2
@@ -12,110 +12,120 @@ RSpec.describe SuperDiff::OperationTreeFlatteners::MultilineString do
12
12
  context "given a tree of only noops" do
13
13
  it "returns a series of lines from printing each value" do
14
14
  collection = Array.new(3) { :some_value }
15
- operation_tree = SuperDiff::OperationTrees::MultilineString.new([
16
- double(
17
- :operation,
18
- name: :noop,
19
- collection: collection,
20
- value: "This is a line\n",
21
- index: 0,
22
- ),
23
- double(
24
- :operation,
25
- name: :noop,
26
- collection: collection,
27
- value: "This is another line\n",
28
- index: 1,
29
- ),
30
- double(
31
- :operation,
32
- name: :noop,
33
- collection: collection,
34
- value: "This is yet another line",
35
- index: 2,
36
- ),
37
- ])
15
+ operation_tree =
16
+ SuperDiff::OperationTrees::MultilineString.new(
17
+ [
18
+ double(
19
+ :operation,
20
+ name: :noop,
21
+ collection: collection,
22
+ value: "This is a line\n",
23
+ index: 0
24
+ ),
25
+ double(
26
+ :operation,
27
+ name: :noop,
28
+ collection: collection,
29
+ value: "This is another line\n",
30
+ index: 1
31
+ ),
32
+ double(
33
+ :operation,
34
+ name: :noop,
35
+ collection: collection,
36
+ value: "This is yet another line",
37
+ index: 2
38
+ )
39
+ ]
40
+ )
38
41
 
39
42
  flattened_operation_tree = described_class.call(operation_tree)
40
43
 
41
- expect(flattened_operation_tree).to match([
42
- an_object_having_attributes(
43
- type: :noop,
44
- indentation_level: 0,
45
- prefix: "",
46
- value: %(This is a line\\n),
47
- add_comma: false,
48
- ),
49
- an_object_having_attributes(
50
- type: :noop,
51
- indentation_level: 0,
52
- prefix: "",
53
- value: %(This is another line\\n),
54
- add_comma: false,
55
- ),
56
- an_object_having_attributes(
57
- type: :noop,
58
- indentation_level: 0,
59
- prefix: "",
60
- value: %(This is yet another line),
61
- add_comma: false,
62
- ),
63
- ])
44
+ expect(flattened_operation_tree).to match(
45
+ [
46
+ an_object_having_attributes(
47
+ type: :noop,
48
+ indentation_level: 0,
49
+ prefix: "",
50
+ value: %(This is a line\\n),
51
+ add_comma: false
52
+ ),
53
+ an_object_having_attributes(
54
+ type: :noop,
55
+ indentation_level: 0,
56
+ prefix: "",
57
+ value: %(This is another line\\n),
58
+ add_comma: false
59
+ ),
60
+ an_object_having_attributes(
61
+ type: :noop,
62
+ indentation_level: 0,
63
+ prefix: "",
64
+ value: "This is yet another line",
65
+ add_comma: false
66
+ )
67
+ ]
68
+ )
64
69
  end
65
70
  end
66
71
 
67
72
  context "given a tree of noops, inserts, and deletes" do
68
73
  it "returns a series of lines from printing each value" do
69
74
  collection = Array.new(3) { :some_value }
70
- operation_tree = SuperDiff::OperationTrees::MultilineString.new([
71
- double(
72
- :operation,
73
- name: :noop,
74
- collection: collection,
75
- value: "This is a line\n",
76
- index: 0,
77
- ),
78
- double(
79
- :operation,
80
- name: :delete,
81
- collection: collection,
82
- value: "This is another line\n",
83
- index: 1,
84
- ),
85
- double(
86
- :operation,
87
- name: :insert,
88
- collection: collection,
89
- value: "This is yet another line",
90
- index: 1,
91
- ),
92
- ])
75
+ operation_tree =
76
+ SuperDiff::OperationTrees::MultilineString.new(
77
+ [
78
+ double(
79
+ :operation,
80
+ name: :noop,
81
+ collection: collection,
82
+ value: "This is a line\n",
83
+ index: 0
84
+ ),
85
+ double(
86
+ :operation,
87
+ name: :delete,
88
+ collection: collection,
89
+ value: "This is another line\n",
90
+ index: 1
91
+ ),
92
+ double(
93
+ :operation,
94
+ name: :insert,
95
+ collection: collection,
96
+ value: "This is yet another line",
97
+ index: 1
98
+ )
99
+ ]
100
+ )
93
101
 
94
102
  flattened_operation_tree = described_class.call(operation_tree)
95
103
 
96
- expect(flattened_operation_tree).to match([
97
- an_object_having_attributes(
98
- type: :noop,
99
- indentation_level: 0,
100
- prefix: "",
101
- value: %(This is a line\\n),
102
- add_comma: false,
103
- ),
104
- an_object_having_attributes(
105
- type: :delete,
106
- indentation_level: 0,
107
- prefix: "",
108
- value: %(This is another line\\n),
109
- add_comma: false,
110
- ),
111
- an_object_having_attributes(
112
- type: :insert,
113
- indentation_level: 0,
114
- prefix: "",
115
- value: %(This is yet another line),
116
- add_comma: false,
117
- ),
118
- ])
104
+ expect(flattened_operation_tree).to match(
105
+ [
106
+ an_object_having_attributes(
107
+ type: :noop,
108
+ indentation_level: 0,
109
+ prefix: "",
110
+ value: %(This is a line\\n),
111
+ add_comma: false
112
+ ),
113
+ an_object_having_attributes(
114
+ type: :delete,
115
+ indentation_level: 0,
116
+ prefix: "",
117
+ value: %(This is another line\\n),
118
+ add_comma: false
119
+ ),
120
+ an_object_having_attributes(
121
+ type: :insert,
122
+ indentation_level: 0,
123
+ prefix: "",
124
+ value: "This is yet another line",
125
+ add_comma: false
126
+ )
127
+ ]
128
+ )
119
129
  end
120
130
  end
121
131
  end
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  RSpec.describe "RSpec's `be` matcher used with an operator" do
4
4
  describe "#description" do
5
- [:==, :===, :=~].each do |operator|
5
+ %i[== === =~].each do |operator|
6
6
  context "when the operator is #{operator}" do
7
7
  it "returns the correct output" do
8
8
  expect(be.public_send(operator, 2).description).to eq("#{operator} 2")
@@ -10,11 +10,11 @@ RSpec.describe "RSpec's `be` matcher used with an operator" do
10
10
  end
11
11
  end
12
12
 
13
- [:<, :<=, :>=, :>].each do |operator|
13
+ %i[< <= >= >].each do |operator|
14
14
  context "when the operator is #{operator}" do
15
15
  it "returns the correct output" do
16
16
  expect(be.public_send(operator, 2).description).to eq(
17
- "be #{operator} 2",
17
+ "be #{operator} 2"
18
18
  )
19
19
  end
20
20
  end
@@ -4,7 +4,7 @@ RSpec.describe "RSpec's `be_<predicate>` matcher" do
4
4
  describe "#description" do
5
5
  it "returns the correct output" do
6
6
  expect(be_famous.description).to eq(
7
- "return true for `famous?` or `famouss?`",
7
+ "return true for `famous?` or `famouss?`"
8
8
  )
9
9
  end
10
10
  end
@@ -14,7 +14,7 @@ RSpec.describe "RSpec's `be_a_<predicate>` matcher" do
14
14
  describe "#description" do
15
15
  it "returns the correct output" do
16
16
  expect(be_a_big_big_star.description).to eq(
17
- "return true for `big_big_star?` or `big_big_stars?`",
17
+ "return true for `big_big_star?` or `big_big_stars?`"
18
18
  )
19
19
  end
20
20
  end
@@ -24,7 +24,7 @@ RSpec.describe "RSpec's `be_an_<predicate>` matcher" do
24
24
  describe "#description" do
25
25
  it "returns the correct output" do
26
26
  expect(be_an_open_book.description).to eq(
27
- "return true for `open_book?` or `open_books?`",
27
+ "return true for `open_book?` or `open_books?`"
28
28
  )
29
29
  end
30
30
  end
@@ -4,7 +4,7 @@ RSpec.describe "RSpec's `contain_exactly` matcher" do
4
4
  describe "#description" do
5
5
  it "returns the correct output" do
6
6
  expect(contain_exactly(:foo, :bar, :baz).description).to eq(
7
- "contain exactly :foo, :bar and :baz",
7
+ "contain exactly :foo, :bar and :baz"
8
8
  )
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ RSpec.describe "RSpec's `have_attributes` matcher" do
4
4
  describe "#description" do
5
5
  it "returns the correct output" do
6
6
  expect(have_attributes(foo: "bar", baz: "qux").description).to eq(
7
- %|have attributes (foo: "bar", baz: "qux")|,
7
+ %|have attributes (foo: "bar", baz: "qux")|
8
8
  )
9
9
  end
10
10
  end
@@ -5,7 +5,7 @@ RSpec.describe "RSpec's `have_<predicate>` matcher" do
5
5
  context "given nothing" do
6
6
  it "returns the correct output" do
7
7
  expect(have_experience.description).to eq(
8
- "return true for `has_experience?`",
8
+ "return true for `has_experience?`"
9
9
  )
10
10
  end
11
11
  end
@@ -13,7 +13,7 @@ RSpec.describe "RSpec's `have_<predicate>` matcher" do
13
13
  context "given an argument" do
14
14
  it "returns the correct output" do
15
15
  expect(have_ingredients(:sugar).description).to eq(
16
- "return true for `has_ingredients?(:sugar)`",
16
+ "return true for `has_ingredients?(:sugar)`"
17
17
  )
18
18
  end
19
19
  end
@@ -5,7 +5,7 @@ RSpec.describe "RSpec's `include` matcher" do
5
5
  context "given a list of items" do
6
6
  it "returns the correct output" do
7
7
  expect(include(:foo, :bar, :baz).description).to eq(
8
- "include :foo, :bar, and :baz",
8
+ "include :foo, :bar, and :baz"
9
9
  )
10
10
  end
11
11
  end
@@ -13,7 +13,7 @@ RSpec.describe "RSpec's `include` matcher" do
13
13
  context "given a hash" do
14
14
  it "returns the correct output" do
15
15
  expect(include(foo: "bar", baz: "qux").description).to eq(
16
- 'include (foo: "bar", baz: "qux")',
16
+ 'include (foo: "bar", baz: "qux")'
17
17
  )
18
18
  end
19
19
  end
@@ -3,8 +3,8 @@ require "spec_helper"
3
3
  RSpec.describe "RSpec's `match_array` matcher" do
4
4
  describe "#description" do
5
5
  it "returns the correct output" do
6
- expect(match_array([:foo, :bar, :baz]).description).to eq(
7
- "match array with :foo, :bar and :baz",
6
+ expect(match_array(%i[foo bar baz]).description).to eq(
7
+ "match array with :foo, :bar and :baz"
8
8
  )
9
9
  end
10
10
  end
@@ -5,39 +5,71 @@ RSpec.describe "RSpec's `raise_error` matcher" do
5
5
  context "given only an exception class" do
6
6
  it "returns the correct output" do
7
7
  expect(raise_error(RuntimeError).description).to eq(
8
- %|raise error #<RuntimeError>|,
8
+ "raise a kind of RuntimeError"
9
9
  )
10
10
  end
11
11
  end
12
12
 
13
- context "with only a message (and assuming a RuntimeError)" do
13
+ context "given only a string message" do
14
14
  it "returns the correct output" do
15
15
  expect(raise_error("hell").description).to eq(
16
- %|raise error #<Exception "hell">|,
16
+ %|raise a kind of Exception with message "hell"|
17
17
  )
18
18
  end
19
19
  end
20
20
 
21
- context "with regular expression as message (and assuming a RuntimeError)" do
21
+ context "given only a regexp message" do
22
22
  it "returns the correct output" do
23
- expect(raise_error(/hell/).description).to eq(
24
- %|raise error #<Exception /hell/>|,
23
+ expect(raise_error(/hell/i).description).to eq(
24
+ "raise a kind of Exception with message matching /hell/i"
25
25
  )
26
26
  end
27
27
  end
28
28
 
29
- context "with both an exception and a message" do
29
+ context "given both an exception and string message" do
30
30
  it "returns the correct output" do
31
31
  expect(raise_error(RuntimeError, "hell").description).to eq(
32
- %|raise error #<RuntimeError "hell">|,
32
+ %|raise a kind of RuntimeError with message "hell"|
33
33
  )
34
34
  end
35
35
  end
36
36
 
37
- context "with an exception and a regular expression as message" do
37
+ context "given both an exception and regexp message" do
38
38
  it "returns the correct output" do
39
- expect(raise_error(RuntimeError, /hell/).description).to eq(
40
- %|raise error #<RuntimeError /hell/>|,
39
+ expect(raise_error(RuntimeError, /hell/i).description).to eq(
40
+ "raise a kind of RuntimeError with message matching /hell/i"
41
+ )
42
+ end
43
+ end
44
+
45
+ context "given a simple RSpec matcher" do
46
+ it "returns the correct output" do
47
+ expect(raise_error(a_kind_of(RuntimeError)).description).to eq(
48
+ "raise #<a kind of RuntimeError>"
49
+ )
50
+ end
51
+ end
52
+
53
+ context "given a simple RSpec matcher and string message" do
54
+ it "returns the correct output" do
55
+ expect(raise_error(a_kind_of(RuntimeError), "boo").description).to eq(
56
+ 'raise #<a kind of RuntimeError> with message "boo"'
57
+ )
58
+ end
59
+ end
60
+
61
+ context "given a simple RSpec matcher and regexp message" do
62
+ it "returns the correct output" do
63
+ expect(raise_error(a_kind_of(RuntimeError), /boo/i).description).to eq(
64
+ "raise #<a kind of RuntimeError> with message matching /boo/i"
65
+ )
66
+ end
67
+ end
68
+
69
+ context "given a compound RSpec matcher" do
70
+ it "returns the correct output" do
71
+ expect(raise_error(a_kind_of(Array).or eq(true)).description).to eq(
72
+ "raise #<a kind of Array or eq true>"
41
73
  )
42
74
  end
43
75
  end
@@ -5,26 +5,27 @@ RSpec.describe "RSpec's `respond_to` matcher" do
5
5
  context "without any qualifiers" do
6
6
  it "returns the correct output" do
7
7
  expect(respond_to(:foo, :bar, :baz).description).to eq(
8
- "respond to :foo, :bar and :baz",
8
+ "respond to :foo, :bar and :baz"
9
9
  )
10
10
  end
11
11
  end
12
12
 
13
13
  context "qualified with #with + #arguments" do
14
14
  it "returns the correct output" do
15
- expect(respond_to(:foo, :bar, :baz).with(3).arguments.description).
16
- to eq("respond to :foo, :bar and :baz with 3 arguments")
15
+ expect(
16
+ respond_to(:foo, :bar, :baz).with(3).arguments.description
17
+ ).to eq("respond to :foo, :bar and :baz with 3 arguments")
17
18
  end
18
19
  end
19
20
 
20
21
  context "qualified with #with_keywords" do
21
22
  it "returns the correct output" do
22
- matcher = respond_to(:foo, :bar, :baz).
23
- with_keywords(:qux, :blargh, :fizz)
23
+ matcher =
24
+ respond_to(:foo, :bar, :baz).with_keywords(:qux, :blargh, :fizz)
24
25
 
25
26
  expect(matcher.description).to eq(
26
27
  "respond to :foo, :bar and :baz with keywords :qux, :blargh " +
27
- "and :fizz",
28
+ "and :fizz"
28
29
  )
29
30
  end
30
31
  end
@@ -34,7 +35,7 @@ RSpec.describe "RSpec's `respond_to` matcher" do
34
35
  matcher = respond_to(:foo, :bar, :baz).with_any_keywords
35
36
 
36
37
  expect(matcher.description).to eq(
37
- "respond to :foo, :bar and :baz with any keywords",
38
+ "respond to :foo, :bar and :baz with any keywords"
38
39
  )
39
40
  end
40
41
  end
@@ -44,33 +45,39 @@ RSpec.describe "RSpec's `respond_to` matcher" do
44
45
  matcher = respond_to(:foo, :bar, :baz).with_unlimited_arguments
45
46
 
46
47
  expect(matcher.description).to eq(
47
- "respond to :foo, :bar and :baz with unlimited arguments",
48
+ "respond to :foo, :bar and :baz with unlimited arguments"
48
49
  )
49
50
  end
50
51
  end
51
52
 
52
53
  context "qualified with #with_any_keywords + #with_unlimited_arguments" do
53
54
  it "returns the correct output" do
54
- matcher = respond_to(:foo, :bar, :baz).
55
- with_any_keywords.
56
- with_unlimited_arguments
55
+ matcher =
56
+ respond_to(
57
+ :foo,
58
+ :bar,
59
+ :baz
60
+ ).with_any_keywords.with_unlimited_arguments
57
61
 
58
62
  expect(matcher.description).to eq(
59
63
  "respond to :foo, :bar and :baz with any keywords and unlimited " +
60
- "arguments",
64
+ "arguments"
61
65
  )
62
66
  end
63
67
  end
64
68
 
65
69
  context "qualified with #with_keywords + #with_unlimited_arguments" do
66
70
  it "returns the correct output" do
67
- matcher = respond_to(:foo, :bar, :baz).
68
- with_keywords(:qux, :blargh, :fizz).
69
- with_unlimited_arguments
71
+ matcher =
72
+ respond_to(:foo, :bar, :baz).with_keywords(
73
+ :qux,
74
+ :blargh,
75
+ :fizz
76
+ ).with_unlimited_arguments
70
77
 
71
78
  expect(matcher.description).to eq(
72
79
  "respond to :foo, :bar and :baz with keywords :qux, :blargh and " +
73
- ":fizz and unlimited arguments",
80
+ ":fizz and unlimited arguments"
74
81
  )
75
82
  end
76
83
  end
@@ -0,0 +1,91 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe SuperDiff, type: :unit do
4
+ describe ".inspect_object", "for RSpec matchers" do
5
+ context "given a custom matcher" do
6
+ let(:custom_matcher) do
7
+ proc do |expected, &block_arg|
8
+ declarations =
9
+ proc do
10
+ match do |actual|
11
+ actual.is_a?(Integer) && actual >= 0 &&
12
+ (Math.sqrt(actual) % 1).zero?
13
+ end
14
+ description { "be a perfect square" }
15
+ end
16
+ RSpec::Matchers::DSL::Matcher.new(
17
+ :be_a_square,
18
+ declarations,
19
+ RSpec::Matchers::DSL,
20
+ *expected,
21
+ &block_arg
22
+ )
23
+ end
24
+ end
25
+
26
+ context "given as_lines: false" do
27
+ it "returns the matcher's description string" do
28
+ string =
29
+ described_class.inspect_object(
30
+ custom_matcher.call(4),
31
+ as_lines: false
32
+ )
33
+ expect(string).to eq("#<be a perfect square>")
34
+ end
35
+ end
36
+
37
+ context "given as_lines: true" do
38
+ it "returns an inspected version of the matcher as multiple lines" do
39
+ tiered_lines =
40
+ described_class.inspect_object(
41
+ custom_matcher.call(4),
42
+ as_lines: true,
43
+ type: :delete,
44
+ indentation_level: 1
45
+ )
46
+ expect(tiered_lines).to match(
47
+ [
48
+ an_object_having_attributes(
49
+ type: :delete,
50
+ indentation_level: 1,
51
+ value: "#<be a perfect square>"
52
+ )
53
+ ]
54
+ )
55
+ end
56
+ end
57
+ end
58
+
59
+ context "given a built-in matcher" do
60
+ let(:matcher) { be_a(Numeric) }
61
+
62
+ context "given as_lines: false" do
63
+ it "returns the matcher's description string" do
64
+ string = described_class.inspect_object(matcher, as_lines: false)
65
+ expect(string).to eq("#<be a kind of Numeric>")
66
+ end
67
+ end
68
+
69
+ context "given as_lines: true" do
70
+ it "returns an inspected version of the matcher as multiple lines" do
71
+ tiered_lines =
72
+ described_class.inspect_object(
73
+ matcher,
74
+ as_lines: true,
75
+ type: :delete,
76
+ indentation_level: 1
77
+ )
78
+ expect(tiered_lines).to match(
79
+ [
80
+ an_object_having_attributes(
81
+ type: :delete,
82
+ indentation_level: 1,
83
+ value: "#<be a kind of Numeric>"
84
+ )
85
+ ]
86
+ )
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end