super_diff 0.2.0 → 0.5.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 (187) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +108 -74
  3. data/lib/super_diff.rb +20 -11
  4. data/lib/super_diff/active_record.rb +21 -23
  5. data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +3 -3
  6. data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -5
  7. data/lib/super_diff/active_record/monkey_patches.rb +9 -0
  8. data/lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb +32 -22
  9. data/lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb +17 -7
  10. data/lib/super_diff/active_record/operation_tree_builders.rb +14 -0
  11. data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_model.rb +2 -2
  12. data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_relation.rb +4 -4
  13. data/lib/super_diff/active_record/{operation_sequences.rb → operation_trees.rb} +2 -2
  14. data/lib/super_diff/active_record/{operation_sequences → operation_trees}/active_record_relation.rb +2 -2
  15. data/lib/super_diff/active_support.rb +16 -19
  16. data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +3 -3
  17. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -5
  18. data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +17 -7
  19. data/lib/super_diff/active_support/operation_tree_builders.rb +10 -0
  20. data/lib/super_diff/active_support/{operational_sequencers → operation_tree_builders}/hash_with_indifferent_access.rb +2 -2
  21. data/lib/super_diff/active_support/{operation_sequences.rb → operation_trees.rb} +2 -2
  22. data/lib/super_diff/active_support/{operation_sequences → operation_trees}/hash_with_indifferent_access.rb +2 -2
  23. data/lib/super_diff/configuration.rb +60 -0
  24. data/lib/super_diff/csi.rb +4 -0
  25. data/lib/super_diff/diff_formatters.rb +3 -3
  26. data/lib/super_diff/diff_formatters/array.rb +3 -3
  27. data/lib/super_diff/diff_formatters/base.rb +3 -2
  28. data/lib/super_diff/diff_formatters/collection.rb +2 -2
  29. data/lib/super_diff/diff_formatters/custom_object.rb +3 -3
  30. data/lib/super_diff/diff_formatters/default_object.rb +6 -8
  31. data/lib/super_diff/diff_formatters/defaults.rb +10 -0
  32. data/lib/super_diff/diff_formatters/hash.rb +3 -3
  33. data/lib/super_diff/diff_formatters/main.rb +41 -0
  34. data/lib/super_diff/diff_formatters/multiline_string.rb +3 -3
  35. data/lib/super_diff/differs.rb +4 -9
  36. data/lib/super_diff/differs/array.rb +2 -11
  37. data/lib/super_diff/differs/base.rb +20 -3
  38. data/lib/super_diff/differs/custom_object.rb +2 -11
  39. data/lib/super_diff/differs/default_object.rb +2 -8
  40. data/lib/super_diff/differs/defaults.rb +12 -0
  41. data/lib/super_diff/differs/hash.rb +2 -11
  42. data/lib/super_diff/differs/main.rb +48 -0
  43. data/lib/super_diff/differs/multiline_string.rb +2 -14
  44. data/lib/super_diff/differs/time_like.rb +15 -0
  45. data/lib/super_diff/equality_matchers.rb +3 -9
  46. data/lib/super_diff/equality_matchers/array.rb +1 -7
  47. data/lib/super_diff/equality_matchers/base.rb +1 -1
  48. data/lib/super_diff/equality_matchers/default.rb +2 -8
  49. data/lib/super_diff/equality_matchers/defaults.rb +12 -0
  50. data/lib/super_diff/equality_matchers/hash.rb +1 -7
  51. data/lib/super_diff/equality_matchers/main.rb +21 -0
  52. data/lib/super_diff/equality_matchers/multiline_string.rb +1 -7
  53. data/lib/super_diff/errors.rb +16 -0
  54. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +21 -0
  55. data/lib/super_diff/errors/no_differ_available_error.rb +24 -0
  56. data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +22 -0
  57. data/lib/super_diff/implementation_checks.rb +19 -0
  58. data/lib/super_diff/object_inspection.rb +1 -10
  59. data/lib/super_diff/object_inspection/inspection_tree.rb +6 -2
  60. data/lib/super_diff/object_inspection/inspectors.rb +5 -0
  61. data/lib/super_diff/object_inspection/inspectors/array.rb +20 -10
  62. data/lib/super_diff/object_inspection/inspectors/base.rb +36 -0
  63. data/lib/super_diff/object_inspection/inspectors/custom_object.rb +24 -14
  64. data/lib/super_diff/object_inspection/inspectors/default_object.rb +44 -30
  65. data/lib/super_diff/object_inspection/inspectors/defaults.rb +15 -0
  66. data/lib/super_diff/object_inspection/inspectors/hash.rb +20 -10
  67. data/lib/super_diff/object_inspection/inspectors/main.rb +35 -0
  68. data/lib/super_diff/object_inspection/inspectors/primitive.rb +20 -5
  69. data/lib/super_diff/object_inspection/inspectors/string.rb +15 -5
  70. data/lib/super_diff/object_inspection/inspectors/time_like.rb +23 -0
  71. data/lib/super_diff/object_inspection/nodes/inspection.rb +9 -2
  72. data/lib/super_diff/operation_tree_builders.rb +18 -0
  73. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/array.rb +38 -59
  74. data/lib/super_diff/operation_tree_builders/base.rb +98 -0
  75. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/custom_object.rb +3 -3
  76. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/default_object.rb +8 -3
  77. data/lib/super_diff/operation_tree_builders/defaults.rb +5 -0
  78. data/lib/super_diff/operation_tree_builders/hash.rb +226 -0
  79. data/lib/super_diff/operation_tree_builders/main.rb +42 -0
  80. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/multiline_string.rb +3 -3
  81. data/lib/super_diff/operation_tree_builders/time_like.rb +34 -0
  82. data/lib/super_diff/operation_trees.rb +13 -0
  83. data/lib/super_diff/{operation_sequences → operation_trees}/array.rb +5 -1
  84. data/lib/super_diff/operation_trees/base.rb +31 -0
  85. data/lib/super_diff/{operation_sequences → operation_trees}/custom_object.rb +5 -1
  86. data/lib/super_diff/{operation_sequences → operation_trees}/default_object.rb +10 -8
  87. data/lib/super_diff/operation_trees/defaults.rb +5 -0
  88. data/lib/super_diff/{operation_sequences → operation_trees}/hash.rb +5 -1
  89. data/lib/super_diff/operation_trees/main.rb +35 -0
  90. data/lib/super_diff/operation_trees/multiline_string.rb +18 -0
  91. data/lib/super_diff/operations/unary_operation.rb +3 -0
  92. data/lib/super_diff/rspec.rb +54 -22
  93. data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
  94. data/lib/super_diff/rspec/differ.rb +2 -17
  95. data/lib/super_diff/rspec/differs.rb +9 -3
  96. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -8
  97. data/lib/super_diff/rspec/differs/collection_including.rb +18 -0
  98. data/lib/super_diff/rspec/differs/hash_including.rb +18 -0
  99. data/lib/super_diff/rspec/differs/object_having_attributes.rb +17 -0
  100. data/lib/super_diff/rspec/matcher_text_builders.rb +4 -0
  101. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +26 -7
  102. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +61 -0
  103. data/lib/super_diff/rspec/matcher_text_builders/match.rb +1 -1
  104. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +13 -1
  105. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +1 -1
  106. data/lib/super_diff/rspec/matcher_text_template.rb +1 -1
  107. data/lib/super_diff/rspec/monkey_patches.rb +226 -115
  108. data/lib/super_diff/rspec/object_inspection.rb +0 -1
  109. data/lib/super_diff/rspec/object_inspection/inspectors.rb +22 -6
  110. data/lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb +17 -8
  111. data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +28 -0
  112. data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +31 -0
  113. data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +23 -0
  114. data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +23 -0
  115. data/lib/super_diff/rspec/object_inspection/inspectors/object_having_attributes.rb +31 -0
  116. data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +13 -0
  117. data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +29 -0
  118. data/lib/super_diff/rspec/operation_tree_builders.rb +22 -0
  119. data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/collection_containing_exactly.rb +6 -6
  120. data/lib/super_diff/rspec/{operational_sequencers/partial_array.rb → operation_tree_builders/collection_including.rb} +4 -3
  121. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +25 -0
  122. data/lib/super_diff/rspec/{operational_sequencers/partial_object.rb → operation_tree_builders/object_having_attributes.rb} +5 -11
  123. data/lib/super_diff/version.rb +1 -1
  124. data/spec/examples.txt +397 -328
  125. data/spec/integration/rails/active_record_spec.rb +1 -1
  126. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +1 -1
  127. data/spec/integration/rspec/be_predicate_matcher_spec.rb +111 -59
  128. data/spec/integration/rspec/eq_matcher_spec.rb +139 -3
  129. data/spec/integration/rspec/have_attributes_matcher_spec.rb +354 -227
  130. data/spec/integration/rspec/have_predicate_matcher_spec.rb +484 -0
  131. data/spec/integration/rspec/include_matcher_spec.rb +2 -2
  132. data/spec/integration/rspec/match_array_matcher_spec.rb +372 -0
  133. data/spec/integration/rspec/match_matcher_spec.rb +8 -8
  134. data/spec/integration/rspec/raise_error_matcher_spec.rb +605 -226
  135. data/spec/integration/rspec/third_party_matcher_spec.rb +241 -0
  136. data/spec/integration/rspec/unhandled_errors_spec.rb +110 -58
  137. data/spec/spec_helper.rb +18 -7
  138. data/spec/support/command_runner.rb +3 -0
  139. data/spec/support/integration/helpers.rb +14 -90
  140. data/spec/support/integration/matchers.rb +143 -0
  141. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +14 -29
  142. data/spec/support/integration/test_programs/base.rb +120 -0
  143. data/spec/support/integration/test_programs/plain.rb +13 -0
  144. data/spec/support/integration/test_programs/rspec_active_record.rb +17 -0
  145. data/spec/support/integration/test_programs/rspec_rails.rb +17 -0
  146. data/spec/support/models/active_record/person.rb +4 -11
  147. data/spec/support/models/active_record/query.rb +15 -0
  148. data/spec/support/models/active_record/shipping_address.rb +10 -14
  149. data/spec/support/object_id.rb +27 -0
  150. data/spec/support/ruby_versions.rb +4 -0
  151. data/spec/support/shared_examples/active_record.rb +71 -0
  152. data/spec/support/shared_examples/hash_with_indifferent_access.rb +724 -208
  153. data/spec/tmp/integration_spec.rb +15 -0
  154. data/spec/unit/{equality_matcher_spec.rb → equality_matchers/main_spec.rb} +165 -9
  155. data/spec/unit/object_inspection_spec.rb +94 -18
  156. data/spec/unit/rspec/matchers/have_predicate_spec.rb +21 -0
  157. data/spec/unit/rspec/matchers/match_array_spec.rb +11 -0
  158. data/spec/unit/rspec/matchers/raise_error_spec.rb +16 -0
  159. data/super_diff.gemspec +3 -6
  160. metadata +99 -91
  161. data/lib/super_diff/active_record/object_inspection/map_extension.rb +0 -18
  162. data/lib/super_diff/active_record/operational_sequencers.rb +0 -14
  163. data/lib/super_diff/active_support/object_inspection/map_extension.rb +0 -15
  164. data/lib/super_diff/active_support/operational_sequencers.rb +0 -10
  165. data/lib/super_diff/diff_formatter.rb +0 -32
  166. data/lib/super_diff/differ.rb +0 -51
  167. data/lib/super_diff/equality_matcher.rb +0 -32
  168. data/lib/super_diff/no_differ_available_error.rb +0 -22
  169. data/lib/super_diff/no_operational_sequencer_available_error.rb +0 -20
  170. data/lib/super_diff/object_inspection/inspector.rb +0 -27
  171. data/lib/super_diff/object_inspection/map.rb +0 -28
  172. data/lib/super_diff/operation_sequences.rb +0 -9
  173. data/lib/super_diff/operation_sequences/base.rb +0 -11
  174. data/lib/super_diff/operational_sequencer.rb +0 -48
  175. data/lib/super_diff/operational_sequencers.rb +0 -16
  176. data/lib/super_diff/operational_sequencers/base.rb +0 -89
  177. data/lib/super_diff/operational_sequencers/hash.rb +0 -85
  178. data/lib/super_diff/rspec/configuration.rb +0 -31
  179. data/lib/super_diff/rspec/differs/partial_array.rb +0 -22
  180. data/lib/super_diff/rspec/differs/partial_hash.rb +0 -22
  181. data/lib/super_diff/rspec/differs/partial_object.rb +0 -22
  182. data/lib/super_diff/rspec/object_inspection/inspectors/partial_array.rb +0 -22
  183. data/lib/super_diff/rspec/object_inspection/inspectors/partial_hash.rb +0 -21
  184. data/lib/super_diff/rspec/object_inspection/inspectors/partial_object.rb +0 -21
  185. data/lib/super_diff/rspec/object_inspection/map_extension.rb +0 -23
  186. data/lib/super_diff/rspec/operational_sequencers.rb +0 -22
  187. data/lib/super_diff/rspec/operational_sequencers/partial_hash.rb +0 -32
