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
data/spec/spec_helper.rb
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require 'rspec'
|
|
2
|
-
require 'fakefs/spec_helpers'
|
|
3
|
-
require 'rspec'
|
|
4
|
-
require 'pact'
|
|
5
|
-
require 'webmock/rspec'
|
|
6
|
-
require 'support/factories'
|
|
7
|
-
require 'support/spec_support'
|
|
8
|
-
require 'pact/provider/rspec'
|
|
9
|
-
|
|
10
|
-
WebMock.disable_net_connect!(allow_localhost: true)
|
|
11
|
-
|
|
12
|
-
require './spec/support/active_support_if_configured'
|
|
13
|
-
|
|
14
|
-
RSpec.configure do | config |
|
|
15
|
-
config.include(FakeFS::SpecHelpers, :fakefs => true)
|
|
16
|
-
|
|
17
|
-
config.extend Pact::Provider::RSpec::ClassMethods
|
|
18
|
-
config.include Pact::Provider::RSpec::InstanceMethods
|
|
19
|
-
config.include Pact::Provider::TestMethods
|
|
20
|
-
config.include Pact::SpecSupport
|
|
21
|
-
end
|
|
22
|
-
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
require 'pact/consumer/rspec'
|
|
2
|
-
require './spec/support/active_support_if_configured'
|
|
3
|
-
|
|
4
|
-
Pact.service_consumer "Standalone Consumer" do
|
|
5
|
-
has_pact_with "Standalone Provider" do
|
|
6
|
-
mock_service :standalone_service do
|
|
7
|
-
port 1238
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
class StandaloneClient
|
|
13
|
-
|
|
14
|
-
def initialize base_url
|
|
15
|
-
@base_url = base_url
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def call
|
|
19
|
-
uri = URI("#{@base_url}/something")
|
|
20
|
-
post_req = Net::HTTP::Post.new(uri.path)
|
|
21
|
-
post_req['Content-Type'] = "application/json"
|
|
22
|
-
post_req.body = {a: "not matching body"}.to_json
|
|
23
|
-
response = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
|
24
|
-
http.request post_req
|
|
25
|
-
end
|
|
26
|
-
JSON.parse(response.body)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe StandaloneClient, pact: true do
|
|
32
|
-
|
|
33
|
-
subject { StandaloneClient.new("http://localhost:1238") }
|
|
34
|
-
|
|
35
|
-
describe "call" do
|
|
36
|
-
|
|
37
|
-
let(:expected_body) { {a: "body"} }
|
|
38
|
-
let(:expected_headers) { {'Content-Type' => "application/hal+json"} }
|
|
39
|
-
|
|
40
|
-
before do
|
|
41
|
-
standalone_service.
|
|
42
|
-
upon_receiving("a request to create something").with(method: 'post', path: '/something', headers: expected_headers, body: expected_body).
|
|
43
|
-
will_respond_with(status: 200, headers: {}, body: {a: 'response body'})
|
|
44
|
-
|
|
45
|
-
standalone_service.
|
|
46
|
-
upon_receiving("a request to create something else").with(method: 'post', path: '/something-else', headers: expected_headers, body: expected_body).
|
|
47
|
-
will_respond_with(status: 200, headers: {}, body: {a: 'response body'})
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "will fail and display a helpful message" do
|
|
51
|
-
subject.call
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
end
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
require 'pact/consumer/rspec'
|
|
2
|
-
require './spec/support/active_support_if_configured'
|
|
3
|
-
|
|
4
|
-
Pact.service_consumer "Standalone Consumer" do
|
|
5
|
-
has_pact_with "Standalone Provider" do
|
|
6
|
-
mock_service :standalone_service do
|
|
7
|
-
port 1237
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
class StandaloneClient
|
|
13
|
-
|
|
14
|
-
def initialize base_url
|
|
15
|
-
@base_url = base_url
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def call
|
|
19
|
-
uri = URI("#{@base_url}/something")
|
|
20
|
-
post_req = Net::HTTP::Post.new(uri.path)
|
|
21
|
-
post_req['Content-Type'] = "application/json"
|
|
22
|
-
post_req.body = {a: "body"}.to_json
|
|
23
|
-
response = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
|
24
|
-
http.request post_req
|
|
25
|
-
end
|
|
26
|
-
response.body
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe StandaloneClient, pact: true do
|
|
32
|
-
|
|
33
|
-
subject { StandaloneClient.new("http://localhost:1237") }
|
|
34
|
-
|
|
35
|
-
describe "call" do
|
|
36
|
-
|
|
37
|
-
let(:expected_body) { {a: "body"} }
|
|
38
|
-
let(:response_body) { {a: 'response body'} }
|
|
39
|
-
|
|
40
|
-
before do
|
|
41
|
-
standalone_service.
|
|
42
|
-
upon_receiving("a request to create something").with(method: 'post', path: '/something', body: expected_body).
|
|
43
|
-
will_respond_with(status: 200, headers: {}, body: response_body)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "will pass" do
|
|
47
|
-
expect(subject.call).to eq response_body.to_json
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
end
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"producer": {
|
|
3
|
-
"name": "an old producer"
|
|
4
|
-
},
|
|
5
|
-
"consumer": {
|
|
6
|
-
"name": "a consumer"
|
|
7
|
-
},
|
|
8
|
-
"interactions": [
|
|
9
|
-
{
|
|
10
|
-
"description": "request one",
|
|
11
|
-
"request": {
|
|
12
|
-
"method": "get",
|
|
13
|
-
"path": "/path_one"
|
|
14
|
-
},
|
|
15
|
-
"response": {
|
|
16
|
-
},
|
|
17
|
-
"producer_state": "state one"
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
"description": "request two",
|
|
21
|
-
"request": {
|
|
22
|
-
"method": "get",
|
|
23
|
-
"path": "/path_two"
|
|
24
|
-
},
|
|
25
|
-
"response": {
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
"metadata": {
|
|
30
|
-
"pactSpecificationVersion": "1.0"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"provider": {
|
|
3
|
-
"name": "a provider"
|
|
4
|
-
},
|
|
5
|
-
"consumer": {
|
|
6
|
-
"name": "a consumer"
|
|
7
|
-
},
|
|
8
|
-
"interactions": [
|
|
9
|
-
{
|
|
10
|
-
"description": "request one",
|
|
11
|
-
"request": {
|
|
12
|
-
"method": "get",
|
|
13
|
-
"path": "/path_one"
|
|
14
|
-
},
|
|
15
|
-
"response": {
|
|
16
|
-
},
|
|
17
|
-
"provider_state": "state one"
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
"description": "request two",
|
|
21
|
-
"request": {
|
|
22
|
-
"method": "get",
|
|
23
|
-
"path": "/path_two"
|
|
24
|
-
},
|
|
25
|
-
"response": {
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
"metadata": {
|
|
30
|
-
"pactSpecificationVersion": "1.0"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"provider": {
|
|
3
|
-
"name": "a provider"
|
|
4
|
-
},
|
|
5
|
-
"consumer": {
|
|
6
|
-
"name": "a consumer"
|
|
7
|
-
},
|
|
8
|
-
"interactions": [
|
|
9
|
-
{
|
|
10
|
-
"description": "request one",
|
|
11
|
-
"request": {
|
|
12
|
-
"method": "get",
|
|
13
|
-
"path": "/path_one"
|
|
14
|
-
},
|
|
15
|
-
"response": {
|
|
16
|
-
"status" : 200
|
|
17
|
-
},
|
|
18
|
-
"provider_state": "state one"
|
|
19
|
-
}
|
|
20
|
-
],
|
|
21
|
-
"metadata": {
|
|
22
|
-
"pactSpecificationVersion": "1.0"
|
|
23
|
-
}
|
|
24
|
-
}
|
data/spec/support/factories.rb
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
require 'hashie'
|
|
2
|
-
require 'hashie/extensions/key_conversion'
|
|
3
|
-
|
|
4
|
-
module Pact
|
|
5
|
-
module HashUtils
|
|
6
|
-
|
|
7
|
-
class Converter < Hash
|
|
8
|
-
include Hashie::Extensions::KeyConversion
|
|
9
|
-
include Hashie::Extensions::DeepMerge
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def symbolize_keys hash
|
|
13
|
-
Hash[Converter[hash].symbolize_keys]
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def stringify_keys hash
|
|
17
|
-
Hash[Converter[hash].stringify_keys]
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def deep_merge hash1, hash2
|
|
21
|
-
Converter[hash1].deep_merge(Converter[hash2])
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
class InteractionFactory
|
|
27
|
-
|
|
28
|
-
extend Pact::HashUtils
|
|
29
|
-
|
|
30
|
-
def self.create hash = {}
|
|
31
|
-
defaults = {
|
|
32
|
-
'description' => 'a description',
|
|
33
|
-
'provider_state' => 'a thing exists',
|
|
34
|
-
'request' => {
|
|
35
|
-
'path' => '/path',
|
|
36
|
-
'method' => 'get',
|
|
37
|
-
},
|
|
38
|
-
'response' => {
|
|
39
|
-
'status' => 200,
|
|
40
|
-
'body' => {a: 'response body'}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
Pact::Interaction.from_hash(stringify_keys(deep_merge(defaults, stringify_keys(hash))))
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
class ConsumerContractFactory
|
|
49
|
-
extend Pact::HashUtils
|
|
50
|
-
DEFAULTS = {:consumer_name => 'consumer',
|
|
51
|
-
:provider_name => 'provider',
|
|
52
|
-
:interactions => [InteractionFactory.create]}
|
|
53
|
-
|
|
54
|
-
def self.create overrides = {}
|
|
55
|
-
options = deep_merge(symbolize_keys(DEFAULTS), symbolize_keys(overrides))
|
|
56
|
-
Pact::ConsumerContract.new({:consumer => Pact::ServiceConsumer.new(name: options[:consumer_name]),
|
|
57
|
-
:provider => Pact::ServiceProvider.new(name: options[:provider_name]),
|
|
58
|
-
:interactions => options[:interactions]})
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
class ResponseFactory
|
|
65
|
-
extend Pact::HashUtils
|
|
66
|
-
DEFAULTS = {:status => 200, :body => {a: 'body'}}.freeze
|
|
67
|
-
def self.create_hash overrides = {}
|
|
68
|
-
deep_merge(DEFAULTS, overrides)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
class RequestFactory
|
|
73
|
-
extend Pact::HashUtils
|
|
74
|
-
DEFAULTS = {:path => '/path', :method => 'get', :query => 'query', :headers => {}}.freeze
|
|
75
|
-
def self.create_hash overrides = {}
|
|
76
|
-
deep_merge(DEFAULTS, overrides)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def self.create_actual overrides = {}
|
|
80
|
-
Pact::Consumer::Request::Actual.from_hash(create_hash(overrides))
|
|
81
|
-
end
|
|
82
|
-
end
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
### A pact between Some Consumer and Some Provider
|
|
2
|
-
|
|
3
|
-
#### Requests from Some Consumer to Some Provider
|
|
4
|
-
|
|
5
|
-
* [A request for alligators](#a_request_for_alligators_given_alligators_exist) given alligators exist
|
|
6
|
-
|
|
7
|
-
* [A request for polar bears](#a_request_for_polar_bears)
|
|
8
|
-
|
|
9
|
-
#### Interactions
|
|
10
|
-
|
|
11
|
-
<a name="a_request_for_alligators_given_alligators_exist"></a>
|
|
12
|
-
Given **alligators exist**, upon receiving **a request for alligators** from Some Consumer, with
|
|
13
|
-
```json
|
|
14
|
-
{
|
|
15
|
-
"method": "get",
|
|
16
|
-
"path": "/alligators"
|
|
17
|
-
}
|
|
18
|
-
```
|
|
19
|
-
Some Provider will respond with:
|
|
20
|
-
```json
|
|
21
|
-
{
|
|
22
|
-
"status": 200,
|
|
23
|
-
"headers": {
|
|
24
|
-
"Content-Type": "application/json"
|
|
25
|
-
},
|
|
26
|
-
"body": {
|
|
27
|
-
"alligators": [
|
|
28
|
-
{
|
|
29
|
-
"name": "Bob",
|
|
30
|
-
"phoneNumber": "12345678"
|
|
31
|
-
}
|
|
32
|
-
]
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
```
|
|
36
|
-
<a name="a_request_for_polar_bears"></a>
|
|
37
|
-
Upon receiving **a request for polar bears** from Some Consumer, with
|
|
38
|
-
```json
|
|
39
|
-
{
|
|
40
|
-
"method": "get",
|
|
41
|
-
"path": "/polar-bears"
|
|
42
|
-
}
|
|
43
|
-
```
|
|
44
|
-
Some Provider will respond with:
|
|
45
|
-
```json
|
|
46
|
-
{
|
|
47
|
-
"status": 404,
|
|
48
|
-
"headers": {
|
|
49
|
-
"Content-Type": "application/json"
|
|
50
|
-
},
|
|
51
|
-
"body": {
|
|
52
|
-
"message": "Sorry, due to climate change, the polar bears are currently unavailable."
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
```
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"provider": {
|
|
3
|
-
"name": "a provider"
|
|
4
|
-
},
|
|
5
|
-
"consumer": {
|
|
6
|
-
"name": "a consumer"
|
|
7
|
-
},
|
|
8
|
-
"interactions": [
|
|
9
|
-
{
|
|
10
|
-
"description": "a request with a body and headers",
|
|
11
|
-
"request": {
|
|
12
|
-
"method": "get",
|
|
13
|
-
"path": "/path",
|
|
14
|
-
"query": "some=thing",
|
|
15
|
-
"headers": {
|
|
16
|
-
"key": "a header"
|
|
17
|
-
},
|
|
18
|
-
"body": {
|
|
19
|
-
"key": "a body"
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
"response": {}
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"description": "a request with an empty body and empty headers",
|
|
26
|
-
"request": {
|
|
27
|
-
"method": "get",
|
|
28
|
-
"path": "/",
|
|
29
|
-
"headers": {},
|
|
30
|
-
"body": {}
|
|
31
|
-
},
|
|
32
|
-
"response": {}
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
"description": "a response with a body and headers",
|
|
36
|
-
"request": {
|
|
37
|
-
"method": "get",
|
|
38
|
-
"path": "/"
|
|
39
|
-
},
|
|
40
|
-
"response": {
|
|
41
|
-
"headers": {
|
|
42
|
-
"key": "a header"
|
|
43
|
-
},
|
|
44
|
-
"body": {
|
|
45
|
-
"key": "a body"
|
|
46
|
-
},
|
|
47
|
-
"status": 200
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
"description": "a response with an empty body and empty headers",
|
|
52
|
-
"request": {
|
|
53
|
-
"method": "get",
|
|
54
|
-
"path": "/"
|
|
55
|
-
},
|
|
56
|
-
"response": {
|
|
57
|
-
"status": 200,
|
|
58
|
-
"headers": {},
|
|
59
|
-
"body": {}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
]
|
|
63
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"provider": {
|
|
3
|
-
"name": "a provider"
|
|
4
|
-
},
|
|
5
|
-
"consumer": {
|
|
6
|
-
"name": "a consumer"
|
|
7
|
-
},
|
|
8
|
-
"interactions": [
|
|
9
|
-
{
|
|
10
|
-
"description": "an interaction with terms",
|
|
11
|
-
"request": {
|
|
12
|
-
"method": "post",
|
|
13
|
-
"path": "/path",
|
|
14
|
-
"query": "some=thing",
|
|
15
|
-
"headers": {
|
|
16
|
-
"key": "a header"
|
|
17
|
-
},
|
|
18
|
-
"body": {
|
|
19
|
-
"term": {
|
|
20
|
-
"json_class": "Pact::Term",
|
|
21
|
-
"data": {
|
|
22
|
-
"generate": "sunny",
|
|
23
|
-
"matcher": {
|
|
24
|
-
"json_class": "Regexp",
|
|
25
|
-
"o": 0,
|
|
26
|
-
"s": "sun"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"response": {
|
|
33
|
-
"status": 200,
|
|
34
|
-
"body": {
|
|
35
|
-
"term": {
|
|
36
|
-
"json_class": "Pact::Term",
|
|
37
|
-
"data": {
|
|
38
|
-
"generate": "rainy",
|
|
39
|
-
"matcher": {
|
|
40
|
-
"json_class": "Regexp",
|
|
41
|
-
"o": 0,
|
|
42
|
-
"s": "rain"
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
]
|
|
50
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"provider": {
|
|
3
|
-
"name": "Some Provider"
|
|
4
|
-
},
|
|
5
|
-
"consumer": {
|
|
6
|
-
"name": "Some Consumer"
|
|
7
|
-
},
|
|
8
|
-
"interactions": [
|
|
9
|
-
{
|
|
10
|
-
"description": "a request for alligators",
|
|
11
|
-
"provider_state": "alligators exist",
|
|
12
|
-
"request": {
|
|
13
|
-
"method": "get",
|
|
14
|
-
"path": "/alligators"
|
|
15
|
-
},
|
|
16
|
-
"response": {
|
|
17
|
-
"headers" : {"Content-Type": "application/json"},
|
|
18
|
-
"status" : 200,
|
|
19
|
-
"body" : {
|
|
20
|
-
"alligators": [{
|
|
21
|
-
"name": "Bob",
|
|
22
|
-
"phoneNumber" : {
|
|
23
|
-
"json_class": "Pact::Term",
|
|
24
|
-
"data": {
|
|
25
|
-
"generate": "12345678",
|
|
26
|
-
"matcher": {"json_class":"Regexp","o":0,"s":"\\d+"}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}]
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
},{
|
|
33
|
-
"description": "a request for polar bears",
|
|
34
|
-
"provider_state": null,
|
|
35
|
-
"request": {
|
|
36
|
-
"method": "get",
|
|
37
|
-
"path": "/polar-bears"
|
|
38
|
-
},
|
|
39
|
-
"response": {
|
|
40
|
-
"headers" : {"Content-Type": "application/json"},
|
|
41
|
-
"status" : 404,
|
|
42
|
-
"body" : {
|
|
43
|
-
"message": "Sorry, due to climate change, the polar bears are currently unavailable."
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
]
|
|
48
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
Pact.provider_states_for "Consumer 1" do
|
|
2
|
-
|
|
3
|
-
provider_state "state1" do
|
|
4
|
-
set_up do
|
|
5
|
-
# Your set up code goes here
|
|
6
|
-
end
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
provider_state "state2" do
|
|
10
|
-
set_up do
|
|
11
|
-
# Your set up code goes here
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
Pact.provider_states_for "Consumer 2" do
|
|
18
|
-
|
|
19
|
-
provider_state "state3" do
|
|
20
|
-
set_up do
|
|
21
|
-
# Your set up code goes here
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
end
|
data/spec/support/options.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"consumer": {
|
|
3
|
-
"name": "Consumer"
|
|
4
|
-
},
|
|
5
|
-
"provider": {
|
|
6
|
-
"name": "Provider"
|
|
7
|
-
},
|
|
8
|
-
"interactions": [
|
|
9
|
-
{
|
|
10
|
-
"description": "an OPTIONS request",
|
|
11
|
-
"request": {
|
|
12
|
-
"method": "options",
|
|
13
|
-
"path": "/"
|
|
14
|
-
},
|
|
15
|
-
"response": {
|
|
16
|
-
"status": 200
|
|
17
|
-
},
|
|
18
|
-
"provider_state": null
|
|
19
|
-
}
|
|
20
|
-
]
|
|
21
|
-
}
|
data/spec/support/options_app.rb
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'pact/provider/rspec'
|
|
2
|
-
|
|
3
|
-
class App
|
|
4
|
-
def self.call env
|
|
5
|
-
if env['REQUEST_METHOD'] == 'OPTIONS'
|
|
6
|
-
[200, {}, []]
|
|
7
|
-
else
|
|
8
|
-
[500, {}, ["Expected an options request"]]
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
Pact.service_provider 'Provider' do
|
|
14
|
-
app { App }
|
|
15
|
-
end
|
data/spec/support/pact_helper.rb
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
# This is the pact_helper for rake pact:tests
|
|
2
|
-
require 'json'
|
|
3
|
-
require 'pact/provider/rspec'
|
|
4
|
-
require './spec/support/active_support_if_configured'
|
|
5
|
-
|
|
6
|
-
module Pact
|
|
7
|
-
module Test
|
|
8
|
-
class TestApp
|
|
9
|
-
def call env
|
|
10
|
-
if env['PATH_INFO'] == '/weather'
|
|
11
|
-
[200, {'Content-Type' => 'application/json'}, [{message: WEATHER[:current_state], :array => [{"foo"=> "blah"}]}.to_json]]
|
|
12
|
-
elsif env['PATH_INFO'] == '/sometext'
|
|
13
|
-
[200, {'Content-Type' => 'text/plain'}, ['some text']]
|
|
14
|
-
elsif env['PATH_INFO'] == '/content_type_is_important'
|
|
15
|
-
[200, {'Content-Type' => 'application/json'}, [{message: "A message", note: "This will cause verify to fail if it using the wrong content type differ."}.to_json]]
|
|
16
|
-
else
|
|
17
|
-
raise "unexpected path #{env['PATH_INFO']}!!!"
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
Pact.configure do | config |
|
|
23
|
-
config.logger.level = Logger::DEBUG
|
|
24
|
-
config.diff_formatter = :unix
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
Pact.service_provider "Some Provider" do
|
|
28
|
-
app { TestApp.new }
|
|
29
|
-
|
|
30
|
-
honours_pact_with 'some-test-consumer' do
|
|
31
|
-
pact_uri './spec/support/test_app_pass.json'
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
Pact.set_up do
|
|
36
|
-
WEATHER ||= {}
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
#one with a top level consumer
|
|
40
|
-
Pact.provider_states_for 'some-test-consumer' do
|
|
41
|
-
|
|
42
|
-
provider_state "the weather is sunny" do
|
|
43
|
-
set_up do
|
|
44
|
-
|
|
45
|
-
WEATHER[:current_state] = 'sunny'
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
#one without a top level consumer
|
|
51
|
-
Pact.provider_state "the weather is cloudy" do
|
|
52
|
-
set_up do
|
|
53
|
-
WEATHER[:current_state] = 'cloudy'
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|