pact 0.1.28 → 1.3.3
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.
- data/.gitignore +2 -1
- data/.ruby-version +1 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +374 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +58 -55
- data/README.md +214 -139
- data/Rakefile +4 -28
- data/bin/pact +2 -2
- data/config.ru +3 -0
- data/documentation/README.md +13 -0
- data/documentation/configuration.md +166 -0
- data/documentation/diff_formatter_embedded.png +0 -0
- data/documentation/diff_formatter_list.png +0 -0
- data/documentation/diff_formatter_unix.png +0 -0
- data/example/animal-service/Gemfile +14 -0
- data/example/animal-service/Gemfile.lock +69 -0
- data/example/animal-service/Rakefile +5 -0
- data/example/animal-service/config.ru +3 -0
- data/example/animal-service/db/animal_db.sqlite3 +0 -0
- data/example/animal-service/lib/animal_service/animal_repository.rb +12 -0
- data/example/animal-service/lib/animal_service/api.rb +28 -0
- data/example/animal-service/lib/animal_service/db.rb +5 -0
- data/example/animal-service/spec/service_consumers/pact_helper.rb +11 -0
- data/example/animal-service/spec/service_consumers/provider_states_for_zoo_app.rb +26 -0
- data/example/zoo-app/Gemfile +12 -0
- data/example/zoo-app/Gemfile.lock +63 -0
- data/example/zoo-app/Rakefile +5 -0
- data/example/zoo-app/doc/pacts/markdown/README.md +3 -0
- data/example/zoo-app/doc/pacts/markdown/Zoo App - Animal Service.md +75 -0
- data/example/zoo-app/lib/zoo_app/animal_service_client.rb +40 -0
- data/example/zoo-app/lib/zoo_app/models/alligator.rb +15 -0
- data/example/zoo-app/spec/pacts/zoo_app-animal_service.json +67 -0
- data/example/zoo-app/spec/service_providers/animal_service_client_spec.rb +71 -0
- data/example/zoo-app/spec/service_providers/pact_helper.rb +15 -0
- data/example/zoo-app/spec/spec_helper.rb +6 -0
- data/lib/pact/cli.rb +138 -0
- data/lib/pact/configuration.rb +169 -28
- data/lib/pact/consumer/app_manager.rb +10 -29
- data/lib/pact/consumer/configuration/configuration_extensions.rb +15 -0
- data/lib/pact/consumer/configuration/dsl.rb +12 -0
- data/lib/pact/consumer/configuration/mock_service.rb +91 -0
- data/lib/pact/consumer/configuration/service_consumer.rb +51 -0
- data/lib/pact/consumer/configuration/service_provider.rb +40 -0
- data/lib/pact/consumer/configuration.rb +11 -0
- data/lib/pact/consumer/consumer_contract_builder.rb +44 -47
- data/lib/pact/consumer/interaction_builder.rb +41 -0
- data/lib/pact/consumer/interactions_filter.rb +48 -0
- data/lib/pact/consumer/mock_service/app.rb +82 -0
- data/lib/pact/consumer/mock_service/interaction_delete.rb +33 -0
- data/lib/pact/consumer/mock_service/interaction_list.rb +76 -0
- data/lib/pact/consumer/mock_service/interaction_mismatch.rb +73 -0
- data/lib/pact/consumer/mock_service/interaction_post.rb +31 -0
- data/lib/pact/consumer/mock_service/interaction_replay.rb +139 -0
- data/lib/pact/consumer/mock_service/log_get.rb +28 -0
- data/lib/pact/consumer/mock_service/missing_interactions_get.rb +30 -0
- data/lib/pact/consumer/mock_service/mock_service_administration_endpoint.rb +31 -0
- data/lib/pact/consumer/mock_service/pact_post.rb +33 -0
- data/lib/pact/consumer/mock_service/rack_request_helper.rb +51 -0
- data/lib/pact/consumer/mock_service/verification_get.rb +68 -0
- data/lib/pact/consumer/mock_service.rb +1 -339
- data/lib/pact/consumer/mock_service_client.rb +65 -0
- data/lib/pact/consumer/mock_service_interaction_expectation.rb +37 -0
- data/lib/pact/consumer/request.rb +27 -0
- data/lib/pact/consumer/rspec.rb +9 -19
- data/lib/pact/consumer/server.rb +90 -0
- data/lib/pact/consumer/spec_hooks.rb +38 -0
- data/lib/pact/consumer/world.rb +37 -0
- data/lib/pact/consumer.rb +10 -7
- data/lib/pact/consumer_contract/consumer_contract.rb +115 -0
- data/lib/pact/consumer_contract/consumer_contract_writer.rb +84 -0
- data/lib/pact/consumer_contract/file_name.rb +19 -0
- data/lib/pact/consumer_contract/headers.rb +51 -0
- data/lib/pact/consumer_contract/interaction.rb +67 -0
- data/lib/pact/consumer_contract/pact_file.rb +24 -0
- data/lib/pact/consumer_contract/request.rb +73 -0
- data/lib/pact/consumer_contract/service_consumer.rb +28 -0
- data/lib/pact/consumer_contract/service_provider.rb +28 -0
- data/lib/pact/consumer_contract.rb +1 -110
- data/lib/pact/doc/doc_file.rb +40 -0
- data/lib/pact/doc/generate.rb +11 -0
- data/lib/pact/doc/generator.rb +82 -0
- data/lib/pact/doc/interaction_view_model.rb +114 -0
- data/lib/pact/doc/markdown/consumer_contract_renderer.rb +56 -0
- data/lib/pact/doc/markdown/generator.rb +26 -0
- data/lib/pact/doc/markdown/index_renderer.rb +41 -0
- data/lib/pact/doc/markdown/interaction.erb +14 -0
- data/lib/pact/doc/markdown/interaction_renderer.rb +38 -0
- data/lib/pact/doc/sort_interactions.rb +17 -0
- data/lib/pact/matchers/actual_type.rb +16 -0
- data/lib/pact/matchers/base_difference.rb +37 -0
- data/lib/pact/matchers/differ.rb +153 -0
- data/lib/pact/matchers/difference.rb +13 -0
- data/lib/pact/matchers/difference_indicator.rb +26 -0
- data/lib/pact/matchers/embedded_diff_formatter.rb +62 -0
- data/lib/pact/matchers/expected_type.rb +35 -0
- data/lib/pact/matchers/index_not_found.rb +15 -0
- data/lib/pact/matchers/list_diff_formatter.rb +101 -0
- data/lib/pact/matchers/matchers.rb +91 -37
- data/lib/pact/matchers/no_diff_indicator.rb +18 -0
- data/lib/pact/matchers/regexp_difference.rb +13 -0
- data/lib/pact/matchers/type_difference.rb +16 -0
- data/lib/pact/matchers/unexpected_index.rb +11 -0
- data/lib/pact/matchers/unexpected_key.rb +11 -0
- data/lib/pact/matchers/unix_diff_formatter.rb +114 -0
- data/lib/pact/project_root.rb +7 -0
- data/lib/pact/provider/configuration/configuration_extension.rb +58 -0
- data/lib/pact/provider/configuration/dsl.rb +13 -0
- data/lib/pact/provider/configuration/pact_verification.rb +46 -0
- data/lib/pact/provider/configuration/service_provider_config.rb +16 -0
- data/lib/pact/provider/configuration/service_provider_dsl.rb +59 -0
- data/lib/pact/provider/configuration.rb +7 -0
- data/lib/pact/provider/context.rb +0 -0
- data/lib/pact/provider/matchers/messages.rb +45 -0
- data/lib/pact/provider/pact_helper_locator.rb +22 -0
- data/lib/pact/provider/pact_spec_runner.rb +123 -0
- data/lib/pact/provider/pact_verification.rb +17 -0
- data/lib/pact/provider/print_missing_provider_states.rb +30 -0
- data/lib/pact/provider/request.rb +70 -0
- data/lib/pact/provider/rspec/backtrace_formatter.rb +43 -0
- data/lib/pact/provider/rspec/custom_options_file +0 -0
- data/lib/pact/provider/rspec/formatter_rspec_2.rb +65 -0
- data/lib/pact/provider/rspec/formatter_rspec_3.rb +96 -0
- data/lib/pact/provider/rspec/matchers.rb +97 -0
- data/lib/pact/provider/rspec.rb +181 -0
- data/lib/pact/provider/state/provider_state.rb +181 -0
- data/lib/pact/provider/state/provider_state_configured_modules.rb +13 -0
- data/lib/pact/provider/state/provider_state_manager.rb +42 -0
- data/lib/pact/provider/state/provider_state_proxy.rb +39 -0
- data/lib/pact/provider/test_methods.rb +47 -0
- data/lib/pact/provider/verification_report.rb +36 -0
- data/lib/pact/provider/world.rb +23 -0
- data/lib/pact/provider.rb +3 -0
- data/lib/pact/reification.rb +6 -4
- data/lib/pact/rspec.rb +53 -0
- data/lib/pact/shared/active_support_support.rb +51 -0
- data/lib/pact/shared/dsl.rb +76 -0
- data/lib/pact/shared/jruby_support.rb +18 -0
- data/lib/pact/shared/json_differ.rb +15 -0
- data/lib/pact/shared/key_not_found.rb +15 -0
- data/lib/pact/shared/null_expectation.rb +31 -0
- data/lib/pact/shared/request.rb +80 -0
- data/lib/pact/shared/text_differ.rb +14 -0
- data/lib/pact/something_like.rb +49 -0
- data/lib/pact/symbolize_keys.rb +12 -0
- data/lib/pact/tasks/task_helper.rb +36 -0
- data/lib/pact/tasks/verification_task.rb +87 -0
- data/lib/pact/tasks.rb +2 -0
- data/lib/pact/templates/provider_state.erb +14 -0
- data/lib/pact/term.rb +47 -2
- data/lib/pact/version.rb +1 -1
- data/lib/pact.rb +1 -1
- data/lib/tasks/pact.rake +25 -2
- data/pact.gemspec +13 -11
- data/{scratchpad.txt → scratchpad.rb} +18 -2
- data/spec/features/consumption_spec.rb +24 -56
- data/spec/features/production_spec.rb +19 -24
- data/spec/features/{producer_states → provider_states}/zebras.rb +3 -3
- data/spec/integration/consumer_spec.rb +212 -0
- data/spec/integration/pact/consumer_configuration_spec.rb +66 -0
- data/spec/integration/pact/provider_configuration_spec.rb +25 -0
- data/spec/lib/pact/cli_spec.rb +47 -0
- data/spec/lib/pact/configuration_spec.rb +269 -7
- data/spec/lib/pact/consumer/app_manager_spec.rb +3 -3
- data/spec/lib/pact/consumer/configuration_spec.rb +57 -0
- data/spec/lib/pact/consumer/consumer_contract_builder_spec.rb +52 -70
- data/spec/lib/pact/consumer/interaction_builder_spec.rb +91 -0
- data/spec/lib/pact/consumer/interactions_spec.rb +64 -0
- data/spec/lib/pact/consumer/mock_service/app_spec.rb +52 -0
- data/spec/lib/pact/consumer/mock_service/interaction_list_spec.rb +78 -0
- data/spec/lib/pact/consumer/mock_service/interaction_mismatch_spec.rb +70 -0
- data/spec/lib/pact/consumer/mock_service/interaction_replay_spec.rb +12 -0
- data/spec/lib/pact/consumer/mock_service/rack_request_helper_spec.rb +88 -0
- data/spec/lib/pact/consumer/mock_service/verification_get_spec.rb +142 -0
- data/spec/lib/pact/consumer/mock_service_client_spec.rb +88 -0
- data/spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb +54 -0
- data/spec/lib/pact/consumer/request_spec.rb +24 -0
- data/spec/lib/pact/consumer/service_consumer_spec.rb +1 -1
- data/spec/lib/pact/consumer_contract/active_support_support_spec.rb +58 -0
- data/spec/lib/pact/consumer_contract/consumer_contract_spec.rb +180 -0
- data/spec/lib/pact/consumer_contract/consumer_contract_writer_spec.rb +111 -0
- data/spec/lib/pact/consumer_contract/headers_spec.rb +107 -0
- data/spec/lib/pact/consumer_contract/interaction_spec.rb +107 -0
- data/spec/lib/pact/{request_spec.rb → consumer_contract/request_spec.rb} +80 -67
- data/spec/lib/pact/doc/generator_spec.rb +84 -0
- data/spec/lib/pact/doc/interaction_view_model_spec.rb +132 -0
- data/spec/lib/pact/doc/markdown/consumer_contract_renderer_spec.rb +29 -0
- data/spec/lib/pact/doc/markdown/index_renderer_spec.rb +29 -0
- data/spec/lib/pact/matchers/differ_spec.rb +214 -0
- data/spec/lib/pact/matchers/difference_spec.rb +22 -0
- data/spec/lib/pact/matchers/embedded_diff_formatter_spec.rb +90 -0
- data/spec/lib/pact/matchers/index_not_found_spec.rb +21 -0
- data/spec/lib/pact/matchers/list_diff_formatter_spec.rb +114 -0
- data/spec/lib/pact/matchers/matchers_spec.rb +400 -254
- data/spec/lib/pact/matchers/regexp_difference_spec.rb +20 -0
- data/spec/lib/pact/matchers/type_difference_spec.rb +34 -0
- data/spec/lib/pact/matchers/unexpected_index_spec.rb +20 -0
- data/spec/lib/pact/matchers/unexpected_key_spec.rb +20 -0
- data/spec/lib/pact/matchers/unix_diff_formatter_spec.rb +216 -0
- data/spec/lib/pact/provider/configuration/configuration_extension_spec.rb +30 -0
- data/spec/lib/pact/provider/configuration/pact_verification_spec.rb +43 -0
- data/spec/lib/pact/provider/configuration/service_provider_config_spec.rb +21 -0
- data/spec/lib/pact/provider/configuration/service_provider_dsl_spec.rb +108 -0
- data/spec/lib/pact/provider/configuration_spec.rb +50 -0
- data/spec/lib/pact/provider/matchers/messages_spec.rb +116 -0
- data/spec/lib/pact/provider/pact_helper_locator_spec.rb +54 -0
- data/spec/lib/pact/provider/print_missing_provider_states_spec.rb +19 -0
- data/spec/lib/pact/provider/request_spec.rb +78 -0
- data/spec/lib/pact/provider/rspec/formatter_rspec_2_spec.rb +68 -0
- data/spec/lib/pact/provider/rspec/formatter_rspec_3_spec.rb +72 -0
- data/spec/lib/pact/provider/rspec_spec.rb +55 -0
- data/spec/lib/pact/provider/state/provider_state_manager_spec.rb +89 -0
- data/spec/lib/pact/provider/state/provider_state_proxy_spec.rb +80 -0
- data/spec/lib/pact/provider/state/provider_state_spec.rb +213 -0
- data/spec/lib/pact/provider/world_spec.rb +41 -0
- data/spec/lib/pact/reification_spec.rb +24 -0
- data/spec/lib/pact/shared/dsl_spec.rb +86 -0
- data/spec/lib/pact/shared/json_differ_spec.rb +36 -0
- data/spec/lib/pact/shared/key_not_found_spec.rb +20 -0
- data/spec/lib/pact/shared/request_spec.rb +111 -0
- data/spec/lib/pact/shared/text_differ_spec.rb +54 -0
- data/spec/lib/pact/something_like_spec.rb +21 -0
- data/spec/lib/pact/tasks/task_helper_spec.rb +74 -0
- data/spec/lib/pact/tasks/verification_task_spec.rb +75 -0
- data/spec/lib/pact/term_spec.rb +57 -4
- data/spec/pact_specification/compliance-1.0.0.rb +47 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/standalone/consumer_fail_test.rb +55 -0
- data/spec/standalone/consumer_pass_test.rb +51 -0
- data/spec/support/a_consumer-a_producer.json +2 -4
- data/spec/support/a_consumer-a_provider.json +32 -0
- data/spec/support/active_support_if_configured.rb +6 -0
- data/spec/support/app_for_config_ru.rb +4 -0
- data/spec/support/consumer_contract_template.json +24 -0
- data/spec/support/dsl_spec_support.rb +7 -0
- data/spec/support/factories.rb +82 -0
- data/spec/support/generated_index.md +4 -0
- data/spec/support/generated_markdown.md +55 -0
- data/spec/support/interaction_view_model.json +63 -0
- data/spec/support/interaction_view_model_with_terms.json +50 -0
- data/spec/support/markdown_pact.json +48 -0
- data/spec/support/missing_provider_states_output.txt +25 -0
- data/spec/support/options.json +21 -0
- data/spec/support/options_app.rb +15 -0
- data/spec/support/pact_helper.rb +57 -0
- data/spec/support/shared_examples_for_request.rb +94 -0
- data/spec/support/spec_support.rb +20 -0
- data/spec/support/stubbing.json +22 -0
- data/spec/support/stubbing_using_allow.rb +29 -0
- data/spec/support/term.json +48 -0
- data/spec/support/test_app_fail.json +41 -2
- data/spec/support/test_app_pass.json +19 -2
- data/spec/support/test_app_with_right_content_type_differ.json +23 -0
- data/tasks/pact-test.rake +98 -8
- data/tasks/spec.rake +8 -0
- metadata +393 -95
- data/lib/pact/app.rb +0 -32
- data/lib/pact/consumer/configuration_dsl.rb +0 -71
- data/lib/pact/consumer/dsl.rb +0 -98
- data/lib/pact/consumer/interaction.rb +0 -70
- data/lib/pact/consumer/run_condor.rb +0 -4
- data/lib/pact/consumer/run_mock_contract_service.rb +0 -13
- data/lib/pact/consumer/service_consumer.rb +0 -22
- data/lib/pact/consumer/service_producer.rb +0 -23
- data/lib/pact/json_warning.rb +0 -23
- data/lib/pact/producer/configuration_dsl.rb +0 -62
- data/lib/pact/producer/matchers.rb +0 -22
- data/lib/pact/producer/pact_spec_runner.rb +0 -57
- data/lib/pact/producer/producer_state.rb +0 -81
- data/lib/pact/producer/rspec.rb +0 -127
- data/lib/pact/producer/test_methods.rb +0 -89
- data/lib/pact/producer.rb +0 -1
- data/lib/pact/rake_task.rb +0 -64
- data/lib/pact/request.rb +0 -109
- data/lib/pact/verification_task.rb +0 -57
- data/spec/integration/pact/configuration_spec.rb +0 -65
- data/spec/lib/pact/consumer/dsl_spec.rb +0 -52
- data/spec/lib/pact/consumer/interaction_spec.rb +0 -108
- data/spec/lib/pact/consumer/mock_service_spec.rb +0 -147
- data/spec/lib/pact/consumer_contract_spec.rb +0 -125
- data/spec/lib/pact/producer/configuration_dsl_spec.rb +0 -101
- data/spec/lib/pact/producer/producer_state_spec.rb +0 -103
- data/spec/lib/pact/producer/rspec_spec.rb +0 -48
- data/spec/lib/pact/verification_task_spec.rb +0 -64
- data/spec/support/pact_rake_support.rb +0 -41
|
@@ -1,354 +1,500 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
-
require 'pact/term'
|
|
3
2
|
require 'pact/matchers'
|
|
3
|
+
require 'pact/consumer_contract/headers'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
include Pact::Matchers
|
|
5
|
+
module Pact::Matchers
|
|
7
6
|
|
|
8
|
-
describe
|
|
9
|
-
|
|
10
|
-
{a: 'a string', b: 1, c: nil, d: [{e: 'thing'}], f: {g: 10}}
|
|
11
|
-
}
|
|
7
|
+
describe Pact::Matchers do
|
|
8
|
+
include Pact::Matchers
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
expect(structure_diff(expected, actual)).to be_empty
|
|
17
|
-
end
|
|
18
|
-
end
|
|
10
|
+
# TODO this is an integration test
|
|
11
|
+
describe 'matching headers' do
|
|
12
|
+
let(:expected) { Pact::Headers.new('Content-Type' => 'application/hippo')}
|
|
19
13
|
|
|
20
|
-
|
|
21
|
-
let(:expected) { {a: 1} }
|
|
22
|
-
#let(:difference) { {a: {expected: 'Fixnum (eg. 1)', actual: 'String ("a string")'}} }
|
|
23
|
-
let(:difference) { {a: {expected: {:class => Fixnum, eg: 1 } , actual: {:class => String, :value => 'a string'}}} }
|
|
14
|
+
context "when the headers match in a case insensitive way" do
|
|
24
15
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
context "when the values match" do
|
|
17
|
+
let(:actual) { Pact::Headers.new('CONTENT-TYPE' => 'application/hippo')}
|
|
18
|
+
it "returns an empty diff" do
|
|
19
|
+
expect(diff(expected, actual)).to be_empty
|
|
20
|
+
end
|
|
29
21
|
end
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
|
|
23
|
+
context "when the header values do not match" do
|
|
24
|
+
let(:actual) { Pact::Headers.new('CONTENT-TYPE' => 'application/alligator')}
|
|
25
|
+
let(:difference) { {"Content-Type" => Difference.new('application/hippo', 'application/alligator')} }
|
|
26
|
+
it "returns the diff" do
|
|
27
|
+
expect(diff(expected, actual)).to eq difference
|
|
28
|
+
end
|
|
36
29
|
end
|
|
37
30
|
end
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
let(:difference) { {:a=>{:expected=>{:class=>Fixnum, :eg=>1}, :actual=>{:class=>Array, :value=>[1]}}} }
|
|
48
|
-
it "returns the diff" do
|
|
49
|
-
expect(structure_diff(expected, actual)).to eq difference
|
|
50
|
-
end
|
|
31
|
+
|
|
32
|
+
context "when the headers do not match" do
|
|
33
|
+
|
|
34
|
+
let(:actual) { Pact::Headers.new('Content-Length' => '1')}
|
|
35
|
+
let(:difference) { {"Content-Type" => Difference.new('application/hippo', Pact::KeyNotFound.new)} }
|
|
36
|
+
it "returns a diff" do
|
|
37
|
+
expect(diff(expected, actual)).to eq difference
|
|
38
|
+
end
|
|
39
|
+
|
|
51
40
|
end
|
|
41
|
+
|
|
52
42
|
end
|
|
53
43
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
context
|
|
57
|
-
let(:
|
|
58
|
-
let(:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
:actual=> { :class=>Fixnum, :value=>1} }
|
|
63
|
-
}
|
|
64
|
-
]
|
|
65
|
-
}
|
|
66
|
-
it "returns the diff" do
|
|
67
|
-
expect(structure_diff(expected, actual)).to eq difference
|
|
44
|
+
describe 'matching with something like' do
|
|
45
|
+
|
|
46
|
+
context 'when the actual is something like the expected' do
|
|
47
|
+
let(:expected) { Pact::SomethingLike.new( { a: 1 } ) }
|
|
48
|
+
let(:actual) { { a: 2} }
|
|
49
|
+
|
|
50
|
+
it 'returns an empty diff' do
|
|
51
|
+
expect(diff(expected, actual)).to eq({})
|
|
68
52
|
end
|
|
53
|
+
|
|
69
54
|
end
|
|
55
|
+
|
|
70
56
|
end
|
|
71
57
|
|
|
58
|
+
describe 'option {allow_unexpected_keys: false}' do
|
|
59
|
+
context "when an unexpected key is found" do
|
|
60
|
+
let(:expected) { {:a => 1} }
|
|
61
|
+
let(:actual) { {:a => 1, :b => 2} }
|
|
62
|
+
let(:difference) { {:b => Difference.new(Pact::UnexpectedKey.new, 2 )} }
|
|
63
|
+
it "returns it in the diff" do
|
|
64
|
+
expect(diff(expected, actual, allow_unexpected_keys: false)).to eq difference
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
72
68
|
|
|
73
|
-
|
|
69
|
+
describe "expecting key to be present with nil value and not finding key" do
|
|
74
70
|
let(:expected) { {a: nil} }
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
expect(structure_diff(expected, actual)).to eq difference
|
|
80
|
-
end
|
|
71
|
+
let(:actual) { {} }
|
|
72
|
+
let(:difference) { {a: Difference.new(nil, Pact::KeyNotFound.new )} }
|
|
73
|
+
it "returns the key in the diff" do
|
|
74
|
+
expect(diff(expected, actual)).to eq difference
|
|
81
75
|
end
|
|
82
76
|
end
|
|
83
77
|
|
|
84
|
-
|
|
85
|
-
let(:expected) { {a:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
end
|
|
92
|
-
end
|
|
78
|
+
describe "expecting a string matching a regexp and not finding key" do
|
|
79
|
+
let(:expected) { {a: /b/} }
|
|
80
|
+
let(:actual) { {} }
|
|
81
|
+
let(:difference) { {:a=> RegexpDifference.new(/b/, Pact::KeyNotFound.new) } }
|
|
82
|
+
it "returns the diff" do
|
|
83
|
+
expect(diff(expected, actual)).to eq difference
|
|
84
|
+
end
|
|
93
85
|
end
|
|
94
|
-
end
|
|
95
86
|
|
|
96
|
-
|
|
87
|
+
describe 'type_diff' do
|
|
88
|
+
let(:expected) {
|
|
89
|
+
{a: 'a string', b: 1, c: nil, d: [{e: 'thing'}], f: {g: 10}, h: false}
|
|
90
|
+
}
|
|
97
91
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
92
|
+
context "when the classes match" do
|
|
93
|
+
let(:actual) { {a: 'another string', b: 2, c: nil, d: [{e: 'something'}], f: {g: 100}, h: true} }
|
|
94
|
+
let(:difference) { {} }
|
|
95
|
+
it "returns an empty hash" do
|
|
96
|
+
expect(type_diff(expected, actual)).to eq difference
|
|
97
|
+
end
|
|
98
|
+
end
|
|
101
99
|
|
|
102
|
-
context
|
|
100
|
+
context "when a key is not found" do
|
|
101
|
+
let(:actual) { {a: 'blah'} }
|
|
102
|
+
let(:expected) { {b: 'blah'} }
|
|
103
|
+
let(:difference) { {:b=>TypeDifference.new(Pact::ExpectedType.new("blah"), Pact::KeyNotFound.new)} }
|
|
104
|
+
it "returns the difference" do
|
|
105
|
+
expect(type_diff(expected, actual)).to eq difference
|
|
106
|
+
end
|
|
107
|
+
end
|
|
103
108
|
|
|
104
|
-
|
|
109
|
+
context "when a number is expected" do
|
|
110
|
+
let(:expected) { {a: 1} }
|
|
111
|
+
let(:difference) { {a: TypeDifference.new(Pact::ExpectedType.new(1) , Pact::ActualType.new('a string'))} }
|
|
105
112
|
|
|
106
|
-
|
|
107
|
-
|
|
113
|
+
context "and a string is found" do
|
|
114
|
+
let(:actual) { {a: 'a string'}}
|
|
115
|
+
it "returns the diff" do
|
|
116
|
+
expect(type_diff(expected, actual)).to eq difference
|
|
117
|
+
end
|
|
108
118
|
end
|
|
119
|
+
context "and nil is found" do
|
|
120
|
+
let(:actual) { {a: nil}}
|
|
121
|
+
let(:difference ) { {a: TypeDifference.new(Pact::ExpectedType.new(1), Pact::ActualType.new(nil)) } }
|
|
122
|
+
it "returns the diff" do
|
|
123
|
+
expect(type_diff(expected, actual)).to eq difference
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
context "and a hash is found" do
|
|
127
|
+
let(:actual) { {a: {b: 1}} }
|
|
128
|
+
let(:difference) { {:a=>TypeDifference.new(Pact::ExpectedType.new(1), Pact::ActualType.new({:b=>1})) } }
|
|
129
|
+
it "returns the diff" do
|
|
130
|
+
expect(type_diff(expected, actual)).to eq difference
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
context "and an array is found" do
|
|
134
|
+
let(:actual) { {a: [1] } }
|
|
135
|
+
let(:difference) { {:a=>TypeDifference.new(Pact::ExpectedType.new(1), Pact::ActualType.new([1]))}}
|
|
136
|
+
it "returns the diff" do
|
|
137
|
+
expect(type_diff(expected, actual)).to eq difference
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
109
141
|
|
|
142
|
+
context "when an array is expected" do
|
|
143
|
+
let(:expected) { [{name: 'Fred'}, {name: 'Mary'}] }
|
|
144
|
+
context "when an item with differing class values is found" do
|
|
145
|
+
let(:actual) { [{name: 'Fred'}, {name: 1}] }
|
|
146
|
+
let(:difference) { [
|
|
147
|
+
Pact::Matchers::NO_DIFF_INDICATOR,
|
|
148
|
+
{:name =>
|
|
149
|
+
TypeDifference.new(Pact::ExpectedType.new("Mary"), Pact::ActualType.new(1))
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
it "returns the diff" do
|
|
154
|
+
expect(type_diff(expected, actual)).to eq difference
|
|
155
|
+
end
|
|
156
|
+
end
|
|
110
157
|
end
|
|
111
158
|
|
|
112
|
-
end
|
|
113
159
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
160
|
+
context "when nil is expected" do
|
|
161
|
+
let(:expected) { {a: nil} }
|
|
162
|
+
context "and a string is found" do
|
|
163
|
+
let(:actual) { {a: 'a string'} }
|
|
164
|
+
let(:difference) { {:a=>TypeDifference.new(Pact::ExpectedType.new(nil), Pact::ActualType.new("a string")) } }
|
|
165
|
+
it "returns the diff" do
|
|
166
|
+
expect(type_diff(expected, actual)).to eq difference
|
|
167
|
+
end
|
|
121
168
|
end
|
|
122
169
|
end
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
let(:
|
|
126
|
-
|
|
127
|
-
|
|
170
|
+
|
|
171
|
+
context "when a term is expected" do
|
|
172
|
+
let(:expected) { {a: Pact::Term.new(:matcher => /p/, :generate => 'apple')} }
|
|
173
|
+
context "and a non matching string is found" do
|
|
174
|
+
let(:actual) { {a: 'banana'} }
|
|
175
|
+
let(:difference) { {:a=>Pact::Matchers::RegexpDifference.new(/p/,"banana")} }
|
|
176
|
+
it "returns the diff" do
|
|
177
|
+
expect(type_diff(expected, actual)).to eq difference
|
|
178
|
+
end
|
|
128
179
|
end
|
|
129
180
|
end
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
let(:
|
|
133
|
-
|
|
134
|
-
|
|
181
|
+
|
|
182
|
+
context "when a term is expected inside a missing hash" do
|
|
183
|
+
let(:expected) { {a: {b: Pact::Term.new(:matcher => /p/, :generate => 'apple')}} }
|
|
184
|
+
context "and a non matching value is found" do
|
|
185
|
+
let(:actual) { {a: nil} }
|
|
186
|
+
let(:difference) { {a: Difference.new({b: /p/}, nil)} }
|
|
187
|
+
it "returns the diff with the regexp unpacked" do
|
|
188
|
+
expect(type_diff(expected, actual)).to eq difference
|
|
189
|
+
end
|
|
135
190
|
end
|
|
136
191
|
end
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
let(:
|
|
140
|
-
|
|
141
|
-
|
|
192
|
+
|
|
193
|
+
context "when unexpected keys are allowed" do
|
|
194
|
+
let(:expected) { { a: 'b' } }
|
|
195
|
+
let(:actual) { {a: 'c', d: 'e'} }
|
|
196
|
+
let(:difference) { {} }
|
|
197
|
+
it "returns the diff" do
|
|
198
|
+
expect(type_diff(expected, actual, allow_unexpected_keys: true)).to eq difference
|
|
142
199
|
end
|
|
143
200
|
end
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
201
|
+
|
|
202
|
+
context "when unexpected keys are not allowed" do
|
|
203
|
+
let(:expected) { { a: 'b' } }
|
|
204
|
+
let(:actual) { {a: 'c', d: 'e'} }
|
|
205
|
+
let(:difference) { {d: Difference.new(Pact::UnexpectedKey.new, 'e')} }
|
|
206
|
+
it "returns the diff" do
|
|
207
|
+
expect(type_diff(expected, actual, allow_unexpected_keys: false)).to eq difference
|
|
148
208
|
end
|
|
149
209
|
end
|
|
150
210
|
end
|
|
151
211
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
context "when
|
|
155
|
-
|
|
156
|
-
let(:
|
|
157
|
-
|
|
158
|
-
|
|
212
|
+
describe 'diffing' do
|
|
213
|
+
|
|
214
|
+
context "when expected is longer than the actual" do
|
|
215
|
+
subject { [1,2,3] }
|
|
216
|
+
let(:actual) { [1,2]}
|
|
217
|
+
let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, Pact::Matchers::NO_DIFF_INDICATOR, Difference.new(3, Pact::IndexNotFound.new)] }
|
|
218
|
+
it 'returns the diff' do
|
|
219
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
159
220
|
end
|
|
160
221
|
end
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
222
|
+
|
|
223
|
+
context "when the different index is in the middle of an array" do
|
|
224
|
+
subject { [1,2,3] }
|
|
225
|
+
let(:actual) { [1,7,3]}
|
|
226
|
+
let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, Difference.new(2, 7), Pact::Matchers::NO_DIFF_INDICATOR] }
|
|
227
|
+
it 'returns the diff' do
|
|
228
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
166
229
|
end
|
|
167
230
|
end
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
231
|
+
|
|
232
|
+
context "when actual array is longer than the expected" do
|
|
233
|
+
subject { [1] }
|
|
234
|
+
let(:actual) { [1,2]}
|
|
235
|
+
let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, Difference.new(Pact::UnexpectedIndex.new, 2)] }
|
|
236
|
+
it 'returns the diff' do
|
|
237
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
173
238
|
end
|
|
174
239
|
end
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
240
|
+
|
|
241
|
+
context 'where an expected value is a non-empty string' do
|
|
242
|
+
|
|
243
|
+
subject { {:a => 'a', :b => 'b'} }
|
|
244
|
+
|
|
245
|
+
context 'and the actual value is an empty string' do
|
|
246
|
+
|
|
247
|
+
let(:actual) { {:a => 'a', :b => ''} }
|
|
248
|
+
|
|
249
|
+
it 'includes this in the diff' do
|
|
250
|
+
expect(diff(subject, actual)).to eq({:b => Difference.new('b', '')})
|
|
251
|
+
end
|
|
252
|
+
|
|
180
253
|
end
|
|
254
|
+
|
|
181
255
|
end
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
256
|
+
|
|
257
|
+
context "when the expected value is a hash" do
|
|
258
|
+
subject { {a: 'b'} }
|
|
259
|
+
context "when the actual value is an array" do
|
|
260
|
+
let(:actual) { [1] }
|
|
261
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
262
|
+
it "should return the diff" do
|
|
263
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
context "when the actual value is an hash" do
|
|
267
|
+
let(:actual) { {b: 'c'} }
|
|
268
|
+
let(:difference) { { a: Difference.new("b",Pact::KeyNotFound.new)} }
|
|
269
|
+
it "should return the diff" do
|
|
270
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
context "when the actual value is an number" do
|
|
274
|
+
let(:actual) { 1 }
|
|
275
|
+
let(:difference) { Difference.new({a: "b"}, 1) }
|
|
276
|
+
it "should return the diff" do
|
|
277
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
context "when the actual value is a string" do
|
|
281
|
+
let(:actual) { "Thing" }
|
|
282
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
283
|
+
it "should return the diff" do
|
|
284
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
context "when the actual value is the same" do
|
|
288
|
+
let (:actual) { {a: 'b'} }
|
|
289
|
+
it "should return an empty hash" do
|
|
290
|
+
expect(diff(subject, actual)).to eq({})
|
|
291
|
+
end
|
|
186
292
|
end
|
|
187
293
|
end
|
|
188
|
-
end
|
|
189
294
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
295
|
+
context "when the expected value is an array" do
|
|
296
|
+
subject { [1] }
|
|
297
|
+
context "when the actual value is an array" do
|
|
298
|
+
let(:actual) { [2] }
|
|
299
|
+
let(:difference) { [Difference.new(1, 2)] }
|
|
300
|
+
it "should return the diff" do
|
|
301
|
+
expect(diff(subject, actual)).to eq difference
|
|
302
|
+
end
|
|
197
303
|
end
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
304
|
+
context "when the actual value is an hash" do
|
|
305
|
+
let(:actual) { {b: 'c'} }
|
|
306
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
307
|
+
it "should return the diff" do
|
|
308
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
309
|
+
end
|
|
204
310
|
end
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
311
|
+
context "when the actual value is an number" do
|
|
312
|
+
let(:actual) { 1 }
|
|
313
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
314
|
+
it "should return the diff" do
|
|
315
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
316
|
+
end
|
|
211
317
|
end
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
318
|
+
context "when the actual value is a string" do
|
|
319
|
+
let(:actual) { "Thing" }
|
|
320
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
321
|
+
it "should return the diff" do
|
|
322
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
323
|
+
end
|
|
218
324
|
end
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
325
|
+
context "when the actual value is the same" do
|
|
326
|
+
let (:actual) { [1] }
|
|
327
|
+
it "should return an empty hash" do
|
|
328
|
+
expect(diff(subject, actual)).to eql({})
|
|
329
|
+
end
|
|
224
330
|
end
|
|
225
331
|
end
|
|
226
|
-
end
|
|
227
332
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
333
|
+
context "when the expected value is a string" do
|
|
334
|
+
subject { "Thing"}
|
|
335
|
+
context "when the actual value is an array" do
|
|
336
|
+
let(:actual) { [2] }
|
|
337
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
338
|
+
it "should return the diff" do
|
|
339
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
340
|
+
end
|
|
235
341
|
end
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
342
|
+
context "when the actual value is an hash" do
|
|
343
|
+
let(:actual) { {b: 'c'} }
|
|
344
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
345
|
+
it "should return the diff" do
|
|
346
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
347
|
+
end
|
|
241
348
|
end
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
349
|
+
context "when the actual value is an number" do
|
|
350
|
+
let(:actual) { 1 }
|
|
351
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
352
|
+
it "should return the diff" do
|
|
353
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
354
|
+
end
|
|
247
355
|
end
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
356
|
+
context "when the actual value is a string" do
|
|
357
|
+
let(:actual) { "Another Thing" }
|
|
358
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
359
|
+
it "should return the diff" do
|
|
360
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
361
|
+
end
|
|
362
|
+
end
|
|
363
|
+
context "when the actual value is the same" do
|
|
364
|
+
let (:actual) { "Thing" }
|
|
365
|
+
it "should return an empty hash" do
|
|
366
|
+
expect(diff(subject, actual)).to eq({})
|
|
367
|
+
end
|
|
253
368
|
end
|
|
254
369
|
end
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
370
|
+
|
|
371
|
+
context "when the expected value is a number" do
|
|
372
|
+
subject { 1 }
|
|
373
|
+
let(:difference) { Difference.new(subject, actual) }
|
|
374
|
+
context "when the actual value is an array" do
|
|
375
|
+
let(:actual) { [2] }
|
|
376
|
+
it "should return the diff" do
|
|
377
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
378
|
+
end
|
|
379
|
+
end
|
|
380
|
+
context "when the actual value is an hash" do
|
|
381
|
+
let(:actual) { {b: 'c'} }
|
|
382
|
+
it "should return the diff" do
|
|
383
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
384
|
+
end
|
|
385
|
+
end
|
|
386
|
+
context "when the actual value is an number" do
|
|
387
|
+
let(:actual) { 2 }
|
|
388
|
+
it "should return the diff" do
|
|
389
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
390
|
+
end
|
|
391
|
+
end
|
|
392
|
+
context "when the actual value is a string" do
|
|
393
|
+
let(:actual) { "Another Thing" }
|
|
394
|
+
it "should return the diff" do
|
|
395
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
396
|
+
end
|
|
397
|
+
end
|
|
398
|
+
context "when the actual value is the same" do
|
|
399
|
+
let (:actual) { 1 }
|
|
400
|
+
it "should return an empty hash" do
|
|
401
|
+
expect(diff(subject, actual)).to eq({})
|
|
402
|
+
end
|
|
259
403
|
end
|
|
260
404
|
end
|
|
261
|
-
end
|
|
262
405
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
end
|
|
406
|
+
context "when the expected value is a String matcher" do
|
|
266
407
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
context "when the expected value is an array with a matcher" do
|
|
271
|
-
|
|
272
|
-
end
|
|
273
|
-
context "when the expected value is a hash with a matcher" do
|
|
274
|
-
|
|
275
|
-
end
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
context "when the expected value is a Number matcher" do
|
|
276
411
|
|
|
277
|
-
context "when an expected value is nil but not nil is found" do
|
|
278
|
-
subject { {a: nil} }
|
|
279
|
-
let(:actual) { {a: 'blah'} }
|
|
280
|
-
let(:difference) { {:a=>{:expected=>nil, :actual=>"blah"}} }
|
|
281
|
-
it "should return the diff" do
|
|
282
|
-
expect(diff(subject, actual)).to eql(difference)
|
|
283
412
|
end
|
|
284
|
-
|
|
413
|
+
context "when the expected value is an array with a matcher" do
|
|
285
414
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
let(:actual) { {a: {b: { c: [1,2]}, d: { e: 'food'}}, f: "thing"} }
|
|
289
|
-
let(:difference) { {:a=>{:d=>{:e=>{:expected=>/a/, :actual=>"food"}}}, :f=>{:expected=>1, :actual=>"thing"}, :g=>{:expected=>{:h=>99}, :actual=>nil}} }
|
|
415
|
+
end
|
|
416
|
+
context "when the expected value is a hash with a matcher" do
|
|
290
417
|
|
|
291
|
-
it 'should return the diff' do
|
|
292
|
-
expect(diff(subject, actual)).to eql(difference)
|
|
293
418
|
end
|
|
294
|
-
end
|
|
295
419
|
|
|
420
|
+
context "when an expected value is nil but not nil is found" do
|
|
421
|
+
subject { {a: nil} }
|
|
422
|
+
let(:actual) { {a: 'blah'} }
|
|
423
|
+
let(:difference) { {:a=>Difference.new(nil, "blah")} }
|
|
424
|
+
it "should return the diff" do
|
|
425
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
426
|
+
end
|
|
427
|
+
end
|
|
296
428
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
429
|
+
context "a deep mismatch" do
|
|
430
|
+
subject { {a: {b: { c: [1,2]}, d: { e: Pact::Term.new(matcher: /a/, generate: 'apple')}}, f: 1, g: {h: 99}} }
|
|
431
|
+
let(:actual) { {a: {b: { c: [1,2]}, d: { e: 'food'}}, f: "thing"} }
|
|
432
|
+
let(:difference) { {:a=>{:d=>{:e=> RegexpDifference.new(/a/, "food")}},
|
|
433
|
+
:f=> Difference.new(1, "thing"),
|
|
434
|
+
:g=>Difference.new({:h=>99}, Pact::KeyNotFound.new)} }
|
|
300
435
|
|
|
301
|
-
|
|
302
|
-
|
|
436
|
+
it 'should return the diff' do
|
|
437
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
438
|
+
end
|
|
303
439
|
end
|
|
304
|
-
end
|
|
305
440
|
|
|
306
|
-
context "where an array is expected at a key inside a hash, but a hash is found" do
|
|
307
|
-
subject { {:a => [1,2,3]} }
|
|
308
|
-
let(:actual) { {:a => {:b => 1} } }
|
|
309
441
|
|
|
310
|
-
|
|
311
|
-
|
|
442
|
+
context "where a Pact::Term is found that matches the actual value" do
|
|
443
|
+
subject { {:a => Pact::Term.new(:matcher => /a/, :generate => 'apple')} }
|
|
444
|
+
let(:actual) { {:a => "apple" } }
|
|
445
|
+
|
|
446
|
+
it 'does not include this in the diff' do
|
|
447
|
+
expect(diff(subject, actual)).to eq({})
|
|
448
|
+
end
|
|
312
449
|
end
|
|
313
|
-
end
|
|
314
450
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
451
|
+
context "where an array is expected at a key inside a hash, but a hash is found" do
|
|
452
|
+
subject { {:a => [1,2,3]} }
|
|
453
|
+
let(:actual) { {:a => {:b => 1} } }
|
|
318
454
|
|
|
319
|
-
|
|
320
|
-
|
|
455
|
+
it 'includes this in the diff' do
|
|
456
|
+
expect(diff(subject, actual)).to eq({:a => Difference.new([1,2,3], {:b => 1})})
|
|
457
|
+
end
|
|
321
458
|
end
|
|
322
|
-
end
|
|
323
459
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
460
|
+
context "where an array is expected, but a hash is found" do
|
|
461
|
+
subject { {:a => :b} }
|
|
462
|
+
let(:actual) { [4,5,6] }
|
|
327
463
|
|
|
328
|
-
|
|
329
|
-
|
|
464
|
+
it 'includes this in the diff' do
|
|
465
|
+
expect(diff(subject, actual)).to eq(Difference.new({:a => :b}, [4,5,6] ))
|
|
466
|
+
end
|
|
330
467
|
end
|
|
331
|
-
end
|
|
332
468
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, {:expected=>5, :actual=>6}, {:expected=>6, :actual=>7}] }
|
|
469
|
+
context "where a hash is expected, but array is found" do
|
|
470
|
+
subject { [4,5,6] }
|
|
471
|
+
let(:actual) { {:a => :b} }
|
|
337
472
|
|
|
338
|
-
|
|
339
|
-
|
|
473
|
+
it 'includes this in the diff' do
|
|
474
|
+
expect(diff(subject, actual)).to eq(Difference.new([4,5,6],{:a => :b}))
|
|
475
|
+
end
|
|
340
476
|
end
|
|
341
|
-
end
|
|
342
477
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
478
|
+
context "when two different arrays are found" do
|
|
479
|
+
subject { [4,5,6] }
|
|
480
|
+
let(:actual) { [4,6,7] }
|
|
481
|
+
let(:difference) { [Pact::Matchers::NO_DIFF_INDICATOR, Difference.new(5, 6), Difference.new(6, 7)] }
|
|
346
482
|
|
|
347
|
-
|
|
348
|
-
|
|
483
|
+
it 'includes this in the diff' do
|
|
484
|
+
expect(diff(subject, actual)).to eq(difference)
|
|
485
|
+
end
|
|
349
486
|
end
|
|
487
|
+
|
|
488
|
+
context "when an array that matches the Pact::Term is found" do
|
|
489
|
+
subject { [Pact::Term.new(:matcher => /4/, :generate => '4'),"5","6"] }
|
|
490
|
+
let(:actual) { ["4","5","6"] }
|
|
491
|
+
|
|
492
|
+
it 'includes this in the diff' do
|
|
493
|
+
expect(diff(subject, actual)).to eq({})
|
|
494
|
+
end
|
|
495
|
+
end
|
|
496
|
+
|
|
350
497
|
end
|
|
351
498
|
|
|
352
499
|
end
|
|
353
|
-
|
|
354
500
|
end
|