@@ -0,0 +1,13 @@
1
+ module SuperDiff
2
+ module IntegrationTests
3
+ module TestPrograms
4
+ class Plain < Base
5
+ protected
6
+
7
+ def test_plan_command
8
+ "run_plain_test"
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module SuperDiff
2
+ module IntegrationTests
3
+ module TestPrograms
4
+ class RspecActiveRecord < Base
5
+ protected
6
+
7
+ def test_plan_prelude
8
+ "test_plan.boot_active_record"
9
+ end
10
+
11
+ def test_plan_command
12
+ "run_rspec_active_record_test"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module SuperDiff
2
+ module IntegrationTests
3
+ module TestPrograms
4
+ class RspecRails < Base
5
+ protected
6
+
7
+ def test_plan_prelude
8
+ "test_plan.boot_active_record"
9
+ end
10
+
11
+ def test_plan_command
12
+ "run_rspec_rails_test"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -9,18 +9,11 @@ module SuperDiff
9
9
  end
10
10
  end
11
11
 
12
- ActiveRecord::Base.connection.create_table(:people) do |t|
13
- t.string :name, null: false
14
- t.integer :age, null: false
15
- end
16
-
17
12
  RSpec.configure do |config|
18
13
  config.before do
19
- ActiveRecord::Base.connection.execute(
20
- "DELETE FROM people",
21
- )
22
- ActiveRecord::Base.connection.execute(
23
- "DELETE FROM sqlite_sequence WHERE name='people'",
24
- )
14
+ ActiveRecord::Base.connection.create_table(:people, force: true) do |t|
15
+ t.string :name, null: false
16
+ t.integer :age, null: false
17
+ end
25
18
  end
