super_diff 0.3.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +104 -73
- data/lib/super_diff.rb +20 -11
- data/lib/super_diff/active_record.rb +21 -23
- data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +3 -3
- data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -5
- data/lib/super_diff/active_record/monkey_patches.rb +9 -0
- data/lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb +32 -22
- data/lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb +17 -7
- data/lib/super_diff/active_record/operation_tree_builders.rb +14 -0
- data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_model.rb +2 -2
- data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_relation.rb +4 -4
- data/lib/super_diff/active_record/{operation_sequences.rb → operation_trees.rb} +2 -2
- data/lib/super_diff/active_record/{operation_sequences → operation_trees}/active_record_relation.rb +2 -2
- data/lib/super_diff/active_support.rb +16 -19
- data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +3 -3
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -5
- data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +17 -7
- data/lib/super_diff/active_support/operation_tree_builders.rb +10 -0
- data/lib/super_diff/active_support/{operational_sequencers → operation_tree_builders}/hash_with_indifferent_access.rb +2 -2
- data/lib/super_diff/active_support/{operation_sequences.rb → operation_trees.rb} +2 -2
- data/lib/super_diff/active_support/{operation_sequences → operation_trees}/hash_with_indifferent_access.rb +2 -2
- data/lib/super_diff/configuration.rb +60 -0
- data/lib/super_diff/csi.rb +4 -0
- data/lib/super_diff/diff_formatters.rb +3 -3
- data/lib/super_diff/diff_formatters/array.rb +3 -3
- data/lib/super_diff/diff_formatters/base.rb +3 -2
- data/lib/super_diff/diff_formatters/collection.rb +2 -2
- data/lib/super_diff/diff_formatters/custom_object.rb +3 -3
- data/lib/super_diff/diff_formatters/default_object.rb +6 -8
- data/lib/super_diff/diff_formatters/defaults.rb +10 -0
- data/lib/super_diff/diff_formatters/hash.rb +3 -3
- data/lib/super_diff/diff_formatters/main.rb +41 -0
- data/lib/super_diff/diff_formatters/multiline_string.rb +3 -3
- data/lib/super_diff/differs.rb +4 -11
- data/lib/super_diff/differs/array.rb +2 -11
- data/lib/super_diff/differs/base.rb +20 -3
- data/lib/super_diff/differs/custom_object.rb +2 -11
- data/lib/super_diff/differs/default_object.rb +2 -8
- data/lib/super_diff/differs/defaults.rb +12 -0
- data/lib/super_diff/differs/hash.rb +2 -11
- data/lib/super_diff/differs/main.rb +48 -0
- data/lib/super_diff/differs/multiline_string.rb +2 -14
- data/lib/super_diff/differs/time_like.rb +15 -0
- data/lib/super_diff/equality_matchers.rb +3 -9
- data/lib/super_diff/equality_matchers/array.rb +1 -7
- data/lib/super_diff/equality_matchers/base.rb +1 -1
- data/lib/super_diff/equality_matchers/default.rb +2 -8
- data/lib/super_diff/equality_matchers/defaults.rb +12 -0
- data/lib/super_diff/equality_matchers/hash.rb +1 -7
- data/lib/super_diff/equality_matchers/main.rb +21 -0
- data/lib/super_diff/equality_matchers/multiline_string.rb +1 -7
- data/lib/super_diff/errors.rb +16 -0
- data/lib/super_diff/errors/no_diff_formatter_available_error.rb +21 -0
- data/lib/super_diff/errors/no_differ_available_error.rb +24 -0
- data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +22 -0
- data/lib/super_diff/implementation_checks.rb +19 -0
- data/lib/super_diff/object_inspection.rb +1 -10
- data/lib/super_diff/object_inspection/inspection_tree.rb +6 -2
- data/lib/super_diff/object_inspection/inspectors.rb +5 -1
- data/lib/super_diff/object_inspection/inspectors/array.rb +20 -10
- data/lib/super_diff/object_inspection/inspectors/base.rb +36 -0
- data/lib/super_diff/object_inspection/inspectors/custom_object.rb +24 -14
- data/lib/super_diff/object_inspection/inspectors/default_object.rb +44 -30
- data/lib/super_diff/object_inspection/inspectors/defaults.rb +15 -0
- data/lib/super_diff/object_inspection/inspectors/hash.rb +20 -10
- data/lib/super_diff/object_inspection/inspectors/main.rb +35 -0
- data/lib/super_diff/object_inspection/inspectors/primitive.rb +20 -5
- data/lib/super_diff/object_inspection/inspectors/string.rb +15 -5
- data/lib/super_diff/object_inspection/inspectors/time_like.rb +23 -0
- data/lib/super_diff/object_inspection/nodes/inspection.rb +9 -2
- data/lib/super_diff/operation_tree_builders.rb +18 -0
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/array.rb +38 -59
- data/lib/super_diff/operation_tree_builders/base.rb +98 -0
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/custom_object.rb +3 -3
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/default_object.rb +8 -3
- data/lib/super_diff/operation_tree_builders/defaults.rb +5 -0
- data/lib/super_diff/operation_tree_builders/hash.rb +226 -0
- data/lib/super_diff/operation_tree_builders/main.rb +42 -0
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/multiline_string.rb +3 -3
- data/lib/super_diff/operation_tree_builders/time_like.rb +34 -0
- data/lib/super_diff/operation_trees.rb +13 -0
- data/lib/super_diff/{operation_sequences → operation_trees}/array.rb +5 -1
- data/lib/super_diff/operation_trees/base.rb +31 -0
- data/lib/super_diff/{operation_sequences → operation_trees}/custom_object.rb +5 -1
- data/lib/super_diff/{operation_sequences → operation_trees}/default_object.rb +10 -8
- data/lib/super_diff/operation_trees/defaults.rb +5 -0
- data/lib/super_diff/{operation_sequences → operation_trees}/hash.rb +5 -1
- data/lib/super_diff/operation_trees/main.rb +35 -0
- data/lib/super_diff/operation_trees/multiline_string.rb +18 -0
- data/lib/super_diff/operations/unary_operation.rb +3 -0
- data/lib/super_diff/rspec.rb +54 -22
- data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
- data/lib/super_diff/rspec/differ.rb +2 -17
- data/lib/super_diff/rspec/differs.rb +9 -3
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -8
- data/lib/super_diff/rspec/differs/collection_including.rb +18 -0
- data/lib/super_diff/rspec/differs/hash_including.rb +18 -0
- data/lib/super_diff/rspec/differs/object_having_attributes.rb +17 -0
- data/lib/super_diff/rspec/matcher_text_builders.rb +4 -0
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +26 -7
- data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +61 -0
- data/lib/super_diff/rspec/matcher_text_builders/match.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +13 -1
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_template.rb +1 -1
- data/lib/super_diff/rspec/monkey_patches.rb +226 -115
- data/lib/super_diff/rspec/object_inspection.rb +0 -1
- data/lib/super_diff/rspec/object_inspection/inspectors.rb +22 -6
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb +17 -8
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +28 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +31 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +23 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +23 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/object_having_attributes.rb +31 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +13 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +29 -0
- data/lib/super_diff/rspec/operation_tree_builders.rb +22 -0
- data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/collection_containing_exactly.rb +6 -6
- data/lib/super_diff/rspec/{operational_sequencers/partial_array.rb → operation_tree_builders/collection_including.rb} +4 -3
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +25 -0
- data/lib/super_diff/rspec/{operational_sequencers/partial_object.rb → operation_tree_builders/object_having_attributes.rb} +5 -11
- data/lib/super_diff/version.rb +1 -1
- data/spec/examples.txt +5 -350
- data/spec/integration/rails/active_record_spec.rb +1 -1
- data/spec/integration/rails/hash_with_indifferent_access_spec.rb +1 -1
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +111 -59
- data/spec/integration/rspec/eq_matcher_spec.rb +1 -1
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +354 -227
- data/spec/integration/rspec/have_predicate_matcher_spec.rb +484 -0
- data/spec/integration/rspec/include_matcher_spec.rb +2 -2
- data/spec/integration/rspec/match_array_matcher_spec.rb +372 -0
- data/spec/integration/rspec/match_matcher_spec.rb +8 -8
- data/spec/integration/rspec/raise_error_matcher_spec.rb +605 -226
- data/spec/integration/rspec/third_party_matcher_spec.rb +241 -0
- data/spec/integration/rspec/unhandled_errors_spec.rb +110 -58
- data/spec/spec_helper.rb +18 -7
- data/spec/support/command_runner.rb +3 -0
- data/spec/support/integration/helpers.rb +14 -90
- data/spec/support/integration/matchers.rb +143 -0
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +14 -29
- data/spec/support/integration/test_programs/base.rb +120 -0
- data/spec/support/integration/test_programs/plain.rb +13 -0
- data/spec/support/integration/test_programs/rspec_active_record.rb +17 -0
- data/spec/support/integration/test_programs/rspec_rails.rb +17 -0
- data/spec/support/models/active_record/person.rb +4 -11
- data/spec/support/models/active_record/query.rb +15 -0
- data/spec/support/models/active_record/shipping_address.rb +10 -14
- data/spec/support/object_id.rb +27 -0
- data/spec/support/ruby_versions.rb +4 -0
- data/spec/support/shared_examples/active_record.rb +71 -0
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +724 -208
- data/spec/unit/{equality_matcher_spec.rb → equality_matchers/main_spec.rb} +165 -9
- data/spec/unit/object_inspection_spec.rb +94 -18
- data/spec/unit/rspec/matchers/have_predicate_spec.rb +21 -0
- data/spec/unit/rspec/matchers/match_array_spec.rb +11 -0
- data/spec/unit/rspec/matchers/raise_error_spec.rb +16 -0
- data/super_diff.gemspec +4 -6
- metadata +99 -82
- data/lib/super_diff/active_record/object_inspection/map_extension.rb +0 -18
- data/lib/super_diff/active_record/operational_sequencers.rb +0 -14
- data/lib/super_diff/active_support/object_inspection/map_extension.rb +0 -15
- data/lib/super_diff/active_support/operational_sequencers.rb +0 -10
- data/lib/super_diff/diff_formatter.rb +0 -32
- data/lib/super_diff/differ.rb +0 -51
- data/lib/super_diff/differs/time.rb +0 -24
- data/lib/super_diff/equality_matcher.rb +0 -32
- data/lib/super_diff/no_differ_available_error.rb +0 -22
- data/lib/super_diff/no_operational_sequencer_available_error.rb +0 -20
- data/lib/super_diff/object_inspection/inspector.rb +0 -27
- data/lib/super_diff/object_inspection/inspectors/time.rb +0 -13
- data/lib/super_diff/object_inspection/map.rb +0 -30
- data/lib/super_diff/operation_sequences.rb +0 -9
- data/lib/super_diff/operation_sequences/base.rb +0 -11
- data/lib/super_diff/operational_sequencer.rb +0 -48
- data/lib/super_diff/operational_sequencers.rb +0 -17
- data/lib/super_diff/operational_sequencers/base.rb +0 -89
- data/lib/super_diff/operational_sequencers/hash.rb +0 -85
- data/lib/super_diff/operational_sequencers/time_like.rb +0 -30
- data/lib/super_diff/rspec/configuration.rb +0 -31
- data/lib/super_diff/rspec/differs/partial_array.rb +0 -22
- data/lib/super_diff/rspec/differs/partial_hash.rb +0 -22
- data/lib/super_diff/rspec/differs/partial_object.rb +0 -22
- data/lib/super_diff/rspec/object_inspection/inspectors/partial_array.rb +0 -22
- data/lib/super_diff/rspec/object_inspection/inspectors/partial_hash.rb +0 -21
- data/lib/super_diff/rspec/object_inspection/inspectors/partial_object.rb +0 -21
- data/lib/super_diff/rspec/object_inspection/map_extension.rb +0 -23
- data/lib/super_diff/rspec/operational_sequencers.rb +0 -22
- data/lib/super_diff/rspec/operational_sequencers/partial_hash.rb +0 -32
@@ -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.
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
@@ -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.
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
@@ -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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
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
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
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
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
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
|