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/lib/pacto/server.rb
ADDED
@@ -1,22 +1,32 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
module Pacto
|
2
3
|
class UriPattern
|
3
4
|
class << self
|
4
|
-
def for(request)
|
5
|
-
|
6
|
-
|
5
|
+
def for(request, strict = Pacto.configuration.strict_matchers)
|
6
|
+
fix_deprecations(request)
|
7
|
+
|
8
|
+
build_template_uri_pattern(request, strict)
|
9
|
+
end
|
10
|
+
|
11
|
+
def build_template_uri_pattern(request, strict)
|
12
|
+
path = request.path.respond_to?(:pattern) ? request.path.pattern : request.path
|
13
|
+
host = request.host ||= '{server}'
|
14
|
+
scheme, host = host.split('://') if host.include?('://')
|
15
|
+
scheme ||= '{scheme}'
|
16
|
+
|
17
|
+
if strict
|
18
|
+
Addressable::Template.new("#{scheme}://#{host}#{path}")
|
7
19
|
else
|
8
|
-
|
20
|
+
Addressable::Template.new("#{scheme}://#{host}#{path}{?anyvars*}")
|
9
21
|
end
|
10
22
|
end
|
11
23
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
24
|
+
def fix_deprecations(request)
|
25
|
+
return if request.path.is_a? Addressable::Template
|
26
|
+
return if request.path == (corrected_path = request.path.gsub(/\/:(\w+)/, '/{\\1}'))
|
15
27
|
|
16
|
-
|
17
|
-
|
18
|
-
host_pattern = Regexp.quote(request.host)
|
19
|
-
/#{host_pattern}#{path_pattern}/
|
28
|
+
Pacto::UI.deprecation "Please change path #{request.path} to uri template: #{corrected_path}"
|
29
|
+
request.path = Addressable::Template.new(corrected_path)
|
20
30
|
end
|
21
31
|
end
|
22
32
|
end
|
@@ -1,47 +1,86 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# -*- encoding : utf-8 -*-
|
3
2
|
module Pacto
|
3
|
+
module Adapters
|
4
|
+
module WebMock
|
5
|
+
class PactoRequest < Pacto::PactoRequest
|
6
|
+
extend Forwardable
|
7
|
+
def_delegators :@webmock_request_signature, :headers, :method, :body, :uri, :to_s, :inspect
|
8
|
+
|
9
|
+
def initialize(webmock_request_signature)
|
10
|
+
@webmock_request_signature = webmock_request_signature
|
11
|
+
end
|
12
|
+
|
13
|
+
def params
|
14
|
+
@webmock_request_signature.uri.query_values
|
15
|
+
end
|
16
|
+
|
17
|
+
def path
|
18
|
+
@webmock_request_signature.uri.path
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class PactoResponse < Pacto::PactoResponse
|
23
|
+
extend Forwardable
|
24
|
+
def_delegators :@webmock_response, :body, :body=, :headers=, :status=, :to_s, :inspect
|
25
|
+
|
26
|
+
def initialize(webmock_response)
|
27
|
+
@webmock_response = webmock_response
|
28
|
+
end
|
29
|
+
|
30
|
+
def headers
|
31
|
+
@webmock_response.headers || {}
|
32
|
+
end
|
33
|
+
|
34
|
+
def status
|
35
|
+
status, _ = @webmock_response.status
|
36
|
+
status
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
4
41
|
module Stubs
|
5
42
|
class WebMockAdapter
|
6
|
-
|
7
|
-
|
43
|
+
include Resettable
|
44
|
+
|
45
|
+
def initialize(middleware)
|
46
|
+
@middleware = middleware
|
47
|
+
|
48
|
+
WebMock.after_request do |webmock_request_signature, webmock_response|
|
49
|
+
process_hooks webmock_request_signature, webmock_response
|
50
|
+
end
|
8
51
|
end
|
9
52
|
|
10
|
-
def stub_request!(
|
11
|
-
|
12
|
-
|
53
|
+
def stub_request!(contract)
|
54
|
+
request_clause = contract.request
|
55
|
+
uri_pattern = UriPattern.for(request_clause)
|
56
|
+
stub = WebMock.stub_request(request_clause.http_method, uri_pattern)
|
13
57
|
|
14
|
-
stub.request_pattern.with(strict_details(
|
58
|
+
stub.request_pattern.with(strict_details(request_clause)) if Pacto.configuration.strict_matchers
|
15
59
|
|
16
|
-
stub.to_return
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
60
|
+
stub.to_return do |request|
|
61
|
+
pacto_request = Pacto::Adapters::WebMock::PactoRequest.new request
|
62
|
+
response = contract.response_for pacto_request
|
63
|
+
{
|
64
|
+
status: response.status,
|
65
|
+
headers: response.headers,
|
66
|
+
body: format_body(response.body)
|
67
|
+
}
|
68
|
+
end
|
21
69
|
end
|
22
70
|
|
23
|
-
def reset!
|
71
|
+
def self.reset!
|
24
72
|
WebMock.reset!
|
25
73
|
WebMock.reset_callbacks
|
26
74
|
end
|
27
75
|
|
28
|
-
def process_hooks(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
Pacto.configuration.hook.process contracts, request_signature, response
|
33
|
-
|
34
|
-
WebMockHelper.validate(request_signature, response) if Pacto.validating?
|
76
|
+
def process_hooks(webmock_request_signature, webmock_response)
|
77
|
+
pacto_request = Pacto::Adapters::WebMock::PactoRequest.new webmock_request_signature
|
78
|
+
pacto_response = Pacto::Adapters::WebMock::PactoResponse.new webmock_response
|
79
|
+
@middleware.process pacto_request, pacto_response
|
35
80
|
end
|
36
81
|
|
37
82
|
private
|
38
83
|
|
39
|
-
def register_hooks
|
40
|
-
WebMock.after_request do |request_signature, response|
|
41
|
-
process_hooks request_signature, response
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
84
|
def format_body(body)
|
46
85
|
if body.is_a?(Hash) || body.is_a?(Array)
|
47
86
|
body.to_json
|
@@ -52,17 +91,13 @@ module Pacto
|
|
52
91
|
|
53
92
|
def strict_details(request)
|
54
93
|
{}.tap do |details|
|
55
|
-
unless request.params.empty?
|
56
|
-
|
57
|
-
end
|
58
|
-
unless request.headers.empty?
|
59
|
-
details[:headers] = request.headers
|
60
|
-
end
|
94
|
+
details[webmock_params_key(request)] = request.params unless request.params.empty?
|
95
|
+
details[:headers] = request.headers unless request.headers.empty?
|
61
96
|
end
|
62
97
|
end
|
63
98
|
|
64
99
|
def webmock_params_key(request)
|
65
|
-
request.
|
100
|
+
request.http_method == :get ? :query : :body
|
66
101
|
end
|
67
102
|
end
|
68
103
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'swagger'
|
3
|
+
|
4
|
+
module Pacto
|
5
|
+
# Builds {Pacto::Contract} instances from Swagger documents
|
6
|
+
class SwaggerContractFactory
|
7
|
+
include Logger
|
8
|
+
|
9
|
+
def load_hints(contract_path, host = nil)
|
10
|
+
app = Swagger.load(contract_path)
|
11
|
+
app.operations.map do |op|
|
12
|
+
Pacto::Generator::Hint.new(request_clause_hash(op, host).merge(
|
13
|
+
service_name: op.fetch(:summary)
|
14
|
+
))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def build_from_file(contract_path, host = nil)
|
19
|
+
app = Swagger.load(contract_path)
|
20
|
+
app.operations.map do |op|
|
21
|
+
default_response = op.default_response
|
22
|
+
request = Pacto::RequestClause.new(request_clause_hash(op, host))
|
23
|
+
response = Pacto::ResponseClause.new(response_clause_hash(op, default_response, host))
|
24
|
+
Contract.new(
|
25
|
+
id: op.operationId,
|
26
|
+
name: op.full_name,
|
27
|
+
file: contract_path,
|
28
|
+
request: request, response: response,
|
29
|
+
examples: build_examples(op, default_response)
|
30
|
+
)
|
31
|
+
end
|
32
|
+
rescue ArgumentError => e
|
33
|
+
raise "Could not load #{contract_path}: #{e.message}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def files_for(contracts_dir)
|
37
|
+
full_path = Pathname.new(contracts_dir).realpath
|
38
|
+
|
39
|
+
if full_path.directory?
|
40
|
+
all_json_files = "#{full_path}/**/*.{json,yaml,yml}"
|
41
|
+
Dir.glob(all_json_files).map do |f|
|
42
|
+
Pathname.new(f)
|
43
|
+
end
|
44
|
+
else
|
45
|
+
[full_path]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def request_clause_hash(op, host)
|
52
|
+
{
|
53
|
+
host: op.host || host,
|
54
|
+
http_method: op.verb,
|
55
|
+
path: op.path
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def response_clause_hash(op, response, _host)
|
60
|
+
if response.nil?
|
61
|
+
logger.warn("No response defined for #{op.full_name}")
|
62
|
+
return Pacto::ResponseClause.new(status: 200)
|
63
|
+
end
|
64
|
+
|
65
|
+
{}.tap do | response_clause |
|
66
|
+
response_clause[:status] = response.status_code || 200
|
67
|
+
response_clause[:schema] = response.schema.parse unless response.schema.nil?
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def build_examples(op, response)
|
72
|
+
return nil if response.nil? || response.examples.nil? || response.examples.empty?
|
73
|
+
|
74
|
+
{
|
75
|
+
default: {
|
76
|
+
request: {}, # Swagger doesn't have a clear way to capture request examples
|
77
|
+
response: {
|
78
|
+
body: response.examples.values.first.parse
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
rescue => e # FIXME: Only parsing errors?
|
83
|
+
logger.warn("Error while trying to parse response example for #{op.full_name}")
|
84
|
+
logger.debug(" Error details: #{e.inspect}")
|
85
|
+
nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
Pacto::ContractFactory.add_factory(:swagger, Pacto::SwaggerContractFactory.new)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
begin
|
3
|
+
require 'pacto'
|
4
|
+
require 'goliath/test_helper'
|
5
|
+
require 'pacto/server'
|
6
|
+
rescue LoadError
|
7
|
+
raise 'pacto/test_helper requires the goliath and pacto-server gems'
|
8
|
+
end
|
9
|
+
|
10
|
+
module Pacto
|
11
|
+
module TestHelper
|
12
|
+
include Goliath::TestHelper
|
13
|
+
DEFAULT_ARGS = {
|
14
|
+
stdout: true,
|
15
|
+
log_file: 'pacto.log',
|
16
|
+
# :config => 'pacto/config/pacto_server.rb',
|
17
|
+
strict: false,
|
18
|
+
stub: true,
|
19
|
+
live: false,
|
20
|
+
generate: false,
|
21
|
+
verbose: true,
|
22
|
+
validate: true,
|
23
|
+
directory: File.join(Dir.pwd, 'spec', 'fixtures', 'contracts'),
|
24
|
+
port: 9000
|
25
|
+
}
|
26
|
+
|
27
|
+
def with_pacto(args = DEFAULT_ARGS)
|
28
|
+
args = DEFAULT_ARGS.merge args
|
29
|
+
with_api(Pacto::Server::API, args) do
|
30
|
+
EM::Synchrony.defer do
|
31
|
+
yield "http://localhost:#{@test_server_port}"
|
32
|
+
EM.stop
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/pacto/ui.rb
CHANGED
@@ -1,7 +1,37 @@
|
|
1
|
-
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'thor'
|
2
3
|
|
3
4
|
module Pacto
|
4
5
|
module UI
|
5
|
-
|
6
|
+
# Colors for HTTP Methods, intended to match colors of Swagger-UI (as close as possible with ANSI Colors)
|
7
|
+
METHOD_COLORS = {
|
8
|
+
'POST' => :green,
|
9
|
+
'PUT' => :yellow,
|
10
|
+
'DELETE' => :red,
|
11
|
+
'GET' => :blue,
|
12
|
+
'PATCH' => :yellow,
|
13
|
+
'HEAD' => :green
|
14
|
+
}
|
15
|
+
|
16
|
+
def self.shell
|
17
|
+
@shell ||= Thor::Shell::Color.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.deprecation(msg)
|
21
|
+
$stderr.puts colorize(msg, :yellow) unless Pacto.configuration.hide_deprecations
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.colorize(msg, color)
|
25
|
+
return msg unless Pacto.configuration.color
|
26
|
+
|
27
|
+
shell.set_color(msg, color)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.colorize_method(method)
|
31
|
+
method_string = method.to_s.upcase
|
32
|
+
|
33
|
+
color = METHOD_COLORS[method_string] || :red # red for unknown methods
|
34
|
+
colorize(method_string, color)
|
35
|
+
end
|
6
36
|
end
|
7
37
|
end
|
data/lib/pacto/uri.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
module Pacto
|
2
3
|
class URI
|
3
4
|
def self.for(host, path, params = {})
|
4
5
|
Addressable::URI.heuristic_parse("#{host}#{path}").tap do |uri|
|
5
|
-
uri.query_values = params unless params.empty?
|
6
|
+
uri.query_values = params unless params.nil? || params.empty?
|
6
7
|
end
|
7
8
|
end
|
8
9
|
end
|
data/lib/pacto/version.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'pacto/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'pacto-server'
|
7
|
+
gem.version = Pacto::VERSION
|
8
|
+
gem.authors = ['ThoughtWorks']
|
9
|
+
gem.email = ['pacto-gem@googlegroups.com']
|
10
|
+
gem.description = "Pacto Server let's you run Pacto as a standalone server to arbitrate contract disputes between a service provider and one or more consumers in any programming language. It's Pacto beyond Ruby"
|
11
|
+
gem.summary = 'Polyglot Integration Contract Testing server'
|
12
|
+
gem.homepage = 'http://thoughtworks.github.io/pacto/'
|
13
|
+
gem.license = 'MIT'
|
14
|
+
|
15
|
+
gem.files = `git ls-files -- bin/pacto-server lib/pacto/server`.split($/) # rubocop:disable SpecialGlobalVars
|
16
|
+
gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(/^(test|spec|features)\//)
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.add_dependency 'pacto', Pacto::VERSION
|
21
|
+
gem.add_dependency 'goliath', '~> 1.0'
|
22
|
+
gem.add_dependency 'em-synchrony', '~> 1.0'
|
23
|
+
gem.add_dependency 'em-http-request', '~> 1.1'
|
24
|
+
end
|
data/pacto.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'pacto/version'
|
@@ -12,8 +11,8 @@ Gem::Specification.new do |gem|
|
|
12
11
|
gem.version = Pacto::VERSION
|
13
12
|
gem.authors = ['ThoughtWorks & Abril']
|
14
13
|
gem.email = ['pacto-gem@googlegroups.com']
|
15
|
-
gem.description =
|
16
|
-
gem.summary =
|
14
|
+
gem.description = 'Pacto is a judge that arbitrates contract disputes between a service provider and one or more consumers. In other words, it is a framework for Integration Contract Testing, and helps guide service evolution patterns like Consumer-Driven Contracts or Documentation-Driven Contracts.'
|
15
|
+
gem.summary = 'Integration Contract Testing framework'
|
17
16
|
gem.homepage = 'http://thoughtworks.github.io/pacto/'
|
18
17
|
gem.license = 'MIT'
|
19
18
|
|
@@ -22,27 +21,32 @@ Gem::Specification.new do |gem|
|
|
22
21
|
gem.test_files = gem.files.grep(/^(test|spec|features)\//)
|
23
22
|
gem.require_paths = ['lib']
|
24
23
|
|
25
|
-
gem.add_dependency 'webmock', '~> 1.
|
24
|
+
gem.add_dependency 'webmock', '~> 1.18', '< 1.20.3'
|
25
|
+
gem.add_dependency 'swagger-core', '~> 0.2', '>= 0.2.1'
|
26
26
|
gem.add_dependency 'middleware', '~> 0.1'
|
27
27
|
gem.add_dependency 'multi_json', '~> 1.8'
|
28
28
|
gem.add_dependency 'json-schema', '~> 2.0'
|
29
29
|
gem.add_dependency 'json-generator', '~> 0.0', '>= 0.0.5'
|
30
|
-
gem.add_dependency '
|
30
|
+
gem.add_dependency 'hashie', '~> 3.0'
|
31
31
|
gem.add_dependency 'faraday', '~> 0.9'
|
32
32
|
gem.add_dependency 'addressable', '~> 2.3'
|
33
33
|
gem.add_dependency 'json-schema-generator', '~> 0.0', '>= 0.0.7'
|
34
|
-
gem.add_dependency '
|
34
|
+
gem.add_dependency 'thor', '~> 0.19'
|
35
35
|
|
36
|
+
gem.add_development_dependency 'polytrix', '~> 0.1', '>= 0.1.4'
|
36
37
|
gem.add_development_dependency 'coveralls', '~> 0'
|
38
|
+
gem.add_development_dependency 'fabrication', '~> 2.11'
|
37
39
|
gem.add_development_dependency 'rake', '~> 10.0'
|
38
40
|
gem.add_development_dependency 'rake-notes', '~> 0'
|
39
|
-
gem.add_development_dependency 'rspec', '~>
|
40
|
-
gem.add_development_dependency 'should_not', '~> 1.0'
|
41
|
+
gem.add_development_dependency 'rspec', '~> 3.0'
|
41
42
|
gem.add_development_dependency 'aruba', '~> 0'
|
43
|
+
gem.add_development_dependency 'json_spec', '~> 1.0'
|
42
44
|
# Only required to push documentation, and not easily installed on Windows
|
43
45
|
# gem.add_development_dependency 'relish'
|
44
46
|
gem.add_development_dependency 'guard-rspec', '~> 4.2'
|
45
|
-
|
47
|
+
# FIXME: Rubocop upgrade needed... rubocop -a will do most of the work
|
48
|
+
gem.add_development_dependency 'rubocop', '~> 0.23', '< 0.27.0'
|
49
|
+
gem.add_development_dependency 'rubocop-rspec', '~> 1.0.rc3'
|
46
50
|
gem.add_development_dependency 'guard-rubocop', '~> 1.0'
|
47
51
|
gem.add_development_dependency 'guard-cucumber', '~> 1.4'
|
48
52
|
gem.add_development_dependency 'rb-fsevent', '~> 0' if RUBY_PLATFORM =~ /darwin/i
|