26
19
  end
@@ -0,0 +1,15 @@
1
+ module SuperDiff
2
+ module Test
3
+ module Models
4
+ module ActiveRecord
5
+ class Query
6
+ attr_reader :results
7
+
8
+ def initialize(results:)
9
+ @results = results
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -9,21 +9,17 @@ module SuperDiff
9
9
  end
10
10
  end
11
11
 
12
- ActiveRecord::Base.connection.create_table(:shipping_addresses) do |t|
13
- t.string :line_1, null: false, default: ""
14
- t.string :line_2, null: false, default: ""
15
- t.string :city, null: false, default: ""
16
- t.string :state, null: false, default: ""
17
- t.string :zip, null: false, default: ""
18
- end
19
-
20
12
  RSpec.configure do |config|
21
13
  config.before do
22
- ActiveRecord::Base.connection.execute(
23
- "DELETE FROM shipping_addresses",
24
- )
25
- ActiveRecord::Base.connection.execute(
26
- "DELETE FROM sqlite_sequence WHERE name='shipping_addresses'",
27
- )
14
+ ActiveRecord::Base.connection.create_table(
15
+ :shipping_addresses,
16
+ force: true,
17
+ ) do |t|
18
+ t.string :line_1, null: false, default: ""
19
+ t.string :line_2, null: false, default: ""
20
+ t.string :city, null: false, default: ""
21
+ t.string :state, null: false, default: ""
22
+ t.string :zip, null: false, default: ""
23
+ end
28
24
  end
29
25
  end
@@ -0,0 +1,27 @@
1
+ require "json"
2
+ require_relative "ruby_versions"
3
+
4
+ if !SuperDiff::Test.jruby? && SuperDiff::Test.version_match?(">= 2.7.0")
5
+ require "objspace"
6
+ end
7
+
8
+ module SuperDiff
9
+ module Test
10
+ if jruby?
11
+ def self.object_id_hex(object)
12
+ # Source: <https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/RubyBasicObject.java>
13
+ "0x%x" % object.hash
14
+ end
15
+ elsif version_match?(">= 2.7.0")
16
+ def self.object_id_hex(object)
17
+ # Sources: <https://bugs.ruby-lang.org/issues/15408> and <https://bugs.ruby-lang.org/issues/15626#Object-ID>
18
+ address = JSON.parse(ObjectSpace.dump(object))["address"]
19
+ "0x%016x" % Integer(address, 16)
20
+ end
21
+ else
22
+ def self.object_id_hex(object)
23
+ "0x%016x" % (object.object_id * 2)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -3,5 +3,9 @@ module SuperDiff
3
3
  def self.jruby?
4
4
  defined?(JRUBY_VERSION)
5
5
  end
6
+
7
+ def self.version_match?(version_string)
8
+ Gem::Requirement.new(version_string).satisfied_by?(Gem::Version.new(RUBY_VERSION))
9
+ end
6
10
  end
7
11
  end
@@ -335,4 +335,75 @@ shared_examples_for "integration with ActiveRecord" do
335
335
  end
336
336
  end
337
337
  end
338
+
339
+ describe "and RSpec's #match matcher" do
340
+ context "when the expected value includes an ActiveRecord object" do
341
+ it "produces the correct output" do
342
+ as_both_colored_and_uncolored do |color_enabled|
343
+ snippet = <<~TEST.strip
344
+ SuperDiff::Test::Models::ActiveRecord::Person.create!(
345
+ name: "Murphy",
346
+ age: 20
347
+ )
348
+
349
+ expected = [
350
+ an_object_having_attributes(
351
+ results: [
352
+ an_object_having_attributes(name: "John", age: 19)
353
+ ]
354
+ )
355
+ ]
356
+
357
+ actual = [
358
+ SuperDiff::Test::Models::ActiveRecord::Query.new(
359
+ results: SuperDiff::Test::Models::ActiveRecord::Person.all
360
+ )
361
+ ]
362
+
363
+ expect(actual).to match(expected)
364
+ TEST
365
+
366
+ program = make_program(snippet, color_enabled: color_enabled)
367
+
368
+ expected_output = build_expected_output(
369
+ color_enabled: color_enabled,
370
+ snippet: %|expect(actual).to match(expected)|,
371
+ newline_before_expectation: true,
372
+ expectation: proc {
373
+ line do
374
+ plain "Expected "
375
+ beta %|[#<SuperDiff::Test::Models::ActiveRecord::Query @results=#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person id: 1, name: "Murphy", age: 20>]>>]|
376
+ end
377
+
378
+ line do
379
+ plain "to match "
380
+ alpha %|[#<an object having attributes (results: [#<an object having attributes (name: "John", age: 19)>])>]|
381
+ end
382
+ },
383
+ diff: proc {
384
+ plain_line %| [|
385
+ plain_line %| #<SuperDiff::Test::Models::ActiveRecord::Query {|
386
+ plain_line %| @results=#<ActiveRecord::Relation [|
387
+ plain_line %| #<SuperDiff::Test::Models::ActiveRecord::Person {|
388
+ plain_line %| id: 1,|
389
+ # alpha_line %|- age: 19,| # TODO
390
+ alpha_line %|- age: 19|
391
+ beta_line %|+ age: 20,|
392
+ alpha_line %|- name: "John"|
393
+ beta_line %|+ name: "Murphy"|
394
+ plain_line %| }>|
395
+ plain_line %| ]>|
396
+ plain_line %| }>|
397
+ plain_line %| ]|
398
+ },
399
+ )
400
+
401
+ expect(program).
402
+ to produce_output_when_run(expected_output).
403
+ in_color(color_enabled).
404
+ removing_object_ids
405
+ end
406
+ end
407
+ end
408
+ end
338
409
  end
