pacto 0.3.1 → 0.4.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +29 -7
- data/.travis.yml +8 -1
- data/CONTRIBUTING.md +3 -6
- data/Gemfile +13 -2
- data/Guardfile +4 -4
- data/Procfile +1 -0
- data/README.md +47 -13
- data/Rakefile +66 -19
- data/TODO.md +33 -10
- data/bin/pacto +4 -0
- data/changelog.md +30 -0
- data/docs/configuration.md +69 -0
- data/docs/consumer.md +18 -0
- data/docs/cops.md +39 -0
- data/docs/forensics.md +66 -0
- data/docs/generation.md +65 -0
- data/docs/rake_tasks.md +10 -0
- data/docs/rspec.md +0 -0
- data/docs/samples.md +133 -0
- data/docs/server.md +34 -0
- data/docs/server_cli.md +18 -0
- data/docs/stenographer.md +20 -0
- data/features/configuration/strict_matchers.feature +10 -10
- data/features/evolve/existing_services.feature +12 -10
- data/features/generate/generation.feature +11 -11
- data/features/steps/pacto_steps.rb +17 -12
- data/features/stub/templates.feature +4 -4
- data/features/support/env.rb +21 -9
- data/features/validate/meta_validation.feature +9 -17
- data/features/validate/validation.feature +5 -6
- data/lib/pacto.rb +41 -33
- data/lib/pacto/actor.rb +5 -0
- data/lib/pacto/actors/from_examples.rb +67 -0
- data/lib/pacto/actors/json_generator.rb +20 -0
- data/lib/pacto/cli.rb +75 -0
- data/lib/pacto/cli/helpers.rb +20 -0
- data/lib/pacto/consumer.rb +80 -0
- data/lib/pacto/consumer/faraday_driver.rb +34 -0
- data/lib/pacto/contract.rb +48 -20
- data/lib/pacto/contract_builder.rb +125 -0
- data/lib/pacto/contract_factory.rb +31 -12
- data/lib/pacto/contract_files.rb +1 -0
- data/lib/pacto/contract_set.rb +12 -0
- data/lib/pacto/cops.rb +46 -0
- data/lib/pacto/cops/body_cop.rb +23 -0
- data/lib/pacto/cops/request_body_cop.rb +10 -0
- data/lib/pacto/cops/response_body_cop.rb +10 -0
- data/lib/pacto/{validators/response_header_validator.rb → cops/response_header_cop.rb} +9 -15
- data/lib/pacto/cops/response_status_cop.rb +18 -0
- data/lib/pacto/core/configuration.rb +16 -5
- data/lib/pacto/core/contract_registry.rb +13 -32
- data/lib/pacto/core/hook.rb +1 -0
- data/lib/pacto/core/http_middleware.rb +23 -0
- data/lib/pacto/core/investigation_registry.rb +60 -0
- data/lib/pacto/core/modes.rb +1 -0
- data/lib/pacto/core/pacto_request.rb +59 -0
- data/lib/pacto/core/pacto_response.rb +41 -0
- data/lib/pacto/dash.rb +9 -0
- data/lib/pacto/erb_processor.rb +1 -0
- data/lib/pacto/exceptions/invalid_contract.rb +1 -0
- data/lib/pacto/extensions.rb +3 -16
- data/lib/pacto/forensics/investigation_filter.rb +90 -0
- data/lib/pacto/forensics/investigation_matcher.rb +80 -0
- data/lib/pacto/generator.rb +31 -53
- data/lib/pacto/generator/filters.rb +8 -7
- data/lib/pacto/generator/hint.rb +26 -0
- data/lib/pacto/generator/native_contract_generator.rb +74 -0
- data/lib/pacto/hooks/erb_hook.rb +2 -1
- data/lib/pacto/investigation.rb +49 -0
- data/lib/pacto/logger.rb +1 -0
- data/lib/pacto/meta_schema.rb +12 -6
- data/lib/pacto/native_contract_factory.rb +60 -0
- data/lib/pacto/observers/stenographer.rb +42 -0
- data/lib/pacto/provider.rb +27 -0
- data/lib/pacto/rake_task.rb +25 -70
- data/lib/pacto/request_clause.rb +31 -29
- data/lib/pacto/request_pattern.rb +20 -3
- data/lib/pacto/resettable.rb +22 -0
- data/lib/pacto/response_clause.rb +5 -12
- data/lib/pacto/rspec.rb +38 -31
- data/lib/pacto/server.rb +4 -0
- data/lib/pacto/stubs/uri_pattern.rb +21 -11
- data/lib/pacto/stubs/webmock_adapter.rb +69 -34
- data/lib/pacto/swagger_contract_factory.rb +90 -0
- data/lib/pacto/test_helper.rb +37 -0
- data/lib/pacto/ui.rb +32 -2
- data/lib/pacto/uri.rb +2 -1
- data/lib/pacto/version.rb +2 -1
- data/pacto-server.gemspec +24 -0
- data/pacto.gemspec +13 -9
- data/resources/contract_schema.json +46 -18
- data/resources/draft-04.json +150 -0
- data/sample_apis/album/cover_api.rb +12 -0
- data/sample_apis/config.ru +25 -0
- data/sample_apis/echo_api.rb +26 -0
- data/sample_apis/files_api.rb +50 -0
- data/sample_apis/hello_api.rb +14 -0
- data/sample_apis/ping_api.rb +11 -0
- data/sample_apis/reverse_api.rb +20 -0
- data/samples/README.md +11 -0
- data/samples/Rakefile +2 -0
- data/samples/configuration.rb +33 -0
- data/samples/consumer.rb +15 -0
- data/samples/contracts/README.md +1 -0
- data/samples/contracts/contract.js +93 -0
- data/samples/contracts/get_album_cover.json +48 -0
- data/samples/contracts/localhost/api/echo.json +37 -0
- data/samples/contracts/localhost/api/ping.json +38 -0
- data/samples/cops.rb +30 -0
- data/samples/forensics.rb +54 -0
- data/samples/generation.rb +48 -0
- data/samples/rake_tasks.sh +7 -0
- data/samples/rspec.rb +1 -0
- data/samples/samples.rb +92 -0
- data/samples/scripts/bootstrap +2 -0
- data/samples/scripts/wrapper +11 -0
- data/samples/server.rb +24 -0
- data/samples/server_cli.sh +12 -0
- data/samples/stenographer.rb +17 -0
- data/spec/coveralls_helper.rb +1 -0
- data/spec/fabricators/contract_fabricator.rb +94 -0
- data/spec/fabricators/http_fabricator.rb +48 -0
- data/spec/fabricators/webmock_fabricator.rb +24 -0
- data/spec/{unit/data → fixtures/contracts}/contract.json +2 -2
- data/spec/fixtures/contracts/contract_with_examples.json +58 -0
- data/spec/{unit/data → fixtures/contracts}/simple_contract.json +5 -3
- data/spec/{integration/data → fixtures/contracts}/strict_contract.json +5 -3
- data/spec/{integration/data → fixtures/contracts}/templating_contract.json +3 -2
- data/spec/{integration/data/simple_contract.json → fixtures/deprecated_contracts/deprecated_contract.json} +2 -1
- data/spec/fixtures/swagger/petstore.yaml +101 -0
- data/spec/integration/e2e_spec.rb +19 -20
- data/spec/integration/forensics/integration_matcher_spec.rb +90 -0
- data/spec/integration/rspec_spec.rb +22 -25
- data/spec/integration/templating_spec.rb +7 -6
- data/spec/pacto/dummy_server.rb +4 -0
- data/spec/pacto/{server → dummy_server}/dummy.rb +7 -6
- data/spec/pacto/dummy_server/jruby_workaround_helper.rb +23 -0
- data/spec/pacto/{server → dummy_server}/playback_servlet.rb +3 -2
- data/spec/spec_helper.rb +16 -7
- data/spec/unit/actors/from_examples_spec.rb +70 -0
- data/spec/unit/actors/json_generator_spec.rb +105 -0
- data/spec/unit/pacto/actor_spec.rb +23 -0
- data/spec/unit/pacto/configuration_spec.rb +7 -6
- data/spec/unit/pacto/consumer/faraday_driver_spec.rb +40 -0
- data/spec/unit/pacto/contract_builder_spec.rb +89 -0
- data/spec/unit/pacto/contract_factory_spec.rb +62 -11
- data/spec/unit/pacto/contract_files_spec.rb +1 -0
- data/spec/unit/pacto/contract_set_spec.rb +36 -0
- data/spec/unit/pacto/contract_spec.rb +51 -39
- data/spec/unit/pacto/cops/body_cop_spec.rb +107 -0
- data/spec/unit/pacto/{validators/response_header_validator_spec.rb → cops/response_header_cop_spec.rb} +30 -19
- data/spec/unit/pacto/cops/response_status_cop_spec.rb +26 -0
- data/spec/unit/pacto/cops_spec.rb +75 -0
- data/spec/unit/pacto/core/configuration_spec.rb +6 -5
- data/spec/unit/pacto/core/contract_registry_spec.rb +16 -83
- data/spec/unit/pacto/core/http_middleware_spec.rb +36 -0
- data/spec/unit/pacto/core/investigation_spec.rb +62 -0
- data/spec/unit/pacto/core/modes_spec.rb +5 -4
- data/spec/unit/pacto/erb_processor_spec.rb +3 -2
- data/spec/unit/pacto/extensions_spec.rb +10 -20
- data/spec/unit/pacto/generator/filters_spec.rb +11 -10
- data/spec/unit/pacto/generator/native_contract_generator_spec.rb +171 -0
- data/spec/unit/{hooks → pacto/hooks}/erb_hook_spec.rb +18 -11
- data/spec/unit/pacto/investigation_registry_spec.rb +77 -0
- data/spec/unit/pacto/logger_spec.rb +6 -5
- data/spec/unit/pacto/meta_schema_spec.rb +5 -4
- data/spec/unit/pacto/native_contract_factory_spec.rb +26 -0
- data/spec/unit/pacto/pacto_spec.rb +13 -28
- data/spec/unit/pacto/request_clause_spec.rb +16 -51
- data/spec/unit/pacto/request_pattern_spec.rb +6 -5
- data/spec/unit/pacto/response_clause_spec.rb +6 -19
- data/spec/unit/pacto/server/playback_servlet_spec.rb +21 -18
- data/spec/unit/pacto/stubs/observers/stenographer_spec.rb +33 -0
- data/spec/unit/pacto/stubs/uri_pattern_spec.rb +39 -11
- data/spec/unit/pacto/stubs/webmock_adapter_spec.rb +67 -117
- data/spec/unit/pacto/swagger_contract_factory_spec.rb +56 -0
- data/spec/unit/pacto/uri_spec.rb +1 -0
- data/tasks/release.rake +57 -0
- metadata +247 -76
- data/.rubocop-todo.yml +0 -24
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/CHANGELOG +0 -12
- data/features/validate/body_only.feature +0 -85
- data/lib/pacto/contract_list.rb +0 -17
- data/lib/pacto/contract_validator.rb +0 -29
- data/lib/pacto/core/validation_registry.rb +0 -40
- data/lib/pacto/stubs/webmock_helper.rb +0 -69
- data/lib/pacto/validation.rb +0 -54
- data/lib/pacto/validators/body_validator.rb +0 -49
- data/lib/pacto/validators/request_body_validator.rb +0 -26
- data/lib/pacto/validators/response_body_validator.rb +0 -26
- data/lib/pacto/validators/response_status_validator.rb +0 -24
- data/spec/pacto/server.rb +0 -2
- data/spec/unit/pacto/contract_list_spec.rb +0 -35
- data/spec/unit/pacto/contract_validator_spec.rb +0 -85
- data/spec/unit/pacto/core/validation_registry_spec.rb +0 -76
- data/spec/unit/pacto/core/validation_spec.rb +0 -60
- data/spec/unit/pacto/generator_spec.rb +0 -132
- data/spec/unit/pacto/stubs/webmock_helper_spec.rb +0 -20
- data/spec/unit/pacto/validators/body_validator_spec.rb +0 -118
- data/spec/unit/pacto/validators/response_status_validator_spec.rb +0 -20
data/docs/server.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
```rb
|
3
|
+
require 'pacto/rspec'
|
4
|
+
require 'pacto/test_helper'
|
5
|
+
|
6
|
+
describe 'ping service' do
|
7
|
+
include Pacto::TestHelper
|
8
|
+
|
9
|
+
it 'pongs' do
|
10
|
+
with_pacto(
|
11
|
+
port: 6000,
|
12
|
+
backend_host: 'http://localhost:5000',
|
13
|
+
live: true,
|
14
|
+
stub: false,
|
15
|
+
generate: false,
|
16
|
+
directory: 'contracts'
|
17
|
+
) do |pacto_endpoint|
|
18
|
+
```
|
19
|
+
|
20
|
+
call your code
|
21
|
+
|
22
|
+
```rb
|
23
|
+
system "curl #{pacto_endpoint}/api/ping"
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
check citations
|
28
|
+
|
29
|
+
```rb
|
30
|
+
expect(Pacto).to have_validated(:get, 'http://localhost:5000/api/ping')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
data/docs/server_cli.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Standalone server
|
2
|
+
You can run Pacto as a server in order to test non-Ruby projects. In order to get the full set
|
3
|
+
of options, run:
|
4
|
+
|
5
|
+
```sh
|
6
|
+
bundle exec pacto-server -h
|
7
|
+
```
|
8
|
+
|
9
|
+
You probably want to run with the -sv option, which will display verbose output to stdout. You can
|
10
|
+
run server that proxies to a live endpoint:
|
11
|
+
|
12
|
+
```sh
|
13
|
+
bundle exec pacto-server -sv --port 9000 --live http://example.com &
|
14
|
+
bundle exec pacto-server -sv --port 9001 --stub &
|
15
|
+
|
16
|
+
pkill -f pacto-server
|
17
|
+
```
|
18
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
```rb
|
3
|
+
require 'pacto'
|
4
|
+
Pacto.configure do |c|
|
5
|
+
c.contracts_path = 'contracts'
|
6
|
+
end
|
7
|
+
contracts = Pacto.load_contracts('contracts', 'http://localhost:5000')
|
8
|
+
contracts.stub_providers
|
9
|
+
|
10
|
+
Pacto.simulate_consumer do
|
11
|
+
request 'Echo', values: nil, response: { status: 200 } # 0 contract violations
|
12
|
+
request 'Ping', values: nil, response: { status: 200 } # 0 contract violations
|
13
|
+
request 'Unknown (http://localhost:8000/404)', values: nil, response: { status: 500 } # 0 contract violations
|
14
|
+
end
|
15
|
+
|
16
|
+
Pacto.simulate_consumer :my_consumer do
|
17
|
+
playback 'pacto_stenographer.log'
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
@@ -17,7 +17,7 @@ Feature: Strict Matching
|
|
17
17
|
"""json
|
18
18
|
{
|
19
19
|
"request": {
|
20
|
-
"
|
20
|
+
"http_method": "GET",
|
21
21
|
"path": "/hello/:id",
|
22
22
|
"headers": {
|
23
23
|
"Accept": "application/json"
|
@@ -28,7 +28,7 @@ Feature: Strict Matching
|
|
28
28
|
"response": {
|
29
29
|
"status": 200,
|
30
30
|
"headers": { "Content-Type": "application/json" },
|
31
|
-
"
|
31
|
+
"schema": {
|
32
32
|
"type": "object",
|
33
33
|
"required": true,
|
34
34
|
"properties": {
|
@@ -50,7 +50,7 @@ Feature: Strict Matching
|
|
50
50
|
Pacto.configure do |config|
|
51
51
|
config.strict_matchers = strict
|
52
52
|
end
|
53
|
-
Pacto.load_contracts('contracts', 'http://dummyprovider.com').
|
53
|
+
Pacto.load_contracts('contracts', 'http://dummyprovider.com').stub_providers
|
54
54
|
|
55
55
|
def response url, headers
|
56
56
|
begin
|
@@ -67,7 +67,7 @@ Feature: Strict Matching
|
|
67
67
|
puts response 'http://dummyprovider.com/hello/:id', headers: {'Accept' => 'application/json' }
|
68
68
|
|
69
69
|
print 'Wrong headers: '
|
70
|
-
puts response 'http://dummyprovider.com/hello
|
70
|
+
puts response 'http://dummyprovider.com/hello/123', headers: {'Content-Type' => 'application/json' }
|
71
71
|
|
72
72
|
print 'ID placeholder: '
|
73
73
|
puts response 'http://dummyprovider.com/hello/123', headers: {'Accept' => 'application/json' }
|
@@ -75,23 +75,23 @@ Feature: Strict Matching
|
|
75
75
|
|
76
76
|
Scenario: Default (strict) behavior
|
77
77
|
When I run `bundle exec ruby requests.rb true`
|
78
|
-
Then the
|
78
|
+
Then the stdout should contain:
|
79
79
|
"""
|
80
80
|
Pacto.configuration.strict_matchers = true
|
81
81
|
|
82
|
-
Exact:
|
82
|
+
Exact: WebMock::NetConnectNotAllowedError
|
83
83
|
Wrong headers: WebMock::NetConnectNotAllowedError
|
84
|
-
ID placeholder:
|
84
|
+
ID placeholder: {"message":"Hello, world!"}
|
85
85
|
|
86
86
|
"""
|
87
87
|
|
88
88
|
Scenario: Non-strict matching
|
89
89
|
When I run `bundle exec ruby requests.rb false`
|
90
|
-
Then the
|
90
|
+
Then the stdout should contain:
|
91
91
|
"""
|
92
92
|
Pacto.configuration.strict_matchers = false
|
93
93
|
|
94
|
-
Exact:
|
94
|
+
Exact: WebMock::NetConnectNotAllowedError
|
95
95
|
Wrong headers: {"message":"Hello, world!"}
|
96
96
|
ID placeholder: {"message":"Hello, world!"}
|
97
|
-
"""
|
97
|
+
"""
|
@@ -23,14 +23,16 @@ Feature: Existing services journey
|
|
23
23
|
@no-clobber
|
24
24
|
Scenario: Ensuring all contracts are valid
|
25
25
|
When I successfully run `bundle exec rake pacto:meta_validate['contracts']`
|
26
|
-
Then the
|
26
|
+
Then the stdout should contain exactly:
|
27
27
|
"""
|
28
|
-
|
29
|
-
|
28
|
+
validated contracts/www.example.com/service1.json
|
29
|
+
validated contracts/www.example.com/service2.json
|
30
30
|
All contracts successfully meta-validated
|
31
31
|
|
32
32
|
"""
|
33
33
|
|
34
|
+
# TODO: find where Webmock is being called with and an empty :with
|
35
|
+
# and update it, to not use with so we can upgrade Webmock past 1.20.2
|
34
36
|
@no-clobber
|
35
37
|
Scenario: Stubbing with the contracts
|
36
38
|
Given a file named "test.rb" with:
|
@@ -42,16 +44,16 @@ Feature: Existing services journey
|
|
42
44
|
end
|
43
45
|
|
44
46
|
contracts = Pacto.load_contracts('contracts/www.example.com/', 'http://www.example.com')
|
45
|
-
contracts.
|
47
|
+
contracts.stub_providers
|
46
48
|
|
47
49
|
puts Faraday.get('http://www.example.com/service1').body
|
48
50
|
puts Faraday.get('http://www.example.com/service2').body
|
49
51
|
"""
|
50
52
|
When I successfully run `bundle exec ruby test.rb`
|
51
|
-
Then the
|
53
|
+
Then the stdout should contain exactly:
|
52
54
|
"""
|
53
|
-
{"thoughtworks":"
|
54
|
-
{"service2":["
|
55
|
+
{"thoughtworks":"pacto"}
|
56
|
+
{"service2":["thoughtworks","pacto"]}
|
55
57
|
|
56
58
|
"""
|
57
59
|
|
@@ -70,13 +72,13 @@ Feature: Existing services journey
|
|
70
72
|
c.contracts_path = 'contracts'
|
71
73
|
end
|
72
74
|
|
73
|
-
Pacto.load_contracts('contracts', 'http://www.example.com').
|
75
|
+
Pacto.load_contracts('contracts', 'http://www.example.com').stub_providers
|
74
76
|
Pacto.validate!
|
75
77
|
|
76
78
|
Faraday.get 'http://www.example.com/service1'
|
77
79
|
Faraday.get 'http://www.example.com/service2'
|
78
80
|
"""
|
79
|
-
Then the
|
81
|
+
Then the stdout should contain exactly:
|
80
82
|
"""
|
81
|
-
|
83
|
+
|
82
84
|
"""
|
@@ -12,7 +12,7 @@ Feature: Contract Generation
|
|
12
12
|
"""
|
13
13
|
{
|
14
14
|
"request": {
|
15
|
-
"
|
15
|
+
"http_method": "GET",
|
16
16
|
"path": "/hello",
|
17
17
|
"headers": {
|
18
18
|
"Accept": "application/json"
|
@@ -20,7 +20,7 @@ Feature: Contract Generation
|
|
20
20
|
},
|
21
21
|
"response": {
|
22
22
|
"status": 200,
|
23
|
-
"
|
23
|
+
"schema": {
|
24
24
|
"required": true
|
25
25
|
}
|
26
26
|
}
|
@@ -30,29 +30,29 @@ Feature: Contract Generation
|
|
30
30
|
Scenario: Generating a contract using the rake task
|
31
31
|
Given a directory named "contracts"
|
32
32
|
When I successfully run `bundle exec rake pacto:generate['tmp/aruba/requests','tmp/aruba/contracts','http://localhost:8000']`
|
33
|
-
Then the
|
33
|
+
Then the stdout should contain "Successfully generated all contracts"
|
34
34
|
|
35
35
|
Scenario: Generating a contract programmatically
|
36
36
|
Given a file named "generate.rb" with:
|
37
37
|
"""ruby
|
38
38
|
require 'pacto'
|
39
|
+
Pacto.configuration.generator_options[:no_examples] = true
|
39
40
|
|
40
41
|
WebMock.allow_net_connect!
|
41
|
-
generator = Pacto::Generator.
|
42
|
-
contract = generator.
|
42
|
+
generator = Pacto::Generator.contract_generator
|
43
|
+
contract = generator.generate_from_partial_contract('requests/my_contract.json', 'http://localhost:8000')
|
43
44
|
puts contract
|
44
45
|
"""
|
45
46
|
When I successfully run `bundle exec ruby generate.rb`
|
46
|
-
Then the
|
47
|
+
Then the stdout should match this contract:
|
47
48
|
"""json
|
48
49
|
{
|
50
|
+
"name": "/hello",
|
49
51
|
"request": {
|
50
52
|
"headers": {
|
51
53
|
"Accept": "application/json"
|
52
54
|
},
|
53
|
-
"
|
54
|
-
"params": {
|
55
|
-
},
|
55
|
+
"http_method": "get",
|
56
56
|
"path": "/hello"
|
57
57
|
},
|
58
58
|
"response": {
|
@@ -61,7 +61,7 @@ Feature: Contract Generation
|
|
61
61
|
"Vary": "Accept"
|
62
62
|
},
|
63
63
|
"status": 200,
|
64
|
-
"
|
64
|
+
"schema": {
|
65
65
|
"$schema": "http://json-schema.org/draft-03/schema#",
|
66
66
|
"description": "Generated from requests/my_contract.json with shasum 210fa3b144ef2db8d1c160c4d9e8d8bf738ed851",
|
67
67
|
"type": "object",
|
@@ -76,4 +76,4 @@ Feature: Contract Generation
|
|
76
76
|
}
|
77
77
|
}
|
78
78
|
|
79
|
-
"""
|
79
|
+
"""
|
@@ -1,23 +1,24 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
Given(/^Pacto is configured with:$/) do |string|
|
2
|
-
steps %
|
3
|
+
steps %(
|
3
4
|
Given a file named "pacto_config.rb" with:
|
4
5
|
"""ruby
|
5
6
|
#{string}
|
6
7
|
"""
|
7
|
-
|
8
|
+
)
|
8
9
|
end
|
9
10
|
|
10
11
|
Given(/^I have a Rakefile$/) do
|
11
|
-
steps %
|
12
|
+
steps %(
|
12
13
|
Given a file named "Rakefile" with:
|
13
14
|
"""ruby
|
14
15
|
require 'pacto/rake_task'
|
15
16
|
"""
|
16
|
-
|
17
|
+
)
|
17
18
|
end
|
18
19
|
|
19
20
|
When(/^I request "(.*?)"$/) do |url|
|
20
|
-
steps %
|
21
|
+
steps %{
|
21
22
|
Given a file named "request.rb" with:
|
22
23
|
"""ruby
|
23
24
|
require 'pacto'
|
@@ -34,10 +35,10 @@ When(/^I request "(.*?)"$/) do |url|
|
|
34
35
|
end
|
35
36
|
|
36
37
|
Given(/^an existing set of services$/) do
|
37
|
-
WebMock.stub_request(:get, 'www.example.com/service1').to_return(:
|
38
|
-
WebMock.stub_request(:post, 'www.example.com/service1').with(:
|
39
|
-
WebMock.stub_request(:get, 'www.example.com/service2').to_return(:
|
40
|
-
WebMock.stub_request(:post, 'www.example.com/service2').with(:
|
38
|
+
WebMock.stub_request(:get, 'www.example.com/service1').to_return(body: { 'thoughtworks' => 'pacto' }.to_json)
|
39
|
+
WebMock.stub_request(:post, 'www.example.com/service1').with(body: 'thoughtworks').to_return(body: 'pacto')
|
40
|
+
WebMock.stub_request(:get, 'www.example.com/service2').to_return(body: { 'service2' => %w(thoughtworks pacto) }.to_json)
|
41
|
+
WebMock.stub_request(:post, 'www.example.com/service2').with(body: 'thoughtworks').to_return(body: 'pacto')
|
41
42
|
end
|
42
43
|
|
43
44
|
When(/^I execute:$/) do |script|
|
@@ -54,11 +55,10 @@ When(/^I execute:$/) do |script|
|
|
54
55
|
end
|
55
56
|
eof
|
56
57
|
eval(script) # rubocop:disable Eval
|
57
|
-
|
58
|
+
# It's just for testing...
|
58
59
|
|
59
60
|
rescue SyntaxError => e
|
60
|
-
|
61
|
-
puts e.backtrace
|
61
|
+
raise e
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
@@ -73,3 +73,8 @@ When(/^I make replacements in "([^"]*)":$/) do |file_name, replacements|
|
|
73
73
|
File.open(file_name, 'w') { |file| file.write content }
|
74
74
|
end
|
75
75
|
end
|
76
|
+
|
77
|
+
Then(/^the stdout should match this contract:$/) do |expected_contract|
|
78
|
+
actual_contract = all_stdout
|
79
|
+
expect(actual_contract).to be_json_eql(expected_contract).excluding('description')
|
80
|
+
end
|
@@ -8,13 +8,13 @@ Feature: Templating
|
|
8
8
|
Pacto.configure do |c|
|
9
9
|
c.register_hook Pacto::Hooks::ERBHook.new
|
10
10
|
end
|
11
|
-
Pacto.load_contracts('contracts', 'http://example.com').
|
11
|
+
Pacto.load_contracts('contracts', 'http://example.com').stub_providers
|
12
12
|
"""
|
13
13
|
Given a file named "contracts/template.json" with:
|
14
14
|
"""json
|
15
15
|
{
|
16
16
|
"request": {
|
17
|
-
"
|
17
|
+
"http_method": "GET",
|
18
18
|
"path": "/hello",
|
19
19
|
"headers": {
|
20
20
|
"Accept": "application/json"
|
@@ -25,7 +25,7 @@ Feature: Templating
|
|
25
25
|
"response": {
|
26
26
|
"status": 200,
|
27
27
|
"headers": { "Content-Type": "application/json" },
|
28
|
-
"
|
28
|
+
"schema": {
|
29
29
|
"type": "object",
|
30
30
|
"required": true,
|
31
31
|
"properties": {
|
@@ -40,7 +40,7 @@ Feature: Templating
|
|
40
40
|
|
41
41
|
Scenario: ERB Template
|
42
42
|
When I request "http://example.com/hello"
|
43
|
-
Then the
|
43
|
+
Then the stdout should contain:
|
44
44
|
"""
|
45
45
|
{"message":"!dlrow ,olleH"}
|
46
46
|
"""
|
data/features/support/env.rb
CHANGED
@@ -1,22 +1,34 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require_relative '../../spec/coveralls_helper'
|
2
|
-
require 'rake'
|
3
|
-
require 'webmock'
|
4
3
|
require 'aruba'
|
5
4
|
require 'aruba/cucumber'
|
5
|
+
require 'json_spec/cucumber'
|
6
6
|
require 'aruba/jruby' if RUBY_PLATFORM == 'java'
|
7
|
-
|
7
|
+
require 'pacto/test_helper'
|
8
|
+
require_relative '../../spec/pacto/dummy_server'
|
9
|
+
|
10
|
+
Pacto.configuration.hide_deprecations = true
|
8
11
|
|
9
12
|
Before do
|
10
13
|
# Given I successfully run `bundle install` can take a while.
|
11
14
|
@aruba_timeout_seconds = RUBY_PLATFORM == 'java' ? 60 : 10
|
12
15
|
end
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
class PactoWorld
|
18
|
+
include Pacto::TestHelper
|
19
|
+
include Pacto::DummyServer::JRubyWorkaroundHelper
|
20
|
+
end
|
21
|
+
|
22
|
+
World do
|
23
|
+
PactoWorld.new
|
24
|
+
end
|
17
25
|
|
18
|
-
Around do |
|
19
|
-
|
20
|
-
|
26
|
+
Around do | _scenario, block |
|
27
|
+
# This is a cucumber bug (see cucumber #640)
|
28
|
+
world = self || PactoWorld.new
|
29
|
+
world.run_pacto do
|
30
|
+
Bundler.with_clean_env do
|
31
|
+
block.call
|
32
|
+
end
|
21
33
|
end
|
22
34
|
end
|
@@ -9,7 +9,7 @@ Feature: Meta-validation
|
|
9
9
|
"""
|
10
10
|
{
|
11
11
|
"request": {
|
12
|
-
"
|
12
|
+
"http_method": "GET",
|
13
13
|
"path": "/hello_world",
|
14
14
|
"headers": {
|
15
15
|
"Accept": "application/json"
|
@@ -22,9 +22,10 @@ Feature: Meta-validation
|
|
22
22
|
"headers": {
|
23
23
|
"Content-Type": "application/json"
|
24
24
|
},
|
25
|
-
"
|
25
|
+
"schema": {
|
26
26
|
"description": "A simple response",
|
27
27
|
"type": "object",
|
28
|
+
"required": ["message"],
|
28
29
|
"properties": {
|
29
30
|
"message": {
|
30
31
|
"type": "string"
|
@@ -37,16 +38,7 @@ Feature: Meta-validation
|
|
37
38
|
|
38
39
|
Scenario: Meta-validation via a rake task
|
39
40
|
When I successfully run `bundle exec rake pacto:meta_validate['tmp/aruba/contracts/my_contract.json']`
|
40
|
-
Then the
|
41
|
-
|
42
|
-
Scenario: Programmatic meta-validation
|
43
|
-
Given a file named "meta_validate.rb" with:
|
44
|
-
"""ruby
|
45
|
-
require 'pacto'
|
46
|
-
Pacto.validate_contract 'contracts/my_contract.json'
|
47
|
-
"""
|
48
|
-
When I successfully run `bundle exec ruby meta_validate.rb`
|
49
|
-
Then the output should contain "Validating contracts/my_contract.json"
|
41
|
+
Then the stdout should contain "All contracts successfully meta-validated"
|
50
42
|
|
51
43
|
# The tests from here down should probably be specs instead of relish
|
52
44
|
|
@@ -57,7 +49,7 @@ Feature: Meta-validation
|
|
57
49
|
"""
|
58
50
|
When I run `bundle exec rake pacto:meta_validate['tmp/aruba/contracts/my_contract.json']`
|
59
51
|
Then the exit status should be 1
|
60
|
-
And the
|
52
|
+
And the stdout should contain "did not match the following type"
|
61
53
|
|
62
54
|
|
63
55
|
Scenario: Meta-validation of a contract with empty request and response
|
@@ -67,20 +59,20 @@ Feature: Meta-validation
|
|
67
59
|
"""
|
68
60
|
When I run `bundle exec rake pacto:meta_validate['tmp/aruba/contracts/my_contract.json']`
|
69
61
|
Then the exit status should be 1
|
70
|
-
And the
|
62
|
+
And the stdout should contain "did not contain a required property"
|
71
63
|
|
72
64
|
Scenario: Meta-validation of a contracts response body
|
73
65
|
Given a file named "contracts/my_contract.json" with:
|
74
66
|
"""
|
75
67
|
{
|
76
68
|
"request": {
|
77
|
-
"
|
69
|
+
"http_method": "GET",
|
78
70
|
"path": "/hello_world"
|
79
71
|
},
|
80
72
|
|
81
73
|
"response": {
|
82
74
|
"status": 200,
|
83
|
-
"
|
75
|
+
"schema": {
|
84
76
|
"required": "anystring"
|
85
77
|
}
|
86
78
|
}
|
@@ -88,4 +80,4 @@ Feature: Meta-validation
|
|
88
80
|
"""
|
89
81
|
When I run `bundle exec rake pacto:meta_validate['tmp/aruba/contracts/my_contract.json']`
|
90
82
|
Then the exit status should be 1
|
91
|
-
And the
|
83
|
+
And the stdout should contain "did not match the following type"
|