pact 1.3.3 → 1.4.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.
- data/CHANGELOG.md +37 -1
- data/lib/pact/cli.rb +0 -26
- data/lib/pact/consumer/configuration/configuration_extensions.rb +51 -0
- data/lib/pact/consumer/configuration/mock_service.rb +2 -1
- data/lib/pact/consumer/configuration.rb +0 -1
- data/lib/pact/consumer/consumer_contract_builder.rb +3 -3
- data/lib/pact/consumer/interaction_builder.rb +3 -5
- data/lib/pact/doc/interaction_view_model.rb +9 -6
- data/lib/pact/doc/sort_interactions.rb +1 -1
- data/lib/pact/provider/configuration/configuration_extension.rb +0 -9
- data/lib/pact/provider/rspec.rb +11 -9
- data/lib/pact/version.rb +1 -1
- data/lib/pact.rb +6 -5
- data/pact.gemspec +6 -2
- metadata +57 -304
- data/.gitignore +0 -29
- data/.rspec +0 -2
- data/.ruby-version +0 -1
- data/.travis.yml +0 -8
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -86
- data/README.md +0 -313
- data/Rakefile +0 -9
- data/config.ru +0 -3
- data/documentation/README.md +0 -13
- data/documentation/configuration.md +0 -166
- 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 +0 -14
- data/example/animal-service/Gemfile.lock +0 -69
- data/example/animal-service/Rakefile +0 -5
- data/example/animal-service/config.ru +0 -3
- data/example/animal-service/db/animal_db.sqlite3 +0 -0
- data/example/animal-service/lib/animal_service/animal_repository.rb +0 -12
- data/example/animal-service/lib/animal_service/api.rb +0 -28
- data/example/animal-service/lib/animal_service/db.rb +0 -5
- data/example/animal-service/spec/service_consumers/pact_helper.rb +0 -11
- data/example/animal-service/spec/service_consumers/provider_states_for_zoo_app.rb +0 -26
- data/example/zoo-app/Gemfile +0 -12
- data/example/zoo-app/Gemfile.lock +0 -63
- data/example/zoo-app/Rakefile +0 -5
- data/example/zoo-app/doc/pacts/markdown/README.md +0 -3
- data/example/zoo-app/doc/pacts/markdown/Zoo App - Animal Service.md +0 -75
- data/example/zoo-app/lib/zoo_app/animal_service_client.rb +0 -40
- data/example/zoo-app/lib/zoo_app/models/alligator.rb +0 -15
- data/example/zoo-app/spec/pacts/zoo_app-animal_service.json +0 -67
- data/example/zoo-app/spec/service_providers/animal_service_client_spec.rb +0 -71
- data/example/zoo-app/spec/service_providers/pact_helper.rb +0 -15
- data/example/zoo-app/spec/spec_helper.rb +0 -6
- data/lib/pact/configuration.rb +0 -195
- data/lib/pact/consumer/app_manager.rb +0 -158
- data/lib/pact/consumer/interactions_filter.rb +0 -48
- data/lib/pact/consumer/mock_service/app.rb +0 -82
- data/lib/pact/consumer/mock_service/interaction_delete.rb +0 -33
- data/lib/pact/consumer/mock_service/interaction_list.rb +0 -76
- data/lib/pact/consumer/mock_service/interaction_mismatch.rb +0 -73
- data/lib/pact/consumer/mock_service/interaction_post.rb +0 -31
- data/lib/pact/consumer/mock_service/interaction_replay.rb +0 -139
- data/lib/pact/consumer/mock_service/log_get.rb +0 -28
- data/lib/pact/consumer/mock_service/missing_interactions_get.rb +0 -30
- data/lib/pact/consumer/mock_service/mock_service_administration_endpoint.rb +0 -31
- data/lib/pact/consumer/mock_service/pact_post.rb +0 -33
- data/lib/pact/consumer/mock_service/rack_request_helper.rb +0 -51
- data/lib/pact/consumer/mock_service/verification_get.rb +0 -68
- data/lib/pact/consumer/mock_service.rb +0 -2
- data/lib/pact/consumer/mock_service_client.rb +0 -65
- data/lib/pact/consumer/mock_service_interaction_expectation.rb +0 -37
- data/lib/pact/consumer/request.rb +0 -27
- data/lib/pact/consumer/server.rb +0 -90
- data/lib/pact/consumer_contract/consumer_contract.rb +0 -115
- data/lib/pact/consumer_contract/consumer_contract_writer.rb +0 -84
- data/lib/pact/consumer_contract/file_name.rb +0 -19
- data/lib/pact/consumer_contract/headers.rb +0 -51
- data/lib/pact/consumer_contract/interaction.rb +0 -67
- data/lib/pact/consumer_contract/pact_file.rb +0 -24
- data/lib/pact/consumer_contract/request.rb +0 -73
- data/lib/pact/consumer_contract/service_consumer.rb +0 -28
- data/lib/pact/consumer_contract/service_provider.rb +0 -28
- data/lib/pact/consumer_contract.rb +0 -1
- data/lib/pact/logging.rb +0 -14
- data/lib/pact/matchers/actual_type.rb +0 -16
- data/lib/pact/matchers/base_difference.rb +0 -37
- data/lib/pact/matchers/differ.rb +0 -153
- data/lib/pact/matchers/difference.rb +0 -13
- data/lib/pact/matchers/difference_indicator.rb +0 -26
- data/lib/pact/matchers/embedded_diff_formatter.rb +0 -62
- data/lib/pact/matchers/expected_type.rb +0 -35
- data/lib/pact/matchers/index_not_found.rb +0 -15
- data/lib/pact/matchers/list_diff_formatter.rb +0 -101
- data/lib/pact/matchers/matchers.rb +0 -139
- data/lib/pact/matchers/no_diff_indicator.rb +0 -18
- data/lib/pact/matchers/regexp_difference.rb +0 -13
- data/lib/pact/matchers/type_difference.rb +0 -16
- data/lib/pact/matchers/unexpected_index.rb +0 -11
- data/lib/pact/matchers/unexpected_key.rb +0 -11
- data/lib/pact/matchers/unix_diff_formatter.rb +0 -114
- data/lib/pact/matchers.rb +0 -1
- data/lib/pact/reification.rb +0 -28
- data/lib/pact/rspec.rb +0 -53
- data/lib/pact/shared/active_support_support.rb +0 -51
- data/lib/pact/shared/dsl.rb +0 -76
- data/lib/pact/shared/jruby_support.rb +0 -18
- data/lib/pact/shared/json_differ.rb +0 -15
- data/lib/pact/shared/key_not_found.rb +0 -15
- data/lib/pact/shared/null_expectation.rb +0 -31
- data/lib/pact/shared/request.rb +0 -80
- data/lib/pact/shared/text_differ.rb +0 -14
- data/lib/pact/something_like.rb +0 -49
- data/lib/pact/symbolize_keys.rb +0 -12
- data/lib/pact/term.rb +0 -85
- data/scratchpad.rb +0 -52
- data/spec/features/consumption_spec.rb +0 -114
- data/spec/features/production_spec.rb +0 -155
- data/spec/features/provider_states/zebras.rb +0 -28
- data/spec/integration/consumer_spec.rb +0 -212
- data/spec/integration/pact/consumer_configuration_spec.rb +0 -66
- data/spec/integration/pact/provider_configuration_spec.rb +0 -25
- data/spec/lib/pact/cli_spec.rb +0 -47
- data/spec/lib/pact/configuration_spec.rb +0 -297
- data/spec/lib/pact/consumer/app_manager_spec.rb +0 -41
- data/spec/lib/pact/consumer/configuration_spec.rb +0 -57
- data/spec/lib/pact/consumer/consumer_contract_builder_spec.rb +0 -69
- data/spec/lib/pact/consumer/interaction_builder_spec.rb +0 -91
- data/spec/lib/pact/consumer/interactions_spec.rb +0 -64
- data/spec/lib/pact/consumer/mock_service/app_spec.rb +0 -52
- data/spec/lib/pact/consumer/mock_service/interaction_list_spec.rb +0 -78
- data/spec/lib/pact/consumer/mock_service/interaction_mismatch_spec.rb +0 -70
- data/spec/lib/pact/consumer/mock_service/interaction_replay_spec.rb +0 -12
- data/spec/lib/pact/consumer/mock_service/rack_request_helper_spec.rb +0 -88
- data/spec/lib/pact/consumer/mock_service/verification_get_spec.rb +0 -142
- data/spec/lib/pact/consumer/mock_service_client_spec.rb +0 -88
- data/spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb +0 -54
- data/spec/lib/pact/consumer/request_spec.rb +0 -24
- data/spec/lib/pact/consumer/service_consumer_spec.rb +0 -11
- data/spec/lib/pact/consumer_contract/active_support_support_spec.rb +0 -58
- data/spec/lib/pact/consumer_contract/consumer_contract_spec.rb +0 -180
- data/spec/lib/pact/consumer_contract/consumer_contract_writer_spec.rb +0 -111
- data/spec/lib/pact/consumer_contract/headers_spec.rb +0 -107
- data/spec/lib/pact/consumer_contract/interaction_spec.rb +0 -107
- data/spec/lib/pact/consumer_contract/request_spec.rb +0 -329
- data/spec/lib/pact/doc/generator_spec.rb +0 -84
- data/spec/lib/pact/doc/interaction_view_model_spec.rb +0 -132
- data/spec/lib/pact/doc/markdown/consumer_contract_renderer_spec.rb +0 -29
- data/spec/lib/pact/doc/markdown/index_renderer_spec.rb +0 -29
- data/spec/lib/pact/matchers/differ_spec.rb +0 -214
- data/spec/lib/pact/matchers/difference_spec.rb +0 -22
- data/spec/lib/pact/matchers/embedded_diff_formatter_spec.rb +0 -90
- data/spec/lib/pact/matchers/index_not_found_spec.rb +0 -21
- data/spec/lib/pact/matchers/list_diff_formatter_spec.rb +0 -114
- data/spec/lib/pact/matchers/matchers_spec.rb +0 -500
- data/spec/lib/pact/matchers/regexp_difference_spec.rb +0 -20
- data/spec/lib/pact/matchers/type_difference_spec.rb +0 -34
- data/spec/lib/pact/matchers/unexpected_index_spec.rb +0 -20
- data/spec/lib/pact/matchers/unexpected_key_spec.rb +0 -20
- data/spec/lib/pact/matchers/unix_diff_formatter_spec.rb +0 -216
- data/spec/lib/pact/provider/configuration/configuration_extension_spec.rb +0 -30
- data/spec/lib/pact/provider/configuration/pact_verification_spec.rb +0 -43
- data/spec/lib/pact/provider/configuration/service_provider_config_spec.rb +0 -21
- data/spec/lib/pact/provider/configuration/service_provider_dsl_spec.rb +0 -108
- data/spec/lib/pact/provider/configuration_spec.rb +0 -50
- data/spec/lib/pact/provider/matchers/messages_spec.rb +0 -116
- data/spec/lib/pact/provider/pact_helper_locator_spec.rb +0 -54
- data/spec/lib/pact/provider/print_missing_provider_states_spec.rb +0 -19
- data/spec/lib/pact/provider/request_spec.rb +0 -78
- data/spec/lib/pact/provider/rspec/formatter_rspec_2_spec.rb +0 -68
- data/spec/lib/pact/provider/rspec/formatter_rspec_3_spec.rb +0 -72
- data/spec/lib/pact/provider/rspec_spec.rb +0 -55
- data/spec/lib/pact/provider/state/provider_state_manager_spec.rb +0 -89
- data/spec/lib/pact/provider/state/provider_state_proxy_spec.rb +0 -80
- data/spec/lib/pact/provider/state/provider_state_spec.rb +0 -213
- data/spec/lib/pact/provider/world_spec.rb +0 -41
- data/spec/lib/pact/reification_spec.rb +0 -67
- data/spec/lib/pact/shared/dsl_spec.rb +0 -86
- data/spec/lib/pact/shared/json_differ_spec.rb +0 -36
- data/spec/lib/pact/shared/key_not_found_spec.rb +0 -20
- data/spec/lib/pact/shared/request_spec.rb +0 -111
- data/spec/lib/pact/shared/text_differ_spec.rb +0 -54
- data/spec/lib/pact/something_like_spec.rb +0 -21
- data/spec/lib/pact/tasks/task_helper_spec.rb +0 -74
- data/spec/lib/pact/tasks/verification_task_spec.rb +0 -75
- data/spec/lib/pact/term_spec.rb +0 -89
- data/spec/pact_specification/compliance-1.0.0.rb +0 -47
- data/spec/spec_helper.rb +0 -22
- data/spec/standalone/consumer_fail_test.rb +0 -55
- data/spec/standalone/consumer_pass_test.rb +0 -51
- data/spec/support/a_consumer-a_producer.json +0 -32
- data/spec/support/a_consumer-a_provider.json +0 -32
- data/spec/support/active_support_if_configured.rb +0 -6
- data/spec/support/app_for_config_ru.rb +0 -4
- data/spec/support/consumer_contract_template.json +0 -24
- data/spec/support/dsl_spec_support.rb +0 -7
- data/spec/support/factories.rb +0 -82
- data/spec/support/generated_index.md +0 -4
- data/spec/support/generated_markdown.md +0 -55
- data/spec/support/interaction_view_model.json +0 -63
- data/spec/support/interaction_view_model_with_terms.json +0 -50
- data/spec/support/markdown_pact.json +0 -48
- data/spec/support/missing_provider_states_output.txt +0 -25
- data/spec/support/options.json +0 -21
- data/spec/support/options_app.rb +0 -15
- data/spec/support/pact_helper.rb +0 -57
- data/spec/support/shared_examples_for_request.rb +0 -94
- data/spec/support/spec_support.rb +0 -20
- data/spec/support/stubbing.json +0 -22
- data/spec/support/stubbing_using_allow.rb +0 -29
- data/spec/support/term.json +0 -48
- data/spec/support/test_app_fail.json +0 -61
- data/spec/support/test_app_pass.json +0 -38
- data/spec/support/test_app_with_right_content_type_differ.json +0 -23
- data/tasks/pact-test.rake +0 -109
- data/tasks/spec.rake +0 -8
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'pact/consumer/mock_service/verification_get'
|
|
3
|
-
|
|
4
|
-
module Pact
|
|
5
|
-
module Consumer
|
|
6
|
-
describe VerificationGet do
|
|
7
|
-
|
|
8
|
-
let(:interaction_list) { instance_double("Pact::Consumer::InteractionList")}
|
|
9
|
-
let(:logger) { double("Logger").as_null_object }
|
|
10
|
-
let(:log_description) { "/log/pact.log" }
|
|
11
|
-
|
|
12
|
-
subject { VerificationGet.new('VerificationGet', logger, interaction_list, log_description) }
|
|
13
|
-
|
|
14
|
-
describe "request_path" do
|
|
15
|
-
it "is /interactions/verification" do
|
|
16
|
-
expect(subject.request_path).to eq '/interactions/verification'
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe "request_method" do
|
|
21
|
-
it "is GET" do
|
|
22
|
-
expect(subject.request_method).to eq 'GET'
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
describe "#respond" do
|
|
27
|
-
let(:env) { {
|
|
28
|
-
"QUERY_STRING" => "example_description=a description"
|
|
29
|
-
} }
|
|
30
|
-
|
|
31
|
-
before do
|
|
32
|
-
allow(interaction_list).to receive(:all_matched?).and_return(all_matched)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
let(:response) { subject.respond env }
|
|
36
|
-
|
|
37
|
-
context "when all interactions have been matched" do
|
|
38
|
-
let(:all_matched) { true }
|
|
39
|
-
|
|
40
|
-
it "returns a 200 status" do
|
|
41
|
-
expect(response.first).to eq 200
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it "returns a Content-Type of text/plain" do
|
|
45
|
-
expect(response[1]).to eq 'Content-Type' => 'text/plain'
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it "returns a nice message" do
|
|
49
|
-
expect(response.last).to eq ['Interactions matched']
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it "logs the success" do
|
|
53
|
-
expect(logger).to receive(:info).with(/Verifying - interactions matched.*a description/)
|
|
54
|
-
response
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
context "when all interactions not been matched" do
|
|
59
|
-
let(:all_matched) { false }
|
|
60
|
-
let(:failure_message) { "this is a failure message"}
|
|
61
|
-
|
|
62
|
-
before do
|
|
63
|
-
allow_any_instance_of(VerificationGet::FailureMessage).to receive(:to_s).and_return(failure_message)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it "returns a 500 status" do
|
|
67
|
-
expect(response.first).to eq 500
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "returns a Content-Type of text/plain" do
|
|
71
|
-
expect(response[1]).to eq 'Content-Type' => 'text/plain'
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "returns a message" do
|
|
75
|
-
expect(response.last.first).to include "Actual interactions do not match"
|
|
76
|
-
expect(response.last.first).to include failure_message
|
|
77
|
-
expect(response.last.first).to include log_description
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it "logs the failure message" do
|
|
81
|
-
expect(logger).to receive(:warn).with(/Verifying - actual interactions do not match/)
|
|
82
|
-
expect(logger).to receive(:warn).with(failure_message)
|
|
83
|
-
response
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
describe "FailureMessage" do
|
|
91
|
-
let(:missing_interactions_summaries) { ["Blah", "Thing"]}
|
|
92
|
-
let(:interaction_mismatches_summaries) { []}
|
|
93
|
-
let(:unexpected_requests_summaries) { []}
|
|
94
|
-
let(:interaction_list) { instance_double("Pact::Consumer::InteractionList") }
|
|
95
|
-
subject { VerificationGet::FailureMessage.new(interaction_list).to_s }
|
|
96
|
-
|
|
97
|
-
before do
|
|
98
|
-
allow(interaction_list).to receive(:missing_interactions_summaries).and_return(missing_interactions_summaries)
|
|
99
|
-
allow(interaction_list).to receive(:interaction_mismatches_summaries).and_return(interaction_mismatches_summaries)
|
|
100
|
-
allow(interaction_list).to receive(:unexpected_requests_summaries).and_return(unexpected_requests_summaries)
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
context "with only a missing interactions" do
|
|
104
|
-
|
|
105
|
-
let(:expected_string) { <<-EOS
|
|
106
|
-
Missing requests:
|
|
107
|
-
\tBlah
|
|
108
|
-
\tThing
|
|
109
|
-
|
|
110
|
-
EOS
|
|
111
|
-
}
|
|
112
|
-
it "only includes missing interactions" do
|
|
113
|
-
expect(subject).to eq expected_string
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
context "with missing, mismatches and unexpected interactions" do
|
|
118
|
-
|
|
119
|
-
let(:interaction_mismatches_summaries) { ["wiffle"]}
|
|
120
|
-
let(:unexpected_requests_summaries) { ["moose"]}
|
|
121
|
-
|
|
122
|
-
let(:expected_string) { <<-EOS
|
|
123
|
-
Incorrect requests:
|
|
124
|
-
\twiffle
|
|
125
|
-
|
|
126
|
-
Missing requests:
|
|
127
|
-
\tBlah
|
|
128
|
-
\tThing
|
|
129
|
-
|
|
130
|
-
Unexpected requests:
|
|
131
|
-
\tmoose
|
|
132
|
-
|
|
133
|
-
EOS
|
|
134
|
-
}
|
|
135
|
-
it "includes all the things" do
|
|
136
|
-
expect(subject).to eq expected_string
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'pact/consumer/mock_service_client'
|
|
3
|
-
|
|
4
|
-
module Pact
|
|
5
|
-
module Consumer
|
|
6
|
-
describe MockServiceClient do
|
|
7
|
-
|
|
8
|
-
subject { MockServiceClient.new(4444) }
|
|
9
|
-
|
|
10
|
-
let(:administration_headers) { {'X-Pact-Mock-Service' => 'true'} }
|
|
11
|
-
|
|
12
|
-
describe "#add_expected_interaction" do
|
|
13
|
-
let(:interaction) { InteractionFactory.create }
|
|
14
|
-
let(:request_body) { MockServiceInteractionExpectation.new(interaction).to_json }
|
|
15
|
-
|
|
16
|
-
context "when successful" do
|
|
17
|
-
let!(:post_interaction) do
|
|
18
|
-
stub_request(:post, "localhost:4444/interactions").
|
|
19
|
-
with(body: request_body, headers: administration_headers.merge('Content-Type' => "application/json")).
|
|
20
|
-
to_return(status: 200)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "sets up the expected interaction on the mock server" do
|
|
24
|
-
subject.add_expected_interaction interaction
|
|
25
|
-
expect(post_interaction).to have_been_made
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe "#verify" do
|
|
32
|
-
|
|
33
|
-
context "when all interactions are successfully verified" do
|
|
34
|
-
|
|
35
|
-
let!(:get_verification) do
|
|
36
|
-
stub_request(:get, "localhost:4444/interactions/verification?example_description=some%20example").
|
|
37
|
-
with(headers: administration_headers).
|
|
38
|
-
to_return(status: 200)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "does not throw an error" do
|
|
42
|
-
subject.verify "some example"
|
|
43
|
-
expect(get_verification).to have_been_made
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
describe ".clear_interactions" do
|
|
49
|
-
let!(:delete_verifications) do
|
|
50
|
-
stub_request(:delete, "localhost:4444/interactions?example_description=some%20example").
|
|
51
|
-
with(headers: administration_headers).
|
|
52
|
-
to_return(status: 200)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "deletes the interactions" do
|
|
56
|
-
MockServiceClient.clear_interactions 4444, "some example"
|
|
57
|
-
expect(delete_verifications).to have_been_made
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
describe "#write_pact" do
|
|
62
|
-
let(:consumer_contract_details) { {consumer: {name: 'Consumer'}, provider: {name: 'Provider'}, pactfile_write_mode: 'update'} }
|
|
63
|
-
let(:pact) { {a: 'pact'}.to_json }
|
|
64
|
-
|
|
65
|
-
let!(:post_pact) do
|
|
66
|
-
stub_request(:post, "localhost:4444/pact").
|
|
67
|
-
with(headers: administration_headers.merge('Content-Type' => "application/json"), body: consumer_contract_details).
|
|
68
|
-
to_return(status: 200, body: pact)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it "deletes the interactions" do
|
|
72
|
-
expect(subject.write_pact(consumer_contract_details)).to eq pact
|
|
73
|
-
expect(post_pact).to have_been_made
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
describe "#log" do
|
|
79
|
-
it "sends a log request to the mock server"
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
describe "#wait_for_interactions" do
|
|
83
|
-
it "waits until there are no missing interactions"
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'pact/consumer/mock_service_interaction_expectation'
|
|
3
|
-
|
|
4
|
-
describe Pact::Consumer::MockServiceInteractionExpectation do
|
|
5
|
-
describe "as_json" do
|
|
6
|
-
|
|
7
|
-
let(:options ) { {} }
|
|
8
|
-
let(:request_as_json) { {a: 'request'} }
|
|
9
|
-
let(:request) { instance_double('Pact::Request::Expected', :as_json => request_as_json, :options => options)}
|
|
10
|
-
let(:response) { double('response') }
|
|
11
|
-
let(:generated_response ) { double('generated_response', :to_json => 'generated_response') }
|
|
12
|
-
let(:interaction) { instance_double('Pact::Interaction', :description => 'description', :request => request, :response => response, :provider_state => 'some state') }
|
|
13
|
-
subject { described_class.new(interaction)}
|
|
14
|
-
let(:expected_hash) { {:response => generated_response, :request => as_json_with_options, :description => '' } }
|
|
15
|
-
|
|
16
|
-
before do
|
|
17
|
-
allow(Pact::Reification).to receive(:from_term).with(response).and_return(generated_response)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "includes the response" do
|
|
21
|
-
expect(subject.as_json[:response]).to eq response
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "includes the options in the request" do
|
|
25
|
-
expect(subject.as_json[:request]).to eq request_as_json
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "includes the provider state" do
|
|
29
|
-
expect(subject.as_json[:provider_state]).to eq 'some state'
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "includes the description" do
|
|
33
|
-
expect(subject.as_json[:description]).to eq 'description'
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "doesn't have any other keys" do
|
|
37
|
-
expect(subject.as_json.keys).to eq [:description, :provider_state, :request, :response]
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
context "without options" do
|
|
41
|
-
it "does not include the options key" do
|
|
42
|
-
expect(subject.as_json.key?(:options)).to be false
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context "with options" do
|
|
47
|
-
let(:options) { {:opts => 'blah'} }
|
|
48
|
-
it "includes the options in the request hash" do
|
|
49
|
-
expect(subject.as_json[:request][:options]).to eq options
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'support/shared_examples_for_request'
|
|
3
|
-
|
|
4
|
-
module Pact
|
|
5
|
-
describe Consumer::Request::Actual do
|
|
6
|
-
it_behaves_like "a request"
|
|
7
|
-
|
|
8
|
-
let(:raw_request) do
|
|
9
|
-
{
|
|
10
|
-
'method' => 'get',
|
|
11
|
-
'path' => '/mallory'
|
|
12
|
-
}
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
describe "from_hash" do
|
|
16
|
-
context "when field are not defined" do
|
|
17
|
-
subject { described_class.from_hash(raw_request) }
|
|
18
|
-
it "raises an error" do
|
|
19
|
-
expect{subject}.to raise_error KeyError
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'pact/shared/active_support_support'
|
|
3
|
-
|
|
4
|
-
module Pact
|
|
5
|
-
describe ActiveSupportSupport do
|
|
6
|
-
|
|
7
|
-
include ActiveSupportSupport
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
describe "fix_regexp" do
|
|
11
|
-
let(:regexp) { /moose/ }
|
|
12
|
-
|
|
13
|
-
subject { fix_regexp regexp }
|
|
14
|
-
|
|
15
|
-
it "returns the original regexp" do
|
|
16
|
-
expect(subject).to be(regexp)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "fixes the as_json method for Regexp that ActiveSupport tramples beneath its destructive hooves of destruction" do
|
|
20
|
-
expect(subject.to_json).to eq("{\"json_class\":\"Regexp\",\"o\":0,\"s\":\"moose\"}")
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe "fix_all_the_things" do
|
|
25
|
-
let(:hash) do
|
|
26
|
-
{ 'body' => Pact::Term.new(matcher: /a*b/, generate: 'abba'), array: [/blah/], thing: /alligator/ }
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
subject { fix_all_the_things(hash) }
|
|
30
|
-
|
|
31
|
-
it "returns the original object" do
|
|
32
|
-
expect(subject).to be(hash)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "finds all the Regexp objects in hashes or Pact class attributes and fixes the as_json method" do
|
|
36
|
-
json = subject.to_json
|
|
37
|
-
expect(json).to include("{\"json_class\":\"Regexp\",\"o\":0,\"s\":\"a*b\"}")
|
|
38
|
-
expect(json).to include("{\"json_class\":\"Regexp\",\"o\":0,\"s\":\"blah\"}")
|
|
39
|
-
expect(json).to include("{\"json_class\":\"Regexp\",\"o\":0,\"s\":\"alligator\"}")
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
describe "fix_json_formatting" do
|
|
44
|
-
let(:active_support_affected_pretty_generated_json) { "{\"json_class\":\"Regexp\",\"o\":0,\"s\":\"a*b\"}" }
|
|
45
|
-
let(:pretty_generated_json) do
|
|
46
|
-
'{
|
|
47
|
-
"json_class": "Regexp",
|
|
48
|
-
"o": 0,
|
|
49
|
-
"s": "a*b"
|
|
50
|
-
}'
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it "pretty formats the json that has been not pretty formatted because of ActiveSupport" do
|
|
54
|
-
expect(fix_json_formatting(active_support_affected_pretty_generated_json)).to eq (pretty_generated_json.strip)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'pact/consumer_contract'
|
|
3
|
-
|
|
4
|
-
module Pact
|
|
5
|
-
describe ConsumerContract do
|
|
6
|
-
describe "as_json" do
|
|
7
|
-
|
|
8
|
-
class MockInteraction
|
|
9
|
-
def as_json(options ={})
|
|
10
|
-
{:mock => "interaction"}
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
before do
|
|
15
|
-
allow(DateTime).to receive(:now).and_return(DateTime.strptime("2013-08-15T13:27:13+10:00"))
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
let(:service_consumer) { double('ServiceConsumer', :as_json => {:a => 'consumer'}) }
|
|
19
|
-
let(:service_provider) { double('ServiceProvider', :as_json => {:a => 'provider'}) }
|
|
20
|
-
let(:pact) { ConsumerContract.new({:interactions => [MockInteraction.new], :consumer => service_consumer, :provider => service_provider }) }
|
|
21
|
-
let(:expected_as_json) { {:provider=>{:a=>"provider"}, :consumer=>{:a=>"consumer"}, :interactions=>[{:mock=>"interaction"}], :metadata=>{:pactSpecificationVersion=> "1.0.0" }} }
|
|
22
|
-
|
|
23
|
-
it "should return a hash representation of the Pact" do
|
|
24
|
-
expect(pact.as_json).to eq expected_as_json
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
describe ".from_json" do
|
|
30
|
-
let(:loaded_pact) { ConsumerContract.from_json(string) }
|
|
31
|
-
context "when the top level object is a ConsumerContract" do
|
|
32
|
-
let(:string) { '{"interactions":[{"request": {"path":"/path", "method" : "get"}}], "consumer": {"name" : "Bob"} , "provider": {"name" : "Mary"} }' }
|
|
33
|
-
|
|
34
|
-
it "should create a Pact" do
|
|
35
|
-
expect(loaded_pact).to be_instance_of ConsumerContract
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "should have interactions" do
|
|
39
|
-
expect(loaded_pact.interactions).to be_instance_of Array
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "should have a consumer" do
|
|
43
|
-
expect(loaded_pact.consumer).to be_instance_of Pact::ServiceConsumer
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "should have a provider" do
|
|
47
|
-
expect(loaded_pact.provider).to be_instance_of Pact::ServiceProvider
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
context "with old 'producer' key" do
|
|
52
|
-
let(:string) { File.read('./spec/support/a_consumer-a_producer.json')}
|
|
53
|
-
it "should create a Pact" do
|
|
54
|
-
expect(loaded_pact).to be_instance_of ConsumerContract
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it "should have interactions" do
|
|
58
|
-
expect(loaded_pact.interactions).to be_instance_of Array
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "should have a consumer" do
|
|
62
|
-
expect(loaded_pact.consumer).to be_instance_of Pact::ServiceConsumer
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "should have a provider" do
|
|
66
|
-
expect(loaded_pact.provider).to be_instance_of Pact::ServiceProvider
|
|
67
|
-
expect(loaded_pact.provider.name).to eq "an old producer"
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "should have a provider_state" do
|
|
71
|
-
expect(loaded_pact.interactions.first.provider_state).to eq 'state one'
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
describe "find_interactions" do
|
|
77
|
-
let(:consumer) { double('Pact::ServiceConsumer', :name => 'Consumer')}
|
|
78
|
-
let(:provider) { double('Pact::ServiceProvider', :name => 'Provider')}
|
|
79
|
-
let(:interaction) { double('Pact::Interaction') }
|
|
80
|
-
subject { ConsumerContract.new(:interactions => [interaction], :consumer => consumer, :provider => provider) }
|
|
81
|
-
let(:criteria) { {:description => /blah/} }
|
|
82
|
-
before do
|
|
83
|
-
expect(interaction).to receive(:matches_criteria?).with(criteria).and_return(matches)
|
|
84
|
-
end
|
|
85
|
-
context "by description" do
|
|
86
|
-
context "when no interactions are found" do
|
|
87
|
-
let(:matches) { false }
|
|
88
|
-
it "returns an empty array" do
|
|
89
|
-
expect(subject.find_interactions(criteria)).to eql []
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
context "when interactions are found" do
|
|
93
|
-
let(:matches) { true }
|
|
94
|
-
it "returns an array of the matching interactions" do
|
|
95
|
-
expect(subject.find_interactions(criteria)).to eql [interaction]
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
describe "find_interaction" do
|
|
102
|
-
let(:consumer) { double('Pact::ServiceConsumer', :name => 'Consumer')}
|
|
103
|
-
let(:provider) { double('Pact::ServiceProvider', :name => 'Provider')}
|
|
104
|
-
let(:interaction1) { double('Pact::Interaction') }
|
|
105
|
-
let(:interaction2) { double('Pact::Interaction') }
|
|
106
|
-
let(:criteria) { {:description => /blah/} }
|
|
107
|
-
|
|
108
|
-
before do
|
|
109
|
-
expect(interaction1).to receive(:matches_criteria?).with(criteria).and_return(matches1)
|
|
110
|
-
expect(interaction2).to receive(:matches_criteria?).with(criteria).and_return(matches2)
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
subject { ConsumerContract.new(:interactions => [interaction1, interaction2], :consumer => consumer, :provider => provider) }
|
|
114
|
-
context "by description" do
|
|
115
|
-
context "when a match is found" do
|
|
116
|
-
let(:matches1) { true }
|
|
117
|
-
let(:matches2) { false }
|
|
118
|
-
|
|
119
|
-
it "returns the interaction" do
|
|
120
|
-
expect(subject.find_interaction criteria).to eql interaction1
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
context "when more than one match is found" do
|
|
124
|
-
let(:matches1) { true }
|
|
125
|
-
let(:matches2) { true }
|
|
126
|
-
it "raises an error" do
|
|
127
|
-
expect{ subject.find_interaction(criteria) }.to raise_error "Found more than 1 interaction matching {:description=>/blah/} in pact file between Consumer and Provider."
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
context "when a match is not found" do
|
|
131
|
-
let(:matches1) { false }
|
|
132
|
-
let(:matches2) { false }
|
|
133
|
-
it "raises an error" do
|
|
134
|
-
expect{ subject.find_interaction(criteria) }.to raise_error "Could not find interaction matching {:description=>/blah/} in pact file between Consumer and Provider."
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
describe "update_pactfile" do
|
|
141
|
-
let(:pacts_dir) { Pathname.new("./tmp/pactfiles") }
|
|
142
|
-
let(:expected_pact_path) { pacts_dir + "test_consumer-test_service.json" }
|
|
143
|
-
let(:expected_pact_string) do <<-eos
|
|
144
|
-
{
|
|
145
|
-
"provider": {
|
|
146
|
-
"name": "test_service"
|
|
147
|
-
},
|
|
148
|
-
"consumer": {
|
|
149
|
-
"name": "test_consumer"
|
|
150
|
-
},
|
|
151
|
-
"interactions": [
|
|
152
|
-
"something"
|
|
153
|
-
],
|
|
154
|
-
"metadata": {
|
|
155
|
-
"pactSpecificationVersion": "1.0.0"
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
eos
|
|
159
|
-
end
|
|
160
|
-
let(:consumer) { Pact::ServiceConsumer.new(:name => 'test_consumer')}
|
|
161
|
-
let(:provider) { Pact::ServiceProvider.new(:name => 'test_service')}
|
|
162
|
-
let(:interactions) { [double("interaction", as_json: "something")]}
|
|
163
|
-
subject { ConsumerContract.new(:consumer => consumer, :provider => provider, :interactions => interactions) }
|
|
164
|
-
before do
|
|
165
|
-
allow(Pact.configuration).to receive(:pact_dir).and_return(Pathname.new("./tmp/pactfiles"))
|
|
166
|
-
FileUtils.rm_rf pacts_dir
|
|
167
|
-
FileUtils.mkdir_p pacts_dir
|
|
168
|
-
subject.update_pactfile
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
it "should write to a file specified by the consumer and provider name" do
|
|
172
|
-
expect(File.exist?(expected_pact_path)).to eq true
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
it "should write the interactions to the file" do
|
|
176
|
-
expect(File.read(expected_pact_path)).to eql expected_pact_string.strip
|
|
177
|
-
end
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
end
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'pact/consumer_contract/consumer_contract_writer'
|
|
3
|
-
|
|
4
|
-
module Pact
|
|
5
|
-
|
|
6
|
-
describe ConsumerContractWriter do
|
|
7
|
-
|
|
8
|
-
let(:support_pact_file) { './spec/support/a_consumer-a_provider.json' }
|
|
9
|
-
let(:consumer_name) { 'a consumer' }
|
|
10
|
-
let(:provider_name) { 'a provider' }
|
|
11
|
-
|
|
12
|
-
before do
|
|
13
|
-
Pact.clear_configuration
|
|
14
|
-
allow(Pact.configuration).to receive(:pact_dir).and_return(File.expand_path(tmp_pact_dir))
|
|
15
|
-
FileUtils.rm_rf tmp_pact_dir
|
|
16
|
-
FileUtils.mkdir_p tmp_pact_dir
|
|
17
|
-
FileUtils.cp support_pact_file, "#{tmp_pact_dir}/a_consumer-a_provider.json"
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
let(:existing_interactions) { ConsumerContract.from_json(File.read(support_pact_file)).interactions }
|
|
21
|
-
let(:new_interactions) { [InteractionFactory.create] }
|
|
22
|
-
let(:tmp_pact_dir) {"./tmp/pacts"}
|
|
23
|
-
let(:logger) { double("logger").as_null_object }
|
|
24
|
-
let(:pactfile_write_mode) {:overwrite}
|
|
25
|
-
let(:consumer_contract_details) {
|
|
26
|
-
{
|
|
27
|
-
consumer: {name: consumer_name},
|
|
28
|
-
provider: {name: provider_name},
|
|
29
|
-
pactfile_write_mode: pactfile_write_mode,
|
|
30
|
-
interactions: new_interactions
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let(:consumer_contract_writer) { ConsumerContractWriter.new(consumer_contract_details, logger) }
|
|
35
|
-
|
|
36
|
-
describe "consumer_contract" do
|
|
37
|
-
|
|
38
|
-
let(:subject) { consumer_contract_writer.consumer_contract }
|
|
39
|
-
|
|
40
|
-
context "when overwriting pact" do
|
|
41
|
-
|
|
42
|
-
it "it uses only the interactions from the current test run" do
|
|
43
|
-
expect(consumer_contract_writer.consumer_contract.interactions).to eq new_interactions
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
context "when updating pact" do
|
|
49
|
-
|
|
50
|
-
let(:pactfile_write_mode) {:update}
|
|
51
|
-
|
|
52
|
-
it "merges the interactions from the current test run with the interactions from the existing file" do
|
|
53
|
-
allow_any_instance_of(ConsumerContractWriter).to receive(:info_and_puts)
|
|
54
|
-
expect(consumer_contract_writer.consumer_contract.interactions).to eq existing_interactions + new_interactions
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
let(:line0) { /\*/ }
|
|
58
|
-
let(:line1) { /Updating existing file/ }
|
|
59
|
-
let(:line2) { /Only interactions defined in this test run will be updated/ }
|
|
60
|
-
let(:line3) { /As interactions are identified by description and provider state/ }
|
|
61
|
-
|
|
62
|
-
it "logs a description message" do
|
|
63
|
-
expect($stdout).to receive(:puts).with(line0).twice
|
|
64
|
-
expect($stdout).to receive(:puts).with(line1)
|
|
65
|
-
expect($stdout).to receive(:puts).with(line2)
|
|
66
|
-
expect($stdout).to receive(:puts).with(line3)
|
|
67
|
-
expect(logger).to receive(:info).with(line0).twice
|
|
68
|
-
expect(logger).to receive(:info).with(line1)
|
|
69
|
-
expect(logger).to receive(:info).with(line2)
|
|
70
|
-
expect(logger).to receive(:info).with(line3)
|
|
71
|
-
consumer_contract_writer.consumer_contract
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
context "when an error occurs deserializing the existing pactfile" do
|
|
76
|
-
|
|
77
|
-
let(:pactfile_write_mode) {:update}
|
|
78
|
-
let(:error) { RuntimeError.new('some error')}
|
|
79
|
-
let(:line1) { /Could not load existing consumer contract from .* due to some error/ }
|
|
80
|
-
let(:line2) {'Creating a new file.'}
|
|
81
|
-
|
|
82
|
-
before do
|
|
83
|
-
allow(ConsumerContract).to receive(:from_json).and_raise(error)
|
|
84
|
-
allow($stderr).to receive(:puts)
|
|
85
|
-
allow(logger).to receive(:puts)
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
it "logs the error" do
|
|
89
|
-
expect($stderr).to receive(:puts).with(line1)
|
|
90
|
-
expect($stderr).to receive(:puts).with(line2)
|
|
91
|
-
expect(logger).to receive(:warn).with(line1)
|
|
92
|
-
expect(logger).to receive(:warn).with(line2)
|
|
93
|
-
consumer_contract_writer.consumer_contract
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
it "uses the new interactions" do
|
|
97
|
-
expect(consumer_contract_writer.consumer_contract.interactions).to eq new_interactions
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
describe "write" do
|
|
103
|
-
it "writes the pact file" do
|
|
104
|
-
expect_any_instance_of(ConsumerContract).to receive(:update_pactfile)
|
|
105
|
-
consumer_contract_writer.write
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
end
|