@@ -1,115 +1,373 @@
1
1
  shared_examples_for "integration with HashWithIndifferentAccess" do
2
2
  describe "and RSpec's #eq matcher" do
3
3
  context "when the actual value is a HashWithIndifferentAccess" do
4
- it "produces the correct output" do
5
- as_both_colored_and_uncolored do |color_enabled|
6
- snippet = <<~TEST.strip
7
- expected = {
8
- line_1: "123 Main St.",
9
- city: "Hill Valley",
10
- state: "CA",
11
- zip: "90382",
12
- }
13
- actual = HashWithIndifferentAccess.new({
14
- line_1: "456 Ponderosa Ct.",
15
- city: "Oakland",
16
- state: "CA",
17
- zip: "91234",
18
- })
19
- expect(actual).to eq(expected)
20
- TEST
21
- program = make_rspec_rails_test_program(
22
- snippet,
23
- color_enabled: color_enabled,
24
- )
25
-
26
- expected_output = build_expected_output(
27
- color_enabled: color_enabled,
28
- snippet: "expect(actual).to eq(expected)",
29
- expectation: proc {
30
- line do
31
- plain "Expected "
32
- beta %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
33
- end
34
-
35
- line do
36
- plain " to eq "
37
- alpha %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
38
- end
39
- },
40
- diff: proc {
41
- plain_line %| #<HashWithIndifferentAccess {|
42
- alpha_line %|- "line_1" => "123 Main St.",|
43
- beta_line %|+ "line_1" => "456 Ponderosa Ct.",|
44
- alpha_line %|- "city" => "Hill Valley",|
45
- beta_line %|+ "city" => "Oakland",|
46
- plain_line %| "state" => "CA",|
47
- alpha_line %|- "zip" => "90382"|
48
- beta_line %|+ "zip" => "91234"|
49
- plain_line %| }>|
50
- },
51
- )
52
-
53
- expect(program).
54
- to produce_output_when_run(expected_output).
55
- in_color(color_enabled)
4
+ context "and both hashes are one-dimensional" do
5
+ context "and the expected hash contains symbol keys" do
6
+ it "produces the correct output" do
7
+ as_both_colored_and_uncolored do |color_enabled|
8
+ snippet = <<~TEST.strip
9
+ expected = {
10
+ line_1: "123 Main St.",
11
+ city: "Hill Valley",
12
+ state: "CA",
13
+ zip: "90382",
14
+ }
15
+ actual = HashWithIndifferentAccess.new({
16
+ line_1: "456 Ponderosa Ct.",
17
+ city: "Oakland",
18
+ state: "CA",
19
+ zip: "91234",
20
+ })
21
+ expect(actual).to eq(expected)
22
+ TEST
23
+ program = make_rspec_rails_test_program(
24
+ snippet,
25
+ color_enabled: color_enabled,
26
+ )
27
+
28
+ expected_output = build_expected_output(
29
+ color_enabled: color_enabled,
30
+ snippet: "expect(actual).to eq(expected)",
31
+ expectation: proc {
32
+ line do
33
+ plain "Expected "
34
+ beta %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
35
+ end
36
+
37
+ line do
38
+ plain " to eq "
39
+ alpha %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
40
+ end
41
+ },
42
+ diff: proc {
43
+ plain_line %| #<HashWithIndifferentAccess {|
44
+ alpha_line %|- "line_1" => "123 Main St.",|
45
+ beta_line %|+ "line_1" => "456 Ponderosa Ct.",|
46
+ alpha_line %|- "city" => "Hill Valley",|
47
+ beta_line %|+ "city" => "Oakland",|
48
+ plain_line %| "state" => "CA",|
49
+ alpha_line %|- "zip" => "90382"|
50
+ beta_line %|+ "zip" => "91234"|
51
+ plain_line %| }>|
52
+ },
53
+ )
54
+
55
+ expect(program).
56
+ to produce_output_when_run(expected_output).
57
+ in_color(color_enabled)
58
+ end
59
+ end
60
+ end
61
+
62
+ context "and the expected hash contains string keys" do
63
+ it "produces the correct output" do
64
+ as_both_colored_and_uncolored do |color_enabled|
65
+ snippet = <<~TEST.strip
66
+ expected = {
67
+ "line_1" => "123 Main St.",
68
+ "city" => "Hill Valley",
69
+ "state" => "CA",
70
+ "zip" => "90382",
71
+ }
72
+ actual = HashWithIndifferentAccess.new({
73
+ line_1: "456 Ponderosa Ct.",
74
+ city: "Oakland",
75
+ state: "CA",
76
+ zip: "91234",
77
+ })
78
+ expect(actual).to eq(expected)
79
+ TEST
80
+ program = make_rspec_rails_test_program(
81
+ snippet,
82
+ color_enabled: color_enabled,
83
+ )
84
+
85
+ expected_output = build_expected_output(
86
+ color_enabled: color_enabled,
87
+ snippet: "expect(actual).to eq(expected)",
88
+ expectation: proc {
89
+ line do
90
+ plain "Expected "
91
+ beta %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
92
+ end
93
+
94
+ line do
95
+ plain " to eq "
96
+ alpha %|{ "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }|
97
+ end
98
+ },
99
+ diff: proc {
100
+ plain_line %| #<HashWithIndifferentAccess {|
101
+ alpha_line %|- "line_1" => "123 Main St.",|
102
+ beta_line %|+ "line_1" => "456 Ponderosa Ct.",|
103
+ alpha_line %|- "city" => "Hill Valley",|
104
+ beta_line %|+ "city" => "Oakland",|
105
+ plain_line %| "state" => "CA",|
106
+ alpha_line %|- "zip" => "90382"|
107
+ beta_line %|+ "zip" => "91234"|
108
+ plain_line %| }>|
109
+ },
110
+ )
111
+
112
+ expect(program).
113
+ to produce_output_when_run(expected_output).
114
+ in_color(color_enabled)
115
+ end
116
+ end
56
117
  end
57
118
  end
58
119
  end
59
120
 
60
121
  context "when the expected value is a HashWithIndifferentAccess" do
