pacto 0.4.0.rc1 → 0.4.0.rc2
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/Gemfile +2 -7
- data/Rakefile +0 -5
- data/appveyor.yml +12 -0
- data/features/configuration/strict_matchers.feature +4 -4
- data/features/generate/generation.feature +8 -10
- data/features/support/env.rb +3 -7
- data/features/validate/validation.feature +3 -3
- data/lib/pacto.rb +5 -4
- data/lib/pacto/actors/json_generator.rb +1 -1
- data/lib/pacto/body_parsing.rb +42 -0
- data/lib/pacto/consumer/faraday_driver.rb +5 -2
- data/lib/pacto/contract.rb +23 -24
- data/lib/pacto/contract_factory.rb +4 -4
- data/lib/pacto/core/configuration.rb +18 -10
- data/lib/pacto/core/http_middleware.rb +1 -1
- data/lib/pacto/core/pacto_request.rb +3 -15
- data/lib/pacto/core/pacto_response.rb +3 -13
- data/lib/pacto/errors.rb +68 -0
- data/lib/pacto/formats/legacy/contract.rb +49 -0
- data/lib/pacto/formats/legacy/contract_builder.rb +129 -0
- data/lib/pacto/formats/legacy/contract_factory.rb +63 -0
- data/lib/pacto/formats/legacy/contract_generator.rb +77 -0
- data/lib/pacto/formats/legacy/generator/filters.rb +46 -0
- data/lib/pacto/formats/legacy/generator_hint.rb +36 -0
- data/lib/pacto/formats/legacy/request_clause.rb +39 -0
- data/lib/pacto/formats/legacy/response_clause.rb +31 -0
- data/lib/pacto/formats/swagger/contract.rb +86 -0
- data/lib/pacto/formats/swagger/contract_factory.rb +45 -0
- data/lib/pacto/formats/swagger/request_clause.rb +53 -0
- data/lib/pacto/formats/swagger/response_clause.rb +31 -0
- data/lib/pacto/generator.rb +4 -4
- data/lib/pacto/handlers/json_handler.rb +19 -0
- data/lib/pacto/handlers/text_handler.rb +17 -0
- data/lib/pacto/request_clause.rb +9 -19
- data/lib/pacto/response_clause.rb +4 -4
- data/lib/pacto/server.rb +41 -2
- data/lib/pacto/stubs/uri_pattern.rb +5 -5
- data/lib/pacto/stubs/webmock_adapter.rb +4 -1
- data/lib/pacto/test_helper.rb +16 -13
- data/lib/pacto/version.rb +1 -1
- data/pacto-server.gemspec +1 -3
- data/pacto.gemspec +1 -1
- data/sample_apis/user_api.rb +16 -0
- data/samples/contracts/user.json +51 -0
- data/samples/cops.rb +3 -0
- data/samples/server_cli.sh +3 -3
- data/spec/fabricators/contract_fabricator.rb +17 -8
- data/spec/fixtures/{deprecated_contracts → contracts/deprecated}/deprecated_contract.json +2 -2
- data/spec/fixtures/contracts/{contract.json → legacy/contract.json} +0 -0
- data/spec/fixtures/contracts/{contract_with_examples.json → legacy/contract_with_examples.json} +0 -0
- data/spec/fixtures/contracts/{simple_contract.json → legacy/simple_contract.json} +1 -1
- data/spec/fixtures/contracts/{strict_contract.json → legacy/strict_contract.json} +0 -0
- data/spec/fixtures/contracts/{templating_contract.json → legacy/templating_contract.json} +0 -0
- data/spec/fixtures/{swagger → contracts/swagger}/petstore.yaml +0 -0
- data/spec/integration/e2e_spec.rb +6 -12
- data/spec/integration/forensics/integration_matcher_spec.rb +5 -11
- data/spec/integration/rspec_spec.rb +12 -12
- data/spec/integration/templating_spec.rb +1 -1
- data/spec/spec_helper.rb +14 -2
- data/spec/unit/pacto/contract_factory_spec.rb +1 -2
- data/spec/unit/pacto/contract_spec.rb +44 -70
- data/spec/unit/pacto/core/investigation_spec.rb +4 -3
- data/spec/unit/pacto/formats/legacy/contract_builder_spec.rb +93 -0
- data/spec/unit/pacto/formats/legacy/contract_factory_spec.rb +29 -0
- data/spec/unit/pacto/formats/legacy/contract_generator_spec.rb +173 -0
- data/spec/unit/pacto/formats/legacy/contract_spec.rb +41 -0
- data/spec/unit/pacto/formats/legacy/generator/filters_spec.rb +104 -0
- data/spec/unit/pacto/formats/legacy/request_clause_spec.rb +79 -0
- data/spec/unit/pacto/formats/legacy/response_clause_spec.rb +45 -0
- data/spec/unit/pacto/formats/swagger/contract_factory_spec.rb +58 -0
- data/spec/unit/pacto/formats/swagger/contract_spec.rb +47 -0
- data/spec/unit/pacto/investigation_registry_spec.rb +1 -2
- data/spec/unit/pacto/pacto_spec.rb +6 -4
- data/spec/unit/pacto/stubs/uri_pattern_spec.rb +7 -8
- data/spec/unit/pacto/stubs/webmock_adapter_spec.rb +2 -4
- data/tasks/release.rake +1 -1
- metadata +53 -53
- data/lib/pacto/contract_builder.rb +0 -125
- data/lib/pacto/exceptions/invalid_contract.rb +0 -12
- data/lib/pacto/generator/filters.rb +0 -42
- data/lib/pacto/generator/hint.rb +0 -26
- data/lib/pacto/generator/native_contract_generator.rb +0 -74
- data/lib/pacto/native_contract_factory.rb +0 -60
- data/lib/pacto/swagger_contract_factory.rb +0 -90
- data/spec/pacto/dummy_server.rb +0 -4
- data/spec/pacto/dummy_server/dummy.rb +0 -51
- data/spec/pacto/dummy_server/jruby_workaround_helper.rb +0 -23
- data/spec/pacto/dummy_server/playback_servlet.rb +0 -22
- data/spec/unit/pacto/contract_builder_spec.rb +0 -89
- data/spec/unit/pacto/generator/filters_spec.rb +0 -100
- data/spec/unit/pacto/generator/native_contract_generator_spec.rb +0 -171
- data/spec/unit/pacto/native_contract_factory_spec.rb +0 -26
- data/spec/unit/pacto/request_clause_spec.rb +0 -75
- data/spec/unit/pacto/response_clause_spec.rb +0 -41
- data/spec/unit/pacto/server/playback_servlet_spec.rb +0 -27
- data/spec/unit/pacto/swagger_contract_factory_spec.rb +0 -56
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 11c33cac8327c3a1e1bae2bf3bfe80a350590386
|
|
4
|
+
data.tar.gz: 0a7eb928773e1447537a169076b3802572fc821f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9a4db2ba134723c8b28c11b3f75b902ddc059694e29667d0aae9cbbd25d06dae75ffaee6a4a880439fc0422649d9b110e14d3048bf5089b16b4859d7f676f9f0
|
|
7
|
+
data.tar.gz: 66fca5589aefe93cf77a44f631fbdaee64d6999b6a50f98e28c701bca51d13daa11f222114e0f6f9616274a986add6885f66f3c73c9c2bc1bb5965b7d91a6ff7
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
|
-
PACTO_HOME = File.expand_path '..', __FILE__
|
|
3
2
|
|
|
4
3
|
# Specify your gem's dependencies in pacto.gemspec
|
|
5
|
-
gemspec :
|
|
6
|
-
|
|
7
|
-
Dir["#{PACTO_HOME}/pacto-*.gemspec"].each do |gemspec|
|
|
8
|
-
plugin = gemspec.scan(/pacto-(.*)\.gemspec/).flatten.first
|
|
9
|
-
gemspec(:name => "pacto-#{plugin}", :path => PACTO_HOME, :development_group => plugin)
|
|
10
|
-
end
|
|
4
|
+
gemspec name: 'pacto'
|
|
5
|
+
gemspec name: 'pacto-server'
|
|
11
6
|
|
|
12
7
|
# This is only used by Relish tests. Putting it here let's travis
|
|
13
8
|
# pre-install so we can speed up the test with `bundle install --local`,
|
data/Rakefile
CHANGED
|
@@ -40,11 +40,6 @@ task :samples do
|
|
|
40
40
|
sh 'bundle exec polytrix generate code2doc --solo=samples --solo-glob="*.{rb,sh}"'
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
desc 'Build the documentation from the samples'
|
|
44
|
-
task :documentation do
|
|
45
|
-
sh "docco -t #{Dir.pwd}/docco_embeddable_layout/docco.jst samples/*"
|
|
46
|
-
end
|
|
47
|
-
|
|
48
43
|
desc 'Build gems into the pkg directory'
|
|
49
44
|
task :build do
|
|
50
45
|
FileUtils.rm_rf('pkg')
|
data/appveyor.yml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
version: 0.0.{build}
|
|
2
|
+
init:
|
|
3
|
+
- choco install openssl.light
|
|
4
|
+
- gem install bundler --quiet --no-ri --no-rdoc
|
|
5
|
+
- gem install foreman --quiet --no-ri --no-rdoc
|
|
6
|
+
install:
|
|
7
|
+
- bundle install
|
|
8
|
+
build: off
|
|
9
|
+
test_script:
|
|
10
|
+
- START /B foreman start
|
|
11
|
+
- bundle exec rake
|
|
12
|
+
|
|
@@ -18,7 +18,7 @@ Feature: Strict Matching
|
|
|
18
18
|
{
|
|
19
19
|
"request": {
|
|
20
20
|
"http_method": "GET",
|
|
21
|
-
"path": "/hello
|
|
21
|
+
"path": "/hello/{id}",
|
|
22
22
|
"headers": {
|
|
23
23
|
"Accept": "application/json"
|
|
24
24
|
},
|
|
@@ -64,7 +64,7 @@ Feature: Strict Matching
|
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
print 'Exact: '
|
|
67
|
-
puts response 'http://dummyprovider.com/hello
|
|
67
|
+
puts response URI.encode('http://dummyprovider.com/hello/{id}'), headers: {'Accept' => 'application/json' }
|
|
68
68
|
|
|
69
69
|
print 'Wrong headers: '
|
|
70
70
|
puts response 'http://dummyprovider.com/hello/123', headers: {'Content-Type' => 'application/json' }
|
|
@@ -79,7 +79,7 @@ Feature: Strict Matching
|
|
|
79
79
|
"""
|
|
80
80
|
Pacto.configuration.strict_matchers = true
|
|
81
81
|
|
|
82
|
-
Exact:
|
|
82
|
+
Exact: {"message":"Hello, world!"}
|
|
83
83
|
Wrong headers: WebMock::NetConnectNotAllowedError
|
|
84
84
|
ID placeholder: {"message":"Hello, world!"}
|
|
85
85
|
|
|
@@ -91,7 +91,7 @@ Feature: Strict Matching
|
|
|
91
91
|
"""
|
|
92
92
|
Pacto.configuration.strict_matchers = false
|
|
93
93
|
|
|
94
|
-
Exact:
|
|
94
|
+
Exact: {"message":"Hello, world!"}
|
|
95
95
|
Wrong headers: {"message":"Hello, world!"}
|
|
96
96
|
ID placeholder: {"message":"Hello, world!"}
|
|
97
97
|
"""
|
|
@@ -10,10 +10,10 @@ Feature: Contract Generation
|
|
|
10
10
|
Background:
|
|
11
11
|
Given a file named "requests/my_contract.json" with:
|
|
12
12
|
"""
|
|
13
|
-
|
|
13
|
+
{
|
|
14
14
|
"request": {
|
|
15
15
|
"http_method": "GET",
|
|
16
|
-
"path": "/
|
|
16
|
+
"path": "/api/ping",
|
|
17
17
|
"headers": {
|
|
18
18
|
"Accept": "application/json"
|
|
19
19
|
}
|
|
@@ -29,7 +29,7 @@ Feature: Contract Generation
|
|
|
29
29
|
|
|
30
30
|
Scenario: Generating a contract using the rake task
|
|
31
31
|
Given a directory named "contracts"
|
|
32
|
-
When I successfully run `bundle exec rake pacto:generate['tmp/aruba/requests','tmp/aruba/contracts','http://localhost:
|
|
32
|
+
When I successfully run `bundle exec rake pacto:generate['tmp/aruba/requests','tmp/aruba/contracts','http://localhost:5000']`
|
|
33
33
|
Then the stdout should contain "Successfully generated all contracts"
|
|
34
34
|
|
|
35
35
|
Scenario: Generating a contract programmatically
|
|
@@ -40,25 +40,23 @@ Feature: Contract Generation
|
|
|
40
40
|
|
|
41
41
|
WebMock.allow_net_connect!
|
|
42
42
|
generator = Pacto::Generator.contract_generator
|
|
43
|
-
contract = generator.generate_from_partial_contract('requests/my_contract.json', 'http://localhost:
|
|
43
|
+
contract = generator.generate_from_partial_contract('requests/my_contract.json', 'http://localhost:5000')
|
|
44
44
|
puts contract
|
|
45
45
|
"""
|
|
46
46
|
When I successfully run `bundle exec ruby generate.rb`
|
|
47
47
|
Then the stdout should match this contract:
|
|
48
48
|
"""json
|
|
49
49
|
{
|
|
50
|
-
"name": "/
|
|
50
|
+
"name": "/api/ping",
|
|
51
51
|
"request": {
|
|
52
52
|
"headers": {
|
|
53
|
-
"Accept": "application/json"
|
|
54
53
|
},
|
|
55
54
|
"http_method": "get",
|
|
56
|
-
"path": "/
|
|
55
|
+
"path": "/api/ping"
|
|
57
56
|
},
|
|
58
57
|
"response": {
|
|
59
58
|
"headers": {
|
|
60
|
-
"Content-Type": "application/json"
|
|
61
|
-
"Vary": "Accept"
|
|
59
|
+
"Content-Type": "application/json"
|
|
62
60
|
},
|
|
63
61
|
"status": 200,
|
|
64
62
|
"schema": {
|
|
@@ -67,7 +65,7 @@ Feature: Contract Generation
|
|
|
67
65
|
"type": "object",
|
|
68
66
|
"required": true,
|
|
69
67
|
"properties": {
|
|
70
|
-
"
|
|
68
|
+
"ping": {
|
|
71
69
|
"type": "string",
|
|
72
70
|
"required": true
|
|
73
71
|
}
|
data/features/support/env.rb
CHANGED
|
@@ -5,7 +5,6 @@ require 'aruba/cucumber'
|
|
|
5
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
8
|
|
|
10
9
|
Pacto.configuration.hide_deprecations = true
|
|
11
10
|
|
|
@@ -16,7 +15,6 @@ end
|
|
|
16
15
|
|
|
17
16
|
class PactoWorld
|
|
18
17
|
include Pacto::TestHelper
|
|
19
|
-
include Pacto::DummyServer::JRubyWorkaroundHelper
|
|
20
18
|
end
|
|
21
19
|
|
|
22
20
|
World do
|
|
@@ -24,11 +22,9 @@ World do
|
|
|
24
22
|
end
|
|
25
23
|
|
|
26
24
|
Around do | _scenario, block |
|
|
27
|
-
|
|
25
|
+
WebMock.allow_net_connect!
|
|
28
26
|
world = self || PactoWorld.new
|
|
29
|
-
world.
|
|
30
|
-
|
|
31
|
-
block.call
|
|
32
|
-
end
|
|
27
|
+
world.with_pacto(port: 8000, live: true, backend_host: 'http://localhost:5000') do
|
|
28
|
+
block.call
|
|
33
29
|
end
|
|
34
30
|
end
|
|
@@ -8,7 +8,7 @@ Feature: Validation
|
|
|
8
8
|
{
|
|
9
9
|
"request": {
|
|
10
10
|
"http_method": "GET",
|
|
11
|
-
"path": "/hello",
|
|
11
|
+
"path": "/api/hello",
|
|
12
12
|
"headers": { "Accept": "application/json" },
|
|
13
13
|
"params": {}
|
|
14
14
|
},
|
|
@@ -26,10 +26,10 @@ Feature: Validation
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
"""
|
|
29
|
-
When I successfully run `bundle exec rake pacto:validate['http://localhost:
|
|
29
|
+
When I successfully run `bundle exec rake pacto:validate['http://localhost:5000','tmp/aruba/contracts/simple_contract.json']`
|
|
30
30
|
Then the stdout should contain:
|
|
31
31
|
""""
|
|
32
|
-
Validating contracts against host http://localhost:
|
|
32
|
+
Validating contracts against host http://localhost:5000
|
|
33
33
|
OK! simple_contract.json
|
|
34
34
|
1 valid contract
|
|
35
35
|
"""
|
data/lib/pacto.rb
CHANGED
|
@@ -13,9 +13,10 @@ require 'ostruct'
|
|
|
13
13
|
require 'erb'
|
|
14
14
|
require 'logger'
|
|
15
15
|
|
|
16
|
+
# FIXME: There's soo much stuff here! I'd both like to re-roganize and to use autoloading.
|
|
17
|
+
require 'pacto/errors'
|
|
16
18
|
require 'pacto/dash'
|
|
17
19
|
require 'pacto/resettable'
|
|
18
|
-
require 'pacto/exceptions/invalid_contract.rb'
|
|
19
20
|
require 'pacto/logger'
|
|
20
21
|
require 'pacto/ui'
|
|
21
22
|
require 'pacto/request_pattern'
|
|
@@ -26,6 +27,7 @@ require 'pacto/consumer'
|
|
|
26
27
|
require 'pacto/provider'
|
|
27
28
|
require 'pacto/actors/json_generator'
|
|
28
29
|
require 'pacto/actors/from_examples'
|
|
30
|
+
require 'pacto/body_parsing'
|
|
29
31
|
require 'pacto/core/pacto_request'
|
|
30
32
|
require 'pacto/core/pacto_response'
|
|
31
33
|
require 'pacto/core/contract_registry'
|
|
@@ -46,7 +48,6 @@ require 'pacto/investigation'
|
|
|
46
48
|
require 'pacto/hooks/erb_hook'
|
|
47
49
|
require 'pacto/observers/stenographer'
|
|
48
50
|
require 'pacto/generator'
|
|
49
|
-
require 'pacto/generator/filters'
|
|
50
51
|
require 'pacto/contract_files'
|
|
51
52
|
require 'pacto/contract_set'
|
|
52
53
|
require 'pacto/uri'
|
|
@@ -96,11 +97,11 @@ module Pacto
|
|
|
96
97
|
true
|
|
97
98
|
end
|
|
98
99
|
|
|
99
|
-
def load_contract(contract_path, host, format = :
|
|
100
|
+
def load_contract(contract_path, host, format = :legacy)
|
|
100
101
|
load_contracts(contract_path, host, format).first
|
|
101
102
|
end
|
|
102
103
|
|
|
103
|
-
def load_contracts(contracts_path, host, format = :
|
|
104
|
+
def load_contracts(contracts_path, host, format = :legacy)
|
|
104
105
|
contracts = ContractFactory.load_contracts(contracts_path, host, format)
|
|
105
106
|
contracts.each do |contract|
|
|
106
107
|
contract_registry.register(contract)
|
|
@@ -5,7 +5,7 @@ module Pacto
|
|
|
5
5
|
def build_request(contract, values = {})
|
|
6
6
|
data = contract.request.to_hash
|
|
7
7
|
data['uri'] = contract.request.uri(values)
|
|
8
|
-
data['body'] = JSON::Generator.generate(data['schema'])
|
|
8
|
+
data['body'] = JSON::Generator.generate(data['schema']) if data['schema']
|
|
9
9
|
data['method'] = contract.request.http_method
|
|
10
10
|
Pacto::PactoRequest.new(data)
|
|
11
11
|
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
|
|
3
|
+
module Pacto
|
|
4
|
+
module Handlers
|
|
5
|
+
autoload :JSONHandler, 'pacto/handlers/json_handler'
|
|
6
|
+
autoload :TextHandler, 'pacto/handlers/text_handler'
|
|
7
|
+
autoload :XMLHandler, 'pacto/handlers/xml_handler'
|
|
8
|
+
end
|
|
9
|
+
module BodyParsing
|
|
10
|
+
def raw_body
|
|
11
|
+
return nil if body.nil?
|
|
12
|
+
return body if body.respond_to? :to_str
|
|
13
|
+
|
|
14
|
+
body_handler.raw(body)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def parsed_body
|
|
18
|
+
return nil if body.nil?
|
|
19
|
+
|
|
20
|
+
body_handler.parse(body)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def content_type
|
|
24
|
+
headers['Content-Type']
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def body_handler
|
|
28
|
+
case content_type
|
|
29
|
+
when /\bjson$/
|
|
30
|
+
Pacto::Handlers::JSONHandler
|
|
31
|
+
when /\btext$/
|
|
32
|
+
Pacto::Handlers::TextHandler
|
|
33
|
+
# No XML support - yet
|
|
34
|
+
# when /\bxml$/
|
|
35
|
+
# XMLHandler
|
|
36
|
+
else
|
|
37
|
+
# JSON is still the default
|
|
38
|
+
Pacto::Handlers::JSONHandler
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
module Pacto
|
|
3
3
|
class Consumer
|
|
4
4
|
class FaradayDriver
|
|
5
|
+
include Pacto::Logger
|
|
5
6
|
# Sends a Pacto::PactoRequest
|
|
6
7
|
def execute(req)
|
|
7
|
-
|
|
8
|
+
conn_options = { url: req.uri.site }
|
|
9
|
+
conn_options[:proxy] = Pacto.configuration.proxy if Pacto.configuration.proxy
|
|
10
|
+
conn = Faraday.new(conn_options) do |faraday|
|
|
8
11
|
faraday.response :logger if Pacto.configuration.logger.level == :debug
|
|
9
12
|
faraday.adapter Faraday.default_adapter
|
|
10
13
|
end
|
|
@@ -12,7 +15,7 @@ module Pacto
|
|
|
12
15
|
response = conn.send(req.method) do |faraday_request|
|
|
13
16
|
faraday_request.url(req.uri.path, req.uri.query_values)
|
|
14
17
|
faraday_request.headers = req.headers
|
|
15
|
-
faraday_request.body = req.
|
|
18
|
+
faraday_request.body = req.raw_body
|
|
16
19
|
end
|
|
17
20
|
|
|
18
21
|
faraday_to_pacto_response response
|
data/lib/pacto/contract.rb
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
|
2
2
|
module Pacto
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
property :file
|
|
6
|
-
property :request, required: true
|
|
7
|
-
# Although I'd like response to be required, it complicates
|
|
8
|
-
# the partial contracts used the rake generation task...
|
|
9
|
-
# yet another reason I'd like to deprecate that feature
|
|
10
|
-
property :response # , required: true
|
|
11
|
-
property :values, default: {}
|
|
12
|
-
# Gotta figure out how to use test doubles w/ coercion
|
|
13
|
-
coerce_key :request, RequestClause
|
|
14
|
-
coerce_key :response, ResponseClause
|
|
15
|
-
property :examples
|
|
16
|
-
property :name, required: true
|
|
17
|
-
property :adapter, default: proc { Pacto.configuration.adapter }
|
|
18
|
-
property :consumer, default: proc { Pacto.configuration.default_consumer }
|
|
19
|
-
property :provider, default: proc { Pacto.configuration.default_provider }
|
|
3
|
+
module Contract
|
|
4
|
+
include Logger
|
|
20
5
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
6
|
+
attr_reader :id
|
|
7
|
+
attr_reader :file
|
|
8
|
+
attr_reader :request
|
|
9
|
+
attr_reader :response
|
|
10
|
+
attr_reader :values
|
|
11
|
+
attr_reader :examples
|
|
12
|
+
attr_reader :name
|
|
13
|
+
attr_writer :adapter
|
|
14
|
+
attr_writer :consumer
|
|
15
|
+
attr_writer :provider
|
|
16
|
+
|
|
17
|
+
def adapter
|
|
18
|
+
@adapter ||= Pacto.configuration.adapter
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def consumer
|
|
22
|
+
@consumer ||= Pacto.configuration.default_consumer
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def provider
|
|
26
|
+
@provider ||= Pacto.configuration.default_provider
|
|
28
27
|
end
|
|
29
28
|
|
|
30
29
|
def examples?
|
|
@@ -16,14 +16,14 @@ module Pacto
|
|
|
16
16
|
@factories.delete format
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
def build(contract_files, host, format = :
|
|
19
|
+
def build(contract_files, host, format = :legacy)
|
|
20
20
|
factory = @factories[format.to_sym]
|
|
21
21
|
fail "No Contract factory registered for #{format}" if factory.nil?
|
|
22
22
|
|
|
23
23
|
contract_files.map { |file| factory.build_from_file(file, host) }.flatten
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
def load_contracts(contracts_path, host, format = :
|
|
26
|
+
def load_contracts(contracts_path, host, format = :legacy)
|
|
27
27
|
factory = @factories[format.to_sym]
|
|
28
28
|
files = factory.files_for(contracts_path)
|
|
29
29
|
contracts = ContractFactory.build(files, host, format)
|
|
@@ -37,5 +37,5 @@ module Pacto
|
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
require 'pacto/
|
|
41
|
-
require 'pacto/
|
|
40
|
+
require 'pacto/formats/legacy/contract_factory'
|
|
41
|
+
require 'pacto/formats/swagger/contract_factory'
|
|
@@ -4,25 +4,31 @@ module Pacto
|
|
|
4
4
|
attr_accessor :adapter, :strict_matchers,
|
|
5
5
|
:contracts_path, :logger, :generator_options,
|
|
6
6
|
:hide_deprecations, :default_consumer, :default_provider,
|
|
7
|
-
:stenographer_log_file, :color
|
|
7
|
+
:stenographer_log_file, :color, :proxy
|
|
8
8
|
attr_reader :hook
|
|
9
9
|
|
|
10
|
-
def initialize
|
|
10
|
+
def initialize # rubocop:disable Metrics/MethodLength
|
|
11
11
|
@middleware = Pacto::Core::HTTPMiddleware.new
|
|
12
12
|
@middleware.add_observer Pacto::Cops, :investigate
|
|
13
13
|
@generator = Pacto::Generator.contract_generator
|
|
14
14
|
@middleware.add_observer @generator, :generate
|
|
15
|
-
@stenographer_log_file ||= File.expand_path('pacto_stenographer.log')
|
|
16
15
|
@default_consumer = Pacto::Consumer.new
|
|
17
16
|
@default_provider = Pacto::Provider.new
|
|
18
17
|
@adapter = Stubs::WebMockAdapter.new(@middleware)
|
|
19
18
|
@strict_matchers = true
|
|
20
19
|
@contracts_path = '.'
|
|
21
|
-
@logger = Logger::SimpleLogger.instance
|
|
22
|
-
define_logger_level
|
|
23
20
|
@hook = Hook.new {}
|
|
24
21
|
@generator_options = { schema_version: 'draft3' }
|
|
25
22
|
@color = $stdout.tty?
|
|
23
|
+
@proxy = ENV['PACTO_PROXY']
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def logger
|
|
27
|
+
@logger ||= new_simple_logger
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def stenographer_log_file
|
|
31
|
+
@stenographer_log_file ||= File.expand_path('pacto_stenographer.log')
|
|
26
32
|
end
|
|
27
33
|
|
|
28
34
|
def register_hook(hook = nil, &block)
|
|
@@ -36,11 +42,13 @@ module Pacto
|
|
|
36
42
|
|
|
37
43
|
private
|
|
38
44
|
|
|
39
|
-
def
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
def new_simple_logger
|
|
46
|
+
Logger::SimpleLogger.instance.tap do | logger |
|
|
47
|
+
if ENV['PACTO_DEBUG']
|
|
48
|
+
logger.level = :debug
|
|
49
|
+
else
|
|
50
|
+
logger.level = :default
|
|
51
|
+
end
|
|
44
52
|
end
|
|
45
53
|
end
|
|
46
54
|
end
|