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,26 +0,0 @@
|
|
|
1
|
-
require 'sequel'
|
|
2
|
-
require 'animal_service/db'
|
|
3
|
-
require 'animal_service/animal_repository'
|
|
4
|
-
|
|
5
|
-
Pact.provider_states_for "Zoo App" do
|
|
6
|
-
|
|
7
|
-
set_up do
|
|
8
|
-
AnimalService::DATABASE[:animals].truncate
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
provider_state "there is an alligator named Mary" do
|
|
12
|
-
set_up do
|
|
13
|
-
AnimalService::DATABASE[:animals].insert(name: 'Mary')
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
provider_state "there is not an alligator named Mary" do
|
|
18
|
-
no_op
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
provider_state "an error occurs retrieving an alligator" do
|
|
22
|
-
set_up do
|
|
23
|
-
allow(AnimalService::AnimalRepository).to receive(:find_alligator_by_name).and_raise("Argh!!!")
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
data/example/zoo-app/Gemfile
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: ../../
|
|
3
|
-
specs:
|
|
4
|
-
pact (1.1.0.rc3)
|
|
5
|
-
awesome_print (~> 1.1)
|
|
6
|
-
find_a_port (~> 1.0.1)
|
|
7
|
-
json
|
|
8
|
-
rack-test (~> 0.6.2)
|
|
9
|
-
randexp (~> 0.1.7)
|
|
10
|
-
rspec (~> 2.12)
|
|
11
|
-
term-ansicolor (~> 1.0)
|
|
12
|
-
thor
|
|
13
|
-
webrick
|
|
14
|
-
|
|
15
|
-
GEM
|
|
16
|
-
remote: https://rubygems.org/
|
|
17
|
-
specs:
|
|
18
|
-
awesome_print (1.2.0)
|
|
19
|
-
coderay (1.0.9)
|
|
20
|
-
diff-lcs (1.2.4)
|
|
21
|
-
find_a_port (1.0.1)
|
|
22
|
-
httparty (0.11.0)
|
|
23
|
-
multi_json (~> 1.0)
|
|
24
|
-
multi_xml (>= 0.5.2)
|
|
25
|
-
json (1.6.8)
|
|
26
|
-
method_source (0.8.2)
|
|
27
|
-
multi_json (1.7.9)
|
|
28
|
-
multi_xml (0.5.5)
|
|
29
|
-
pry (0.9.12.2)
|
|
30
|
-
coderay (~> 1.0.5)
|
|
31
|
-
method_source (~> 0.8)
|
|
32
|
-
slop (~> 3.4)
|
|
33
|
-
rack (1.5.2)
|
|
34
|
-
rack-test (0.6.2)
|
|
35
|
-
rack (>= 1.0)
|
|
36
|
-
rake (10.1.0)
|
|
37
|
-
randexp (0.1.7)
|
|
38
|
-
rspec (2.14.1)
|
|
39
|
-
rspec-core (~> 2.14.0)
|
|
40
|
-
rspec-expectations (~> 2.14.0)
|
|
41
|
-
rspec-mocks (~> 2.14.0)
|
|
42
|
-
rspec-core (2.14.5)
|
|
43
|
-
rspec-expectations (2.14.2)
|
|
44
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
|
45
|
-
rspec-mocks (2.14.3)
|
|
46
|
-
slop (3.4.6)
|
|
47
|
-
term-ansicolor (1.3.0)
|
|
48
|
-
tins (~> 1.0)
|
|
49
|
-
thor (0.19.1)
|
|
50
|
-
tins (1.1.0)
|
|
51
|
-
webrick (1.3.1)
|
|
52
|
-
|
|
53
|
-
PLATFORMS
|
|
54
|
-
ruby
|
|
55
|
-
|
|
56
|
-
DEPENDENCIES
|
|
57
|
-
httparty
|
|
58
|
-
json (~> 1.6.8)
|
|
59
|
-
pact!
|
|
60
|
-
pry
|
|
61
|
-
rack (~> 1.5.2)
|
|
62
|
-
rake
|
|
63
|
-
rspec
|
data/example/zoo-app/Rakefile
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
### A pact between Zoo App and Animal Service
|
|
2
|
-
|
|
3
|
-
#### Requests from Zoo App to Animal Service
|
|
4
|
-
|
|
5
|
-
* [A request for an alligator](#a_request_for_an_alligator_given_there_is_an_alligator_named_Mary) given there is an alligator named Mary
|
|
6
|
-
|
|
7
|
-
* [A request for an alligator](#a_request_for_an_alligator_given_there_is_not_an_alligator_named_Mary) given there is not an alligator named Mary
|
|
8
|
-
|
|
9
|
-
* [A request for an alligator](#a_request_for_an_alligator_given_an_error_occurs_retrieving_an_alligator) given an error occurs retrieving an alligator
|
|
10
|
-
|
|
11
|
-
#### Interactions
|
|
12
|
-
|
|
13
|
-
<a name="a_request_for_an_alligator_given_there_is_an_alligator_named_Mary"></a>
|
|
14
|
-
Given **there is an alligator named Mary**, upon receiving **a request for an alligator** from Zoo App, with
|
|
15
|
-
```json
|
|
16
|
-
{
|
|
17
|
-
"method": "get",
|
|
18
|
-
"path": "/alligators/Mary",
|
|
19
|
-
"headers": {
|
|
20
|
-
"Accept": "application/json"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
```
|
|
24
|
-
Animal Service will respond with:
|
|
25
|
-
```json
|
|
26
|
-
{
|
|
27
|
-
"status": 200,
|
|
28
|
-
"headers": {
|
|
29
|
-
"Content-Type": "application/json;charset=utf-8"
|
|
30
|
-
},
|
|
31
|
-
"body": {
|
|
32
|
-
"name": "Mary"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
```
|
|
36
|
-
<a name="a_request_for_an_alligator_given_there_is_not_an_alligator_named_Mary"></a>
|
|
37
|
-
Given **there is not an alligator named Mary**, upon receiving **a request for an alligator** from Zoo App, with
|
|
38
|
-
```json
|
|
39
|
-
{
|
|
40
|
-
"method": "get",
|
|
41
|
-
"path": "/alligators/Mary",
|
|
42
|
-
"headers": {
|
|
43
|
-
"Accept": "application/json"
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
```
|
|
47
|
-
Animal Service will respond with:
|
|
48
|
-
```json
|
|
49
|
-
{
|
|
50
|
-
"status": 404
|
|
51
|
-
}
|
|
52
|
-
```
|
|
53
|
-
<a name="a_request_for_an_alligator_given_an_error_occurs_retrieving_an_alligator"></a>
|
|
54
|
-
Given **an error occurs retrieving an alligator**, upon receiving **a request for an alligator** from Zoo App, with
|
|
55
|
-
```json
|
|
56
|
-
{
|
|
57
|
-
"method": "get",
|
|
58
|
-
"path": "/alligators/Mary",
|
|
59
|
-
"headers": {
|
|
60
|
-
"Accept": "application/json"
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
Animal Service will respond with:
|
|
65
|
-
```json
|
|
66
|
-
{
|
|
67
|
-
"status": 500,
|
|
68
|
-
"headers": {
|
|
69
|
-
"Content-Type": "application/json;charset=utf-8"
|
|
70
|
-
},
|
|
71
|
-
"body": {
|
|
72
|
-
"error": "Argh!!!"
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
```
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
require 'httparty'
|
|
2
|
-
require 'zoo_app/models/alligator'
|
|
3
|
-
|
|
4
|
-
module ZooApp
|
|
5
|
-
class AnimalServiceClient
|
|
6
|
-
|
|
7
|
-
include HTTParty
|
|
8
|
-
base_uri 'animal-service.com'
|
|
9
|
-
|
|
10
|
-
def self.find_alligators
|
|
11
|
-
response = get("/alligators", :headers => {'Accept' => 'application/json'})
|
|
12
|
-
handle_response response do
|
|
13
|
-
parse_body(response).collect do | hash |
|
|
14
|
-
ZooApp::Animals::Alligator.new(hash)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def self.find_alligator_by_name name
|
|
20
|
-
response = get("/alligators/#{name}", :headers => {'Accept' => 'application/json'})
|
|
21
|
-
when_successful(response) do
|
|
22
|
-
ZooApp::Animals::Alligator.new(parse_body(response))
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def self.when_successful response
|
|
27
|
-
if response.success?
|
|
28
|
-
yield
|
|
29
|
-
elsif response.code == 404
|
|
30
|
-
nil
|
|
31
|
-
else
|
|
32
|
-
raise response.body
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def self.parse_body response
|
|
37
|
-
JSON.parse(response.body, {:symbolize_names => true})
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"provider": {
|
|
3
|
-
"name": "Animal Service"
|
|
4
|
-
},
|
|
5
|
-
"consumer": {
|
|
6
|
-
"name": "Zoo App"
|
|
7
|
-
},
|
|
8
|
-
"interactions": [
|
|
9
|
-
{
|
|
10
|
-
"description": "a request for an alligator",
|
|
11
|
-
"provider_state": "there is an alligator named Mary",
|
|
12
|
-
"request": {
|
|
13
|
-
"method": "get",
|
|
14
|
-
"path": "/alligators/Mary",
|
|
15
|
-
"headers": {
|
|
16
|
-
"Accept": "application/json"
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"response": {
|
|
20
|
-
"status": 200,
|
|
21
|
-
"headers": {
|
|
22
|
-
"Content-Type": "application/json;charset=utf-8"
|
|
23
|
-
},
|
|
24
|
-
"body": {
|
|
25
|
-
"name": "Mary"
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
"description": "a request for an alligator",
|
|
31
|
-
"provider_state": "there is not an alligator named Mary",
|
|
32
|
-
"request": {
|
|
33
|
-
"method": "get",
|
|
34
|
-
"path": "/alligators/Mary",
|
|
35
|
-
"headers": {
|
|
36
|
-
"Accept": "application/json"
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
"response": {
|
|
40
|
-
"status": 404
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
"description": "a request for an alligator",
|
|
45
|
-
"provider_state": "an error occurs retrieving an alligator",
|
|
46
|
-
"request": {
|
|
47
|
-
"method": "get",
|
|
48
|
-
"path": "/alligators/Mary",
|
|
49
|
-
"headers": {
|
|
50
|
-
"Accept": "application/json"
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
"response": {
|
|
54
|
-
"status": 500,
|
|
55
|
-
"headers": {
|
|
56
|
-
"Content-Type": "application/json;charset=utf-8"
|
|
57
|
-
},
|
|
58
|
-
"body": {
|
|
59
|
-
"error": "Argh!!!"
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
],
|
|
64
|
-
"metadata": {
|
|
65
|
-
"pactSpecificationVersion": "1.0.0"
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
require_relative 'pact_helper'
|
|
2
|
-
require 'zoo_app/animal_service_client'
|
|
3
|
-
|
|
4
|
-
module ZooApp
|
|
5
|
-
describe AnimalServiceClient, :pact => true do
|
|
6
|
-
|
|
7
|
-
before do
|
|
8
|
-
AnimalServiceClient.base_uri animal_service.mock_service_base_url
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
describe ".find_alligator_by_name" do
|
|
12
|
-
context "when an alligator by the given name exists" do
|
|
13
|
-
|
|
14
|
-
before do
|
|
15
|
-
animal_service.given("there is an alligator named Mary").
|
|
16
|
-
upon_receiving("a request for an alligator").with(
|
|
17
|
-
method: :get,
|
|
18
|
-
path: '/alligators/Mary',
|
|
19
|
-
headers: {'Accept' => 'application/json'} ).
|
|
20
|
-
will_respond_with(
|
|
21
|
-
status: 200,
|
|
22
|
-
headers: {'Content-Type' => 'application/json;charset=utf-8'},
|
|
23
|
-
body: {name: 'Mary'}
|
|
24
|
-
)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it "returns the alligator" do
|
|
28
|
-
expect(AnimalServiceClient.find_alligator_by_name("Mary")).to eq ZooApp::Animals::Alligator.new(name: 'Mary')
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context "when an alligator by the given name does not exist" do
|
|
34
|
-
|
|
35
|
-
before do
|
|
36
|
-
animal_service.given("there is not an alligator named Mary").
|
|
37
|
-
upon_receiving("a request for an alligator").with(
|
|
38
|
-
method: :get,
|
|
39
|
-
path: '/alligators/Mary',
|
|
40
|
-
headers: {'Accept' => 'application/json'} ).
|
|
41
|
-
will_respond_with(status: 404)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it "returns nil" do
|
|
45
|
-
expect(AnimalServiceClient.find_alligator_by_name("Mary")).to be_nil
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
context "when an error occurs retrieving the alligator" do
|
|
51
|
-
|
|
52
|
-
before do
|
|
53
|
-
animal_service.given("an error occurs retrieving an alligator").
|
|
54
|
-
upon_receiving("a request for an alligator").with(
|
|
55
|
-
method: :get,
|
|
56
|
-
path: '/alligators/Mary',
|
|
57
|
-
headers: {'Accept' => 'application/json'}).
|
|
58
|
-
will_respond_with(
|
|
59
|
-
status: 500,
|
|
60
|
-
headers: { 'Content-Type' => 'application/json;charset=utf-8'},
|
|
61
|
-
body: {error: 'Argh!!!'})
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it "raises an error" do
|
|
65
|
-
expect{ AnimalServiceClient.find_alligator_by_name("Mary") }.to raise_error /Argh/
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require_relative '../spec_helper'
|
|
2
|
-
require 'pact/consumer/rspec'
|
|
3
|
-
|
|
4
|
-
Pact.configure do | config |
|
|
5
|
-
config.doc_generator = :markdown
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
Pact.service_consumer 'Zoo App' do
|
|
9
|
-
has_pact_with "Animal Service" do
|
|
10
|
-
mock_service :animal_service do
|
|
11
|
-
port 1234
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
data/lib/pact/configuration.rb
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
require 'ostruct'
|
|
2
|
-
require 'logger'
|
|
3
|
-
require 'pact/doc/markdown/generator'
|
|
4
|
-
require 'pact/matchers/unix_diff_formatter'
|
|
5
|
-
require 'pact/matchers/embedded_diff_formatter'
|
|
6
|
-
require 'pact/matchers/list_diff_formatter'
|
|
7
|
-
require 'pact/shared/json_differ'
|
|
8
|
-
require 'pact/shared/text_differ'
|
|
9
|
-
|
|
10
|
-
module Pact
|
|
11
|
-
|
|
12
|
-
class Configuration
|
|
13
|
-
|
|
14
|
-
DOC_GENERATORS = { markdown: Pact::Doc::Markdown::Generator }
|
|
15
|
-
|
|
16
|
-
DIFF_FORMATTERS = {
|
|
17
|
-
:embedded => Pact::Matchers::EmbeddedDiffFormatter,
|
|
18
|
-
:unix => Pact::Matchers::UnixDiffFormatter,
|
|
19
|
-
:list => Pact::Matchers::ListDiffFormatter
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class NilMatcher
|
|
24
|
-
def self.=~ other
|
|
25
|
-
other == nil ? 0 : nil
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
DIFF_FORMATTER_REGISTRATIONS = [
|
|
30
|
-
[/.*/, Pact::Matchers::UnixDiffFormatter],
|
|
31
|
-
[NilMatcher, Pact::Matchers::UnixDiffFormatter]
|
|
32
|
-
]
|
|
33
|
-
|
|
34
|
-
DIFFERS = [
|
|
35
|
-
[/json/, Pact::JsonDiffer],
|
|
36
|
-
[NilMatcher, Pact::TextDiffer],
|
|
37
|
-
[/.*/, Pact::TextDiffer]
|
|
38
|
-
]
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
DEFAULT_DIFFER = Pact::TextDiffer
|
|
42
|
-
|
|
43
|
-
attr_accessor :pact_dir
|
|
44
|
-
attr_accessor :log_dir
|
|
45
|
-
attr_accessor :doc_dir
|
|
46
|
-
attr_accessor :reports_dir
|
|
47
|
-
attr_writer :logger
|
|
48
|
-
attr_accessor :tmp_dir
|
|
49
|
-
attr_writer :pactfile_write_mode
|
|
50
|
-
|
|
51
|
-
attr_accessor :error_stream
|
|
52
|
-
attr_accessor :output_stream
|
|
53
|
-
|
|
54
|
-
def self.default_configuration
|
|
55
|
-
c = Configuration.new
|
|
56
|
-
c.pact_dir = File.expand_path('./spec/pacts')
|
|
57
|
-
c.tmp_dir = File.expand_path('./tmp/pacts')
|
|
58
|
-
c.log_dir = default_log_dir
|
|
59
|
-
c.pactfile_write_mode = :overwrite
|
|
60
|
-
c.reports_dir = File.expand_path('./reports/pacts')
|
|
61
|
-
c.doc_dir = File.expand_path("./doc/pacts")
|
|
62
|
-
c.output_stream = $stdout
|
|
63
|
-
c.error_stream = $stderr
|
|
64
|
-
c
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def initialize
|
|
68
|
-
@differ_registrations = []
|
|
69
|
-
@diff_formatter_registrations = []
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def logger
|
|
73
|
-
@logger ||= create_logger
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def doc_generator= doc_generator
|
|
77
|
-
doc_generators << begin
|
|
78
|
-
if DOC_GENERATORS[doc_generator]
|
|
79
|
-
DOC_GENERATORS[doc_generator]
|
|
80
|
-
elsif doc_generator.respond_to?(:call)
|
|
81
|
-
doc_generator
|
|
82
|
-
else
|
|
83
|
-
raise "Pact.configuration.doc_generator needs to respond to call, or be in the preconfigured list: #{DOC_GENERATORS.keys}"
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def doc_generators
|
|
89
|
-
@doc_generators ||= []
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
# Should this be deprecated in favour of register_diff_formatter???
|
|
93
|
-
def diff_formatter= diff_formatter
|
|
94
|
-
register_diff_formatter /.*/, diff_formatter
|
|
95
|
-
register_diff_formatter nil, diff_formatter
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def register_diff_formatter content_type, diff_formatter
|
|
99
|
-
key = content_type_regexp_for content_type
|
|
100
|
-
@diff_formatter_registrations << [key, diff_formatter_for(diff_formatter)]
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def diff_formatter_for_content_type content_type
|
|
104
|
-
diff_formatter_registrations.find{ | registration | registration.first =~ content_type }.last
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def register_body_differ content_type, differ
|
|
108
|
-
key = content_type_regexp_for content_type
|
|
109
|
-
validate_differ differ
|
|
110
|
-
@differ_registrations << [key, differ]
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def body_differ_for_content_type content_type
|
|
114
|
-
differ_registrations.find{ | registration | registration.first =~ content_type }.last
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def log_path
|
|
118
|
-
log_dir + "/pact.log"
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def pactfile_write_mode
|
|
122
|
-
if @pactfile_write_mode == :smart
|
|
123
|
-
is_rake_running? ? :overwrite : :update
|
|
124
|
-
else
|
|
125
|
-
@pactfile_write_mode
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
private
|
|
130
|
-
|
|
131
|
-
def diff_formatter_for input
|
|
132
|
-
if DIFF_FORMATTERS[input]
|
|
133
|
-
DIFF_FORMATTERS[input]
|
|
134
|
-
elsif input.respond_to?(:call)
|
|
135
|
-
input
|
|
136
|
-
else
|
|
137
|
-
raise "Pact diff_formatter needs to respond to call, or be in the preconfigured list: #{DIFF_FORMATTERS.keys}"
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def validate_differ differ
|
|
142
|
-
if !differ.respond_to?(:call)
|
|
143
|
-
raise "Pact.configuration.register_body_differ expects a differ that is a lamda or a class/object that responds to call."
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
def content_type_regexp_for content_type
|
|
148
|
-
case content_type
|
|
149
|
-
when String then Regexp.new(/^#{Regexp.escape(content_type)}$/)
|
|
150
|
-
when Regexp then content_type
|
|
151
|
-
when nil then NilMatcher
|
|
152
|
-
else
|
|
153
|
-
raise "Invalid content type used to register a differ (#{content_type.inspect}). Please use a Regexp or a String."
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
def differ_registrations
|
|
158
|
-
@differ_registrations + DIFFERS
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def diff_formatter_registrations
|
|
162
|
-
@diff_formatter_registrations + DIFF_FORMATTER_REGISTRATIONS
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
def self.default_log_dir
|
|
166
|
-
File.expand_path("./log")
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
#Would love a better way of determining this! It sure won't work on windows.
|
|
170
|
-
def is_rake_running?
|
|
171
|
-
`ps -ef | grep rake | grep #{Process.ppid} | grep -v 'grep'`.size > 0
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
def create_logger
|
|
175
|
-
FileUtils::mkdir_p log_dir
|
|
176
|
-
logger = Logger.new(log_path)
|
|
177
|
-
logger.level = Logger::DEBUG
|
|
178
|
-
logger
|
|
179
|
-
end
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
def self.configuration
|
|
183
|
-
@configuration ||= Configuration.default_configuration
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
def self.configure
|
|
187
|
-
yield configuration
|
|
188
|
-
FileUtils::mkdir_p configuration.tmp_dir
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
def self.clear_configuration
|
|
192
|
-
@configuration = nil
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
end
|