61
- it "produces the correct output" do
62
- as_both_colored_and_uncolored do |color_enabled|
63
- snippet = <<~TEST.strip
64
- expected = HashWithIndifferentAccess.new({
65
- line_1: "456 Ponderosa Ct.",
66
- city: "Oakland",
67
- state: "CA",
68
- zip: "91234",
69
- })
70
- actual = {
71
- line_1: "123 Main St.",
72
- city: "Hill Valley",
73
- state: "CA",
74
- zip: "90382",
75
- }
76
- expect(actual).to eq(expected)
77
- TEST
78
- program = make_rspec_rails_test_program(
79
- snippet,
80
- color_enabled: color_enabled,
81
- )
82
-
83
- expected_output = build_expected_output(
84
- color_enabled: color_enabled,
85
- snippet: "expect(actual).to eq(expected)",
86
- expectation: proc {
87
- line do
88
- plain "Expected "
89
- beta %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
90
- end
91
-
92
- line do
93
- plain " to eq "
94
- alpha %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
95
- end
96
- },
97
- diff: proc {
98
- plain_line %| #<HashWithIndifferentAccess {|
99
- alpha_line %|- "line_1" => "456 Ponderosa Ct.",|
100
- beta_line %|+ "line_1" => "123 Main St.",|
101
- alpha_line %|- "city" => "Oakland",|
102
- beta_line %|+ "city" => "Hill Valley",|
103
- plain_line %| "state" => "CA",|
104
- alpha_line %|- "zip" => "91234"|
105
- beta_line %|+ "zip" => "90382"|
106
- plain_line %| }>|
107
- },
108
- )
109
-
110
- expect(program).
111
- to produce_output_when_run(expected_output).
112
- in_color(color_enabled)
122
+ context "and both hashes are one-dimensional" do
123
+ context "and the actual hash contains symbol keys" do
124
+ it "produces the correct output" do
125
+ as_both_colored_and_uncolored do |color_enabled|
126
+ snippet = <<~TEST.strip
127
+ expected = HashWithIndifferentAccess.new({
128
+ line_1: "456 Ponderosa Ct.",
129
+ city: "Oakland",
130
+ state: "CA",
131
+ zip: "91234",
132
+ })
133
+ actual = {
134
+ line_1: "123 Main St.",
135
+ city: "Hill Valley",
136
+ state: "CA",
137
+ zip: "90382",
138
+ }
139
+ expect(actual).to eq(expected)
140
+ TEST
141
+ program = make_rspec_rails_test_program(
142
+ snippet,
143
+ color_enabled: color_enabled,
144
+ )
145
+
146
+ expected_output = build_expected_output(
147
+ color_enabled: color_enabled,
148
+ snippet: "expect(actual).to eq(expected)",
149
+ expectation: proc {
150
+ line do
151
+ plain "Expected "
152
+ beta %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
153
+ end
154
+
155
+ line do
156
+ plain " to eq "
157
+ alpha %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
158
+ end
159
+ },
160
+ diff: proc {
161
+ plain_line %| #<HashWithIndifferentAccess {|
162
+ alpha_line %|- "line_1" => "456 Ponderosa Ct.",|
163
+ beta_line %|+ "line_1" => "123 Main St.",|
164
+ alpha_line %|- "city" => "Oakland",|
165
+ beta_line %|+ "city" => "Hill Valley",|
166
+ plain_line %| "state" => "CA",|
167
+ alpha_line %|- "zip" => "91234"|
168
+ beta_line %|+ "zip" => "90382"|
169
+ plain_line %| }>|
170
+ },
171
+ )
172
+
173
+ expect(program).
174
+ to produce_output_when_run(expected_output).
175
+ in_color(color_enabled)
176
+ end
177
+ end
178
+ end
179
+
180
+ context "and the actual hash contains string keys" do
181
+ it "produces the correct output" do
182
+ as_both_colored_and_uncolored do |color_enabled|
183
+ snippet = <<~TEST.strip
184
+ expected = HashWithIndifferentAccess.new({
185
+ line_1: "456 Ponderosa Ct.",
186
+ city: "Oakland",
187
+ state: "CA",
188
+ zip: "91234",
189
+ })
190
+ actual = {
191
+ "line_1" => "123 Main St.",
192
+ "city" => "Hill Valley",
193
+ "state" => "CA",
194
+ "zip" => "90382",
195
+ }
196
+ expect(actual).to eq(expected)
197
+ TEST
198
+ program = make_rspec_rails_test_program(
199
+ snippet,
200
+ color_enabled: color_enabled,
201
+ )
202
+
203
+ expected_output = build_expected_output(
204
+ color_enabled: color_enabled,
205
+ snippet: "expect(actual).to eq(expected)",
206
+ expectation: proc {
207
+ line do
208
+ plain "Expected "
209
+ beta %|{ "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }|
210
+ end
211
+
212
+ line do
213
+ plain " to eq "
214
+ alpha %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
215
+ end
216
+ },
217
+ diff: proc {
218
+ plain_line %| #<HashWithIndifferentAccess {|
219
+ alpha_line %|- "line_1" => "456 Ponderosa Ct.",|
220
+ beta_line %|+ "line_1" => "123 Main St.",|
221
+ alpha_line %|- "city" => "Oakland",|
222
+ beta_line %|+ "city" => "Hill Valley",|
223
+ plain_line %| "state" => "CA",|
224
+ alpha_line %|- "zip" => "91234"|
225
+ beta_line %|+ "zip" => "90382"|
226
+ plain_line %| }>|
227
+ },
228
+ )
229
+
230
+ expect(program).
231
+ to produce_output_when_run(expected_output).
232
+ in_color(color_enabled)
233
+ end
234
+ end
235
+ end
236
+ end
237
+
238
+ context "and both hashes are multi-dimensional" do
239
+ context "and the actual hash contains symbol keys" do
240
+ it "produces the correct output" do
241
+ as_both_colored_and_uncolored do |color_enabled|
242
+ snippet = <<~TEST.strip
243
+ expected = HashWithIndifferentAccess.new({
244
+ shipments: [
245
+ HashWithIndifferentAccess.new({
246
+ estimated_delivery: HashWithIndifferentAccess.new({
247
+ from: '2019-05-06',
248
+ to: '2019-05-06'
249
+ })
250
+ })
251
+ ]
252
+ })
253
+ actual = {
254
+ shipments: [
255
+ {
256
+ estimated_delivery: {
257
+ from: '2019-05-06',
258
+ to: '2019-05-09'
259
+ }
260
+ }
261
+ ]
262
+ }
263
+ expect(actual).to eq(expected)
264
+ TEST
265
+ program = make_rspec_rails_test_program(
266
+ snippet,
267
+ color_enabled: color_enabled,
268
+ )
269
+
270
+ expected_output = build_expected_output(
271
+ color_enabled: color_enabled,
272
+ snippet: "expect(actual).to eq(expected)",
273
+ expectation: proc {
274
+ line do
275
+ plain "Expected "
276
+ beta %|{ shipments: [{ estimated_delivery: { from: "2019-05-06", to: "2019-05-09" } }] }|
277
+ end
278
+
279
+ line do
280
+ plain " to eq "
281
+ alpha %|#<HashWithIndifferentAccess { "shipments" => [#<HashWithIndifferentAccess { "estimated_delivery" => #<HashWithIndifferentAccess { "from" => "2019-05-06", "to" => "2019-05-06" }> }>] }>|
282
+ end
283
+ },
284
+ diff: proc {
285
+ plain_line %| #<HashWithIndifferentAccess {|
286
+ plain_line %| "shipments" => [|
287
+ plain_line %| {|
288
+ plain_line %| "estimated_delivery" => {|
289
+ plain_line %| "from" => "2019-05-06",|
290
+ alpha_line %|- "to" => "2019-05-06"|
291
+ beta_line %|+ "to" => "2019-05-09"|
292
+ plain_line %| }|
293
+ plain_line %| }|
294
+ plain_line %| ]|
295
+ plain_line %| }>|
296
+ },
297
+ )
298
+
299
+ expect(program).
300
+ to produce_output_when_run(expected_output).
301
+ in_color(color_enabled)
302
+ end
303
+ end
304
+ end
305
+
306
+ context "and the actual hash contains string keys" do
307
+ it "produces the correct output" do
308
+ as_both_colored_and_uncolored do |color_enabled|
309
+ snippet = <<~TEST.strip
310
+ expected = HashWithIndifferentAccess.new({
311
+ shipments: [
312
+ HashWithIndifferentAccess.new({
313
+ estimated_delivery: HashWithIndifferentAccess.new({
314
+ from: '2019-05-06',
315
+ to: '2019-05-06'
316
+ })
317
+ })
318
+ ]
319
+ })
320
+ actual = {
321
+ 'shipments' => [
322
+ {
323
+ 'estimated_delivery' => {
324
+ 'from' => '2019-05-06',
325
+ 'to' => '2019-05-09'
326
+ }
327
+ }
328
+ ]
329
+ }
330
+ expect(actual).to eq(expected)
331
+ TEST
332
+ program = make_rspec_rails_test_program(
333
+ snippet,
334
+ color_enabled: color_enabled,
335
+ )
336
+
337
+ expected_output = build_expected_output(
338
+ color_enabled: color_enabled,
339
+ snippet: "expect(actual).to eq(expected)",
340
+ expectation: proc {
341
+ line do
342
+ plain "Expected "
343
+ beta %|{ "shipments" => [{ "estimated_delivery" => { "from" => "2019-05-06", "to" => "2019-05-09" } }] }|
344
+ end
345
+
346
+ line do
347
+ plain " to eq "
348
+ alpha %|#<HashWithIndifferentAccess { "shipments" => [#<HashWithIndifferentAccess { "estimated_delivery" => #<HashWithIndifferentAccess { "from" => "2019-05-06", "to" => "2019-05-06" }> }>] }>|
349
+ end
350
+ },
351
+ diff: proc {
352
+ plain_line %| #<HashWithIndifferentAccess {|
353
+ plain_line %| "shipments" => [|
354
+ plain_line %| {|
355
+ plain_line %| "estimated_delivery" => {|
356
+ plain_line %| "from" => "2019-05-06",|
357
+ alpha_line %|- "to" => "2019-05-06"|
358
+ beta_line %|+ "to" => "2019-05-09"|
359
+ plain_line %| }|
360
+ plain_line %| }|
361
+ plain_line %| ]|
362
+ plain_line %| }>|
363
+ },
364
+ )
365
+
366
+ expect(program).
367
+ to produce_output_when_run(expected_output).
368
+ in_color(color_enabled)
369
+ end
370
+ end
113
371
  end
