pacto 0.4.0.rc1 → 0.4.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,8 +1,8 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
module Pacto
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module ResponseClause
|
4
|
+
attr_reader :status
|
5
|
+
attr_reader :headers
|
6
|
+
attr_reader :schema
|
7
7
|
end
|
8
8
|
end
|
data/lib/pacto/server.rb
CHANGED
@@ -1,4 +1,43 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
-
require '
|
2
|
+
require 'reel'
|
3
3
|
require 'pacto'
|
4
|
-
|
4
|
+
require_relative 'server/settings'
|
5
|
+
require_relative 'server/proxy'
|
6
|
+
|
7
|
+
module Pacto
|
8
|
+
module Server
|
9
|
+
class HTTP < Reel::Server::HTTP
|
10
|
+
attr_reader :settings, :logger
|
11
|
+
include Proxy
|
12
|
+
|
13
|
+
def initialize(host = '127.0.0.1', port = 3000, options = {})
|
14
|
+
@logger = options[:pacto_logger] || Pacto.configuration.logger
|
15
|
+
@settings = Settings::OptionHandler.new(port, @logger).handle(options)
|
16
|
+
logger.info "Pacto Server starting on #{host}:#{port}"
|
17
|
+
super(host, port, spy: options[:spy], &method(:on_connection))
|
18
|
+
end
|
19
|
+
|
20
|
+
def on_connection(connection)
|
21
|
+
# Support multiple keep-alive requests per connection
|
22
|
+
connection.each_request do |reel_request|
|
23
|
+
begin
|
24
|
+
pacto_request = # exclusive do
|
25
|
+
Pacto::PactoRequest.new(
|
26
|
+
headers: reel_request.headers, body: reel_request.read,
|
27
|
+
method: reel_request.method, uri: Addressable::URI.heuristic_parse(reel_request.uri)
|
28
|
+
)
|
29
|
+
# end
|
30
|
+
|
31
|
+
pacto_response = proxy_request(pacto_request)
|
32
|
+
reel_response = ::Reel::Response.new(pacto_response.status, pacto_response.headers, pacto_response.body)
|
33
|
+
reel_request.respond(reel_response)
|
34
|
+
rescue WebMock::NetConnectNotAllowedError, Faraday::ConnectionFailed => e
|
35
|
+
reel_request.respond 502, e.message
|
36
|
+
rescue => e
|
37
|
+
reel_request.respond 500, Pacto::Errors.formatted_trace(e)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -3,14 +3,15 @@ module Pacto
|
|
3
3
|
class UriPattern
|
4
4
|
class << self
|
5
5
|
def for(request, strict = Pacto.configuration.strict_matchers)
|
6
|
-
|
6
|
+
fail_deprecations(request)
|
7
7
|
|
8
8
|
build_template_uri_pattern(request, strict)
|
9
9
|
end
|
10
10
|
|
11
11
|
def build_template_uri_pattern(request, strict)
|
12
12
|
path = request.path.respond_to?(:pattern) ? request.path.pattern : request.path
|
13
|
-
host = request.host
|
13
|
+
host = request.host
|
14
|
+
host ||= '{server}'
|
14
15
|
scheme, host = host.split('://') if host.include?('://')
|
15
16
|
scheme ||= '{scheme}'
|
16
17
|
|
@@ -21,12 +22,11 @@ module Pacto
|
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
|
-
def
|
25
|
+
def fail_deprecations(request)
|
25
26
|
return if request.path.is_a? Addressable::Template
|
26
27
|
return if request.path == (corrected_path = request.path.gsub(/\/:(\w+)/, '/{\\1}'))
|
27
28
|
|
28
|
-
|
29
|
-
request.path = Addressable::Template.new(corrected_path)
|
29
|
+
fail "please change path #{request.path} to uri template: #{corrected_path} - old syntax no longer supported"
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -55,7 +55,10 @@ module Pacto
|
|
55
55
|
uri_pattern = UriPattern.for(request_clause)
|
56
56
|
stub = WebMock.stub_request(request_clause.http_method, uri_pattern)
|
57
57
|
|
58
|
-
|
58
|
+
if Pacto.configuration.strict_matchers
|
59
|
+
with_opts = strict_details(request_clause)
|
60
|
+
stub.request_pattern.with(with_opts) unless with_opts.empty?
|
61
|
+
end
|
59
62
|
|
60
63
|
stub.to_return do |request|
|
61
64
|
pacto_request = Pacto::Adapters::WebMock::PactoRequest.new request
|
data/lib/pacto/test_helper.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
begin
|
3
3
|
require 'pacto'
|
4
|
-
require 'goliath/test_helper'
|
5
4
|
require 'pacto/server'
|
6
5
|
rescue LoadError
|
7
|
-
raise 'pacto/test_helper requires the
|
6
|
+
raise 'pacto/test_helper requires the pacto-server gem'
|
8
7
|
end
|
9
8
|
|
10
9
|
module Pacto
|
11
10
|
module TestHelper
|
12
|
-
include Goliath::TestHelper
|
13
11
|
DEFAULT_ARGS = {
|
14
12
|
stdout: true,
|
15
13
|
log_file: 'pacto.log',
|
@@ -20,18 +18,23 @@ module Pacto
|
|
20
18
|
generate: false,
|
21
19
|
verbose: true,
|
22
20
|
validate: true,
|
23
|
-
directory: File.join(Dir.pwd, '
|
24
|
-
port: 9000
|
21
|
+
directory: File.join(Dir.pwd, 'contracts'),
|
22
|
+
port: 9000,
|
23
|
+
format: :legacy,
|
24
|
+
stenographer_log_file: File.expand_path('pacto_stenographer.log', Dir.pwd),
|
25
|
+
strip_port: true
|
25
26
|
}
|
26
27
|
|
27
|
-
def with_pacto(args =
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
def with_pacto(args = {})
|
29
|
+
start_index = ::Pacto::InvestigationRegistry.instance.investigations.size
|
30
|
+
::Pacto::InvestigationRegistry.instance.investigations.clear
|
31
|
+
args = DEFAULT_ARGS.merge(args)
|
32
|
+
args[:spy] = args[:verbose]
|
33
|
+
server = Pacto::Server::HTTP.supervise('0.0.0.0', args[:port], args)
|
34
|
+
yield "http://localhost:#{args[:port]}"
|
35
|
+
::Pacto::InvestigationRegistry.instance.investigations[start_index, -1]
|
36
|
+
ensure
|
37
|
+
server.terminate unless server.nil?
|
35
38
|
end
|
36
39
|
end
|
37
40
|
end
|
data/lib/pacto/version.rb
CHANGED
data/pacto-server.gemspec
CHANGED
@@ -18,7 +18,5 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.require_paths = ['lib']
|
19
19
|
|
20
20
|
gem.add_dependency 'pacto', Pacto::VERSION
|
21
|
-
gem.add_dependency '
|
22
|
-
gem.add_dependency 'em-synchrony', '~> 1.0'
|
23
|
-
gem.add_dependency 'em-http-request', '~> 1.1'
|
21
|
+
gem.add_dependency 'reel', '~> 0.5'
|
24
22
|
end
|
data/pacto.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.test_files = gem.files.grep(/^(test|spec|features)\//)
|
22
22
|
gem.require_paths = ['lib']
|
23
23
|
|
24
|
-
gem.add_dependency 'webmock', '~> 1.18'
|
24
|
+
gem.add_dependency 'webmock', '~> 1.18'
|
25
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'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
# A siple JSON service to demonstrate request/response bodies
|
3
|
+
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
module DummyServices
|
7
|
+
class Echo < Grape::API
|
8
|
+
format :json
|
9
|
+
|
10
|
+
post '/users' do
|
11
|
+
user = env['api.request.body']
|
12
|
+
user[:id] = SecureRandom.uuid
|
13
|
+
user
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
{
|
2
|
+
"name": "User",
|
3
|
+
"request": {
|
4
|
+
"headers": {
|
5
|
+
"Content-Type": "application/json"
|
6
|
+
},
|
7
|
+
"http_method": "post",
|
8
|
+
"path": "/api/users",
|
9
|
+
"schema": {
|
10
|
+
"$schema": "http://json-schema.org/draft-03/schema#",
|
11
|
+
"type": "object",
|
12
|
+
"properties": {
|
13
|
+
"firstName": {"type": "string", "required": true},
|
14
|
+
"lastName": {"type": "string", "required": true}
|
15
|
+
}
|
16
|
+
}
|
17
|
+
},
|
18
|
+
"response": {
|
19
|
+
"status": 201,
|
20
|
+
"schema": {
|
21
|
+
"$schema": "http://json-schema.org/draft-03/schema#",
|
22
|
+
"type": "object",
|
23
|
+
"properties": {
|
24
|
+
"id": { "type": "string", "required": true },
|
25
|
+
"firstName": {"type": "string", "required": true},
|
26
|
+
"lastName": {"type": "string", "required": true}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
},
|
30
|
+
"examples": {
|
31
|
+
"max": {
|
32
|
+
"request": {
|
33
|
+
"headers": {
|
34
|
+
"Content-Type": "application/json"
|
35
|
+
},
|
36
|
+
"body": {
|
37
|
+
"firstName": "Max",
|
38
|
+
"lastName": "Lincoln"
|
39
|
+
}
|
40
|
+
},
|
41
|
+
"response": {
|
42
|
+
"body": {
|
43
|
+
"id": "026ed411-6d12-4a76-a3c7-19758a872455",
|
44
|
+
"firstName": "Max",
|
45
|
+
"lastName": "Lincoln"
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
data/samples/cops.rb
CHANGED
data/samples/server_cli.sh
CHANGED
@@ -6,7 +6,7 @@ bundle exec pacto-server -h
|
|
6
6
|
|
7
7
|
# You probably want to run with the -sv option, which will display verbose output to stdout. You can
|
8
8
|
# run server that proxies to a live endpoint:
|
9
|
-
bundle exec pacto
|
10
|
-
bundle exec pacto
|
9
|
+
bundle exec pacto proxy --port 9000 --to http://example.com &
|
10
|
+
bundle exec pacto stub --port 9001 &
|
11
11
|
|
12
|
-
pkill -f pacto
|
12
|
+
pkill -f 'pacto server'
|
@@ -3,9 +3,16 @@ require 'pacto'
|
|
3
3
|
require 'hashie/mash'
|
4
4
|
|
5
5
|
# Fabricators for contracts or parts of contracts
|
6
|
+
unless defined? PACTO_DEFAULT_FORMAT
|
7
|
+
PACTO_DEFAULT_FORMAT = (ENV['PACTO_DEFAULT_FORMAT'] || 'legacy')
|
8
|
+
CONTRACT_CLASS = Pacto::Formats.const_get(PACTO_DEFAULT_FORMAT.capitalize).const_get('Contract')
|
9
|
+
REQUEST_CLAUSE_CLASS = Pacto::Formats.const_get(PACTO_DEFAULT_FORMAT.capitalize).const_get('RequestClause')
|
10
|
+
RESPONSE_CLAUSE_CLASS = Pacto::Formats.const_get(PACTO_DEFAULT_FORMAT.capitalize).const_get('ResponseClause')
|
11
|
+
end
|
12
|
+
|
13
|
+
Fabricator(:contract, from: CONTRACT_CLASS) do
|
14
|
+
initialize_with { @_klass.new(to_hash.merge(skip_freeze: true)) } # Hash based initialization
|
6
15
|
|
7
|
-
Fabricator(:contract, from: Pacto::Contract) do
|
8
|
-
initialize_with { @_klass.new to_hash } # Hash based initialization
|
9
16
|
transient example_count: 0
|
10
17
|
name { 'Dummy Contract' }
|
11
18
|
file { 'file:///does/not/exist/dummy_contract.json' }
|
@@ -23,17 +30,19 @@ Fabricator(:contract, from: Pacto::Contract) do
|
|
23
30
|
nil
|
24
31
|
end
|
25
32
|
end
|
33
|
+
|
34
|
+
# after_save { | contract, _transients | contract.freeze }
|
26
35
|
end
|
27
36
|
|
28
|
-
Fabricator(:partial_contract, from:
|
29
|
-
initialize_with { @_klass.new
|
37
|
+
Fabricator(:partial_contract, from: CONTRACT_CLASS) do
|
38
|
+
initialize_with { @_klass.new(to_hash.merge(skip_freeze: true)) } # Hash based initialization
|
30
39
|
name { 'Dummy Contract' }
|
31
40
|
file { 'file:///does/not/exist/dummy_contract.json' }
|
32
41
|
request { Fabricate(:request_clause).to_hash }
|
33
42
|
end
|
34
43
|
|
35
|
-
Fabricator(:request_clause, from:
|
36
|
-
initialize_with { @_klass.new
|
44
|
+
Fabricator(:request_clause, from: REQUEST_CLAUSE_CLASS) do
|
45
|
+
initialize_with { @_klass.new(to_hash.merge(skip_freeze: true)) } # Hash based initialization
|
37
46
|
host { 'example.com' }
|
38
47
|
http_method { 'GET' }
|
39
48
|
path { '/abcd' }
|
@@ -49,8 +58,8 @@ Fabricator(:request_clause, from: Pacto::RequestClause) do
|
|
49
58
|
params {}
|
50
59
|
end
|
51
60
|
|
52
|
-
Fabricator(:response_clause, from:
|
53
|
-
initialize_with { @_klass.new
|
61
|
+
Fabricator(:response_clause, from: RESPONSE_CLAUSE_CLASS) do
|
62
|
+
initialize_with { @_klass.new(to_hash.merge(skip_freeze: true)) } # Hash based initialization
|
54
63
|
status { 200 }
|
55
64
|
headers do
|
56
65
|
{
|
File without changes
|
data/spec/fixtures/contracts/{contract_with_examples.json → legacy/contract_with_examples.json}
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,20 +1,14 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
describe Pacto do
|
3
|
-
let(:contract_path) { '
|
4
|
-
let(:strict_contract_path) { '
|
3
|
+
let(:contract_path) { contract_file 'simple_contract' }
|
4
|
+
let(:strict_contract_path) { contract_file 'strict_contract' }
|
5
5
|
|
6
6
|
before :all do
|
7
7
|
WebMock.allow_net_connect!
|
8
8
|
end
|
9
9
|
|
10
10
|
context 'Contract investigation' do
|
11
|
-
|
12
|
-
run_pacto do
|
13
|
-
example.run
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'verifies the contract against a producer' do
|
11
|
+
xit 'verifies the contract against a producer' do
|
18
12
|
# FIXME: Does this really test what it says it does??
|
19
13
|
contract = described_class.load_contracts(contract_path, 'http://localhost:8000')
|
20
14
|
expect(contract.simulate_consumers.map(&:successful?).uniq).to eq([true])
|
@@ -26,7 +20,7 @@ describe Pacto do
|
|
26
20
|
contracts = described_class.load_contracts(contract_path, 'http://dummyprovider.com')
|
27
21
|
contracts.stub_providers
|
28
22
|
|
29
|
-
response = get_json('http://dummyprovider.com/hello')
|
23
|
+
response = get_json('http://dummyprovider.com/api/hello')
|
30
24
|
expect(response['message']).to eq 'bar'
|
31
25
|
end
|
32
26
|
end
|
@@ -38,10 +32,10 @@ describe Pacto do
|
|
38
32
|
c.register_hook Pacto::Hooks::ERBHook.new
|
39
33
|
end
|
40
34
|
|
41
|
-
contracts = described_class.load_contracts
|
35
|
+
contracts = described_class.load_contracts contracts_folder, 'http://dummyprovider.com'
|
42
36
|
contracts.stub_providers(device_id: 42)
|
43
37
|
|
44
|
-
login_response = get_json('http://dummyprovider.com/hello')
|
38
|
+
login_response = get_json('http://dummyprovider.com/api/hello')
|
45
39
|
expect(login_response.keys).to eq ['message']
|
46
40
|
expect(login_response['message']).to be_kind_of(String)
|
47
41
|
|
@@ -3,14 +3,8 @@ require 'pacto/rspec'
|
|
3
3
|
|
4
4
|
module Pacto
|
5
5
|
describe '#have_investigated' do
|
6
|
-
let(:contract_path) { '
|
7
|
-
let(:strict_contract_path) { '
|
8
|
-
|
9
|
-
around :each do |example|
|
10
|
-
run_pacto do
|
11
|
-
example.run
|
12
|
-
end
|
13
|
-
end
|
6
|
+
let(:contract_path) { contract_file 'simple_contract' }
|
7
|
+
let(:strict_contract_path) { contract_file 'strict_contract' }
|
14
8
|
|
15
9
|
def expect_to_raise(message_pattern = nil, &blk)
|
16
10
|
expect { blk.call }.to raise_error(RSpec::Expectations::ExpectationNotMetError, message_pattern)
|
@@ -32,7 +26,7 @@ module Pacto
|
|
32
26
|
|
33
27
|
context 'successful investigations' do
|
34
28
|
let(:contracts) do
|
35
|
-
Pacto.load_contracts
|
29
|
+
Pacto.load_contracts contracts_folder, 'http://dummyprovider.com'
|
36
30
|
end
|
37
31
|
|
38
32
|
before(:each) do
|
@@ -44,7 +38,7 @@ module Pacto
|
|
44
38
|
contracts.stub_providers(device_id: 42)
|
45
39
|
Pacto.validate!
|
46
40
|
|
47
|
-
Faraday.get('http://dummyprovider.com/hello') do |req|
|
41
|
+
Faraday.get('http://dummyprovider.com/api/hello') do |req|
|
48
42
|
req.headers = { 'Accept' => 'application/json' }
|
49
43
|
end
|
50
44
|
end
|
@@ -57,7 +51,7 @@ module Pacto
|
|
57
51
|
# Increasingly strict assertions
|
58
52
|
expect(Pacto).to have_investigated('Simple Contract')
|
59
53
|
expect(Pacto).to have_investigated('Simple Contract').with_request(headers: hash_including('Accept' => 'application/json'))
|
60
|
-
expect(Pacto).to have_investigated('Simple Contract').with_request(http_method: :get, url: 'http://dummyprovider.com/hello')
|
54
|
+
expect(Pacto).to have_investigated('Simple Contract').with_request(http_method: :get, url: 'http://dummyprovider.com/api/hello')
|
61
55
|
end
|
62
56
|
|
63
57
|
it 'supports negative assertions' do
|