This repository has been archived by the owner on Dec 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:thoughtworks/pacto into remove_sh…
…ould_from_specs Conflicts: spec/spec_helper.rb spec/unit/pacto/core/contract_repository_spec.rb
- Loading branch information
Showing
23 changed files
with
238 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
--colour | ||
--require spec_helper | ||
--require integration/spec_helper | ||
--require unit/spec_helper |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Pacto | ||
class Callback | ||
def initialize(&block) | ||
@callback = block | ||
end | ||
|
||
def process(contracts, request_signature, response) | ||
@callback.call contracts, request_signature, response | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Pacto | ||
module Hooks | ||
class ERBHook < Pacto::Callback | ||
def initialize | ||
@processor = ERBProcessor.new | ||
end | ||
|
||
def process(contracts, request_signature, response) | ||
bound_values = contracts.empty? ? {} : contracts.first.values | ||
bound_values.merge!({:req => { 'HEADERS' => request_signature.headers}}) | ||
response.body = @processor.process response.body, bound_values | ||
response.body | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
describe Pacto::Hooks::ERBHook do | ||
describe '.process' do | ||
let(:req) { | ||
OpenStruct.new({:headers => {'User-Agent' => 'abcd'}}) | ||
} | ||
let(:converted_req) { | ||
{'HEADERS' => {'User-Agent' => 'abcd'}} | ||
} | ||
let(:res) { | ||
OpenStruct.new({:body => 'before'}) | ||
} | ||
|
||
before do | ||
end | ||
|
||
context 'no matching contracts' do | ||
it 'binds the request' do | ||
contracts = Set.new | ||
mock_erb({ :req => converted_req }) | ||
described_class.new.process contracts, req, res | ||
expect(res.body).to eq('after') | ||
end | ||
end | ||
|
||
context 'one matching contract' do | ||
it 'binds the request and the contract\'s values' do | ||
contract = OpenStruct.new({:values => {:max => 'test'}}) | ||
contracts = Set.new([contract]) | ||
mock_erb({ :req => converted_req, :max => 'test'}) | ||
described_class.new.process contracts, req, res | ||
expect(res.body).to eq('after') | ||
end | ||
end | ||
|
||
context 'multiple matching contracts' do | ||
it 'binds the request and the first contract\'s values' do | ||
contract1 = OpenStruct.new({:values => {:max => 'test'}}) | ||
contract2 = OpenStruct.new({:values => {:mob => 'team'}}) | ||
res = OpenStruct.new({:body => 'before'}) | ||
mock_erb({ :req => converted_req, :max => 'test'}) | ||
contracts = Set.new([contract1, contract2]) | ||
described_class.new.process contracts, req, res | ||
expect(res.body).to eq('after') | ||
end | ||
end | ||
end | ||
|
||
def mock_erb(hash) | ||
Pacto::ERBProcessor.any_instance.should_receive(:process).with('before', hash).and_return('after') | ||
end | ||
end |
Oops, something went wrong.