114
372
  end
115
373
  end
@@ -117,115 +375,373 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
117
375
 
118
376
  describe "and RSpec's #match matcher" do
119
377
  context "when the actual value is a HashWithIndifferentAccess" do
120
- it "produces the correct output" do
121
- as_both_colored_and_uncolored do |color_enabled|
122
- snippet = <<~TEST.strip
123
- expected = {
124
- line_1: "123 Main St.",
125
- city: "Hill Valley",
126
- state: "CA",
127
- zip: "90382",
128
- }
129
- actual = HashWithIndifferentAccess.new({
130
- line_1: "456 Ponderosa Ct.",
131
- city: "Oakland",
132
- state: "CA",
133
- zip: "91234",
134
- })
135
- expect(actual).to match(expected)
136
- TEST
137
- program = make_rspec_rails_test_program(
138
- snippet,
139
- color_enabled: color_enabled,
140
- )
141
-
142
- expected_output = build_expected_output(
143
- color_enabled: color_enabled,
144
- snippet: "expect(actual).to match(expected)",
145
- expectation: proc {
146
- line do
147
- plain "Expected "
148
- beta %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
149
- end
150
-
151
- line do
152
- plain "to match "
153
- alpha %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
154
- end
155
- },
156
- diff: proc {
157
- plain_line %| #<HashWithIndifferentAccess {|
158
- alpha_line %|- "line_1" => "123 Main St.",|
159
- beta_line %|+ "line_1" => "456 Ponderosa Ct.",|
160
- alpha_line %|- "city" => "Hill Valley",|
161
- beta_line %|+ "city" => "Oakland",|
162
- plain_line %| "state" => "CA",|
163
- alpha_line %|- "zip" => "90382"|
164
- beta_line %|+ "zip" => "91234"|
165
- plain_line %| }>|
166
- },
167
- )
168
-
169
- expect(program).
170
- to produce_output_when_run(expected_output).
171
- in_color(color_enabled)
378
+ context "and both hashes are one-dimensional" do
379
+ context "and the expected hash contains symbol keys" do
380
+ it "produces the correct output" do
381
+ as_both_colored_and_uncolored do |color_enabled|
382
+ snippet = <<~TEST.strip
383
+ expected = {
384
+ line_1: "123 Main St.",
385
+ city: "Hill Valley",
386
+ state: "CA",
387
+ zip: "90382",
388
+ }
389
+ actual = HashWithIndifferentAccess.new({
390
+ line_1: "456 Ponderosa Ct.",
391
+ city: "Oakland",
392
+ state: "CA",
393
+ zip: "91234",
394
+ })
395
+ expect(actual).to match(expected)
396
+ TEST
397
+ program = make_rspec_rails_test_program(
398
+ snippet,
399
+ color_enabled: color_enabled,
400
+ )
401
+
402
+ expected_output = build_expected_output(
403
+ color_enabled: color_enabled,
404
+ snippet: "expect(actual).to match(expected)",
405
+ expectation: proc {
406
+ line do
407
+ plain "Expected "
408
+ beta %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
409
+ end
410
+
411
+ line do
412
+ plain "to match "
413
+ alpha %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
414
+ end
415
+ },
416
+ diff: proc {
417
+ plain_line %| #<HashWithIndifferentAccess {|
418
+ alpha_line %|- "line_1" => "123 Main St.",|
419
+ beta_line %|+ "line_1" => "456 Ponderosa Ct.",|
420
+ alpha_line %|- "city" => "Hill Valley",|
421
+ beta_line %|+ "city" => "Oakland",|
422
+ plain_line %| "state" => "CA",|
423
+ alpha_line %|- "zip" => "90382"|
424
+ beta_line %|+ "zip" => "91234"|
425
+ plain_line %| }>|
426
+ },
427
+ )
428
+
429
+ expect(program).
430
+ to produce_output_when_run(expected_output).
431
+ in_color(color_enabled)
432
+ end
433
+ end
434
+ end
435
+
436
+ context "and the expected hash contains string keys" do
437
+ it "produces the correct output" do
438
+ as_both_colored_and_uncolored do |color_enabled|
439
+ snippet = <<~TEST.strip
440
+ expected = {
441
+ "line_1" => "123 Main St.",
442
+ "city" => "Hill Valley",
443
+ "state" => "CA",
444
+ "zip" => "90382",
445
+ }
446
+ actual = HashWithIndifferentAccess.new({
447
+ line_1: "456 Ponderosa Ct.",
448
+ city: "Oakland",
449
+ state: "CA",
450
+ zip: "91234",
451
+ })
452
+ expect(actual).to match(expected)
453
+ TEST
454
+ program = make_rspec_rails_test_program(
455
+ snippet,
456
+ color_enabled: color_enabled,
457
+ )
458
+
459
+ expected_output = build_expected_output(
460
+ color_enabled: color_enabled,
461
+ snippet: "expect(actual).to match(expected)",
462
+ expectation: proc {
463
+ line do
464
+ plain "Expected "
465
+ beta %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
466
+ end
467
+
468
+ line do
469
+ plain "to match "
470
+ alpha %|{ "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }|
471
+ end
472
+ },
473
+ diff: proc {
474
+ plain_line %| #<HashWithIndifferentAccess {|
475
+ alpha_line %|- "line_1" => "123 Main St.",|
476
+ beta_line %|+ "line_1" => "456 Ponderosa Ct.",|
477
+ alpha_line %|- "city" => "Hill Valley",|
478
+ beta_line %|+ "city" => "Oakland",|
479
+ plain_line %| "state" => "CA",|
480
+ alpha_line %|- "zip" => "90382"|
481
+ beta_line %|+ "zip" => "91234"|
482
+ plain_line %| }>|
483
+ },
484
+ )
485
+
486
+ expect(program).
487
+ to produce_output_when_run(expected_output).
488
+ in_color(color_enabled)
489
+ end
490
+ end
172
491
  end
173
492
  end
174
493
  end
175
494
 
176
495
  context "when the expected value is a HashWithIndifferentAccess" do
177
- it "produces the correct output" do
178
- as_both_colored_and_uncolored do |color_enabled|
179
- snippet = <<~TEST.strip
180
- expected = HashWithIndifferentAccess.new({
181
- line_1: "456 Ponderosa Ct.",
182
- city: "Oakland",
183
- state: "CA",
184
- zip: "91234",
185
- })
186
- actual = {
187
- line_1: "123 Main St.",
188
- city: "Hill Valley",
189
- state: "CA",
190
- zip: "90382",
191
- }
192
- expect(actual).to match(expected)
193
- TEST
194
- program = make_rspec_rails_test_program(
195
- snippet,
196
- color_enabled: color_enabled,
197
- )
198
-
199
- expected_output = build_expected_output(
200
- color_enabled: color_enabled,
201
- snippet: "expect(actual).to match(expected)",
202
- expectation: proc {
203
- line do
204
- plain "Expected "
205
- beta %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
206
- end
207
-
208
- line do
209
- plain "to match "
210
- alpha %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
211
- end
212
- },
213
- diff: proc {
214
- plain_line %| #<HashWithIndifferentAccess {|
215
- alpha_line %|- "line_1" => "456 Ponderosa Ct.",|
216
- beta_line %|+ "line_1" => "123 Main St.",|
217
- alpha_line %|- "city" => "Oakland",|
218
- beta_line %|+ "city" => "Hill Valley",|
219
- plain_line %| "state" => "CA",|
220
- alpha_line %|- "zip" => "91234"|
221
- beta_line %|+ "zip" => "90382"|
222
- plain_line %| }>|
223
- },
224
- )
225
-
226
- expect(program).
227
- to produce_output_when_run(expected_output).
228
- in_color(color_enabled)
496
+ context "and both hashes are one-dimensional" do
497
+ context "and the actual hash contains symbol keys" do
498
+ it "produces the correct output" do
499
+ as_both_colored_and_uncolored do |color_enabled|
500
+ snippet = <<~TEST.strip
501
+ expected = HashWithIndifferentAccess.new({
502
+ line_1: "456 Ponderosa Ct.",
503
+ city: "Oakland",
504
+ state: "CA",
505
+ zip: "91234",
506
+ })
507
+ actual = {
508
+ line_1: "123 Main St.",
509
+ city: "Hill Valley",
510
+ state: "CA",
511
+ zip: "90382",
512
+ }
513
+ expect(actual).to match(expected)
514
+ TEST
515
+ program = make_rspec_rails_test_program(
516
+ snippet,
517
+ color_enabled: color_enabled,
518
+ )
519
+
520
+ expected_output = build_expected_output(
521
+ color_enabled: color_enabled,
522
+ snippet: "expect(actual).to match(expected)",
523
+ expectation: proc {
524
+ line do
525
+ plain "Expected "
526
+ beta %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
527
+ end
528
+
529
+ line do
530
+ plain "to match "
531
+ alpha %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
532
+ end
533
+ },
534
+ diff: proc {
535
+ plain_line %| #<HashWithIndifferentAccess {|
536
+ alpha_line %|- "line_1" => "456 Ponderosa Ct.",|
537
+ beta_line %|+ "line_1" => "123 Main St.",|
538
+ alpha_line %|- "city" => "Oakland",|
539
+ beta_line %|+ "city" => "Hill Valley",|
540
+ plain_line %| "state" => "CA",|
541
+ alpha_line %|- "zip" => "91234"|
542
+ beta_line %|+ "zip" => "90382"|
543
+ plain_line %| }>|
544
+ },
545
+ )
546
+
547
+ expect(program).
548
+ to produce_output_when_run(expected_output).
549
+ in_color(color_enabled)
550
+ end
551
+ end
552
+ end
553
+
554
+ context "and the actual hash contains string keys" do
555
+ it "produces the correct output" do
556
+ as_both_colored_and_uncolored do |color_enabled|
557
+ snippet = <<~TEST.strip
558
+ expected = HashWithIndifferentAccess.new({
559
+ line_1: "456 Ponderosa Ct.",
560
+ city: "Oakland",
561
+ state: "CA",
562
+ zip: "91234",
563
+ })
564
+ actual = {
565
+ "line_1" => "123 Main St.",
566
+ "city" => "Hill Valley",
567
+ "state" => "CA",
568
+ "zip" => "90382",
569
+ }
570
+ expect(actual).to match(expected)
571
+ TEST
572
+ program = make_rspec_rails_test_program(
573
+ snippet,
574
+ color_enabled: color_enabled,
575
+ )
576
+
577
+ expected_output = build_expected_output(
578
+ color_enabled: color_enabled,
579
+ snippet: "expect(actual).to match(expected)",
580
+ expectation: proc {
581
+ line do
582
+ plain "Expected "
583
+ beta %|{ "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }|
584
+ end
585
+
586
+ line do
587
+ plain "to match "
588
+ alpha %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
589
+ end
590
+ },
591
+ diff: proc {
592
+ plain_line %| #<HashWithIndifferentAccess {|
593
+ alpha_line %|- "line_1" => "456 Ponderosa Ct.",|
594
+ beta_line %|+ "line_1" => "123 Main St.",|
595
+ alpha_line %|- "city" => "Oakland",|
596
+ beta_line %|+ "city" => "Hill Valley",|
597
+ plain_line %| "state" => "CA",|
598
+ alpha_line %|- "zip" => "91234"|
599
+ beta_line %|+ "zip" => "90382"|
600
+ plain_line %| }>|
601
+ },
602
+ )
603
+
604
+ expect(program).
605
+ to produce_output_when_run(expected_output).
606
+ in_color(color_enabled)
607
+ end
608
+ end
609
+ end
610
+ end
611
+
612
+ context "and both hashes are multi-dimensional" do
613
+ context "and the actual hash contains symbol keys" do
614
+ it "produces the correct output" do
615
+ as_both_colored_and_uncolored do |color_enabled|
616
+ snippet = <<~TEST.strip
617
+ expected = HashWithIndifferentAccess.new({
618
+ shipments: [
619
+ HashWithIndifferentAccess.new({
620
+ estimated_delivery: HashWithIndifferentAccess.new({
621
+ from: '2019-05-06',
622
+ to: '2019-05-06'
623
+ })
624
+ })
625
+ ]
626
+ })
627
+ actual = {
628
+ shipments: [
629
+ {
630
+ estimated_delivery: {
631
+ from: '2019-05-06',
632
+ to: '2019-05-09'
633
+ }
634
+ }
635
+ ]
636
+ }
637
+ expect(actual).to match(expected)
638
+ TEST
639
+ program = make_rspec_rails_test_program(
640
+ snippet,
641
+ color_enabled: color_enabled,
642
+ )
643
+
644
+ expected_output = build_expected_output(
645
+ color_enabled: color_enabled,
646
+ snippet: "expect(actual).to match(expected)",
647
+ expectation: proc {
648
+ line do
649
+ plain "Expected "
650
+ beta %|{ shipments: [{ estimated_delivery: { from: "2019-05-06", to: "2019-05-09" } }] }|
651
+ end
652
+
653
+ line do
654
+ plain "to match "
655
+ alpha %|#<HashWithIndifferentAccess { "shipments" => [#<HashWithIndifferentAccess { "estimated_delivery" => #<HashWithIndifferentAccess { "from" => "2019-05-06", "to" => "2019-05-06" }> }>] }>|
656
+ end
657
+ },
658
+ diff: proc {
659
+ plain_line %| #<HashWithIndifferentAccess {|
660
+ plain_line %| "shipments" => [|
661
+ plain_line %| {|
662
+ plain_line %| "estimated_delivery" => {|
663
+ plain_line %| "from" => "2019-05-06",|
664
+ alpha_line %|- "to" => "2019-05-06"|
665
+ beta_line %|+ "to" => "2019-05-09"|
666
+ plain_line %| }|
667
+ plain_line %| }|
668
+ plain_line %| ]|
669
+ plain_line %| }>|
670
+ },
671
+ )
672
+
673
+ expect(program).
674
+ to produce_output_when_run(expected_output).
675
+ in_color(color_enabled)
676
+ end
677
+ end
678
+ end
679
+
680
+ context "and the actual hash contains string keys" do
681
+ it "produces the correct output" do
682
+ as_both_colored_and_uncolored do |color_enabled|
683
+ snippet = <<~TEST.strip
684
+ expected = HashWithIndifferentAccess.new({
685
+ shipments: [
686
+ HashWithIndifferentAccess.new({
687
+ estimated_delivery: HashWithIndifferentAccess.new({
688
+ from: '2019-05-06',
689
+ to: '2019-05-06'
690
+ })
691
+ })
692
+ ]
693
+ })
694
+ actual = {
695
+ 'shipments' => [
696
+ {
697
+ 'estimated_delivery' => {
698
+ 'from' => '2019-05-06',
699
+ 'to' => '2019-05-09'
700
+ }
701
+ }
702
+ ]
703
+ }
704
+ expect(actual).to match(expected)
705
+ TEST
706
+ program = make_rspec_rails_test_program(
707
+ snippet,
708
+ color_enabled: color_enabled,
709
+ )
710
+
711
+ expected_output = build_expected_output(
712
+ color_enabled: color_enabled,
713
+ snippet: "expect(actual).to match(expected)",
714
+ expectation: proc {
715
+ line do
716
+ plain "Expected "
717
+ beta %|{ "shipments" => [{ "estimated_delivery" => { "from" => "2019-05-06", "to" => "2019-05-09" } }] }|
718
+ end
719
+
720
+ line do
721
+ plain "to match "
722
+ alpha %|#<HashWithIndifferentAccess { "shipments" => [#<HashWithIndifferentAccess { "estimated_delivery" => #<HashWithIndifferentAccess { "from" => "2019-05-06", "to" => "2019-05-06" }> }>] }>|
723
+ end
724
+ },
725
+ diff: proc {
726
+ plain_line %| #<HashWithIndifferentAccess {|
727
+ plain_line %| "shipments" => [|
728
+ plain_line %| {|
729
+ plain_line %| "estimated_delivery" => {|
730
+ plain_line %| "from" => "2019-05-06",|
731
+ alpha_line %|- "to" => "2019-05-06"|
732
+ beta_line %|+ "to" => "2019-05-09"|
733
+ plain_line %| }|
734
+ plain_line %| }|
735
+ plain_line %| ]|
736
+ plain_line %| }>|
737
+ },
738
+ )
739
+
740
+ expect(program).
741
+ to produce_output_when_run(expected_output).
742
+ in_color(color_enabled)
743
+ end
744
+ end
229
745
  end
230
746
  end
231
747
  end