Skip to content

Commit 9e6de46

Browse files
committedJul 23, 2018
feat: allow WIP pacts to be verified without causing the process to return an non zero exit code
1 parent 6519819 commit 9e6de46

22 files changed

+335
-54
lines changed
 

‎lib/pact/cli.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class CLI < Thor
88
desc 'verify', "Verify a pact"
99
method_option :pact_helper, aliases: "-h", desc: "Pact helper file", :required => true
1010
method_option :pact_uri, aliases: "-p", desc: "Pact URI"
11+
method_option :wip, type: :boolean, default: false, desc: "If WIP, process will always exit with exit code 0", hide: true
1112
method_option :pact_broker_username, aliases: "-u", desc: "Pact broker user name"
1213
method_option :pact_broker_password, aliases: "-w", desc: "Pact broker password"
1314
method_option :backtrace, aliases: "-b", desc: "Show full backtrace", :default => false, :type => :boolean
@@ -33,6 +34,5 @@ def docs
3334
require 'pact/doc/generator'
3435
Pact::Doc::Generate.call(options[:pact_dir], options[:doc_dir], [Pact::Doc::Markdown::Generator])
3536
end
36-
3737
end
3838
end

‎lib/pact/cli/run_pact_verification.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ def pact_spec_options
7171
full_backtrace: options[:backtrace],
7272
criteria: SpecCriteria.call(options),
7373
format: options[:format],
74-
out: options[:out]
74+
out: options[:out],
75+
wip: options[:wip]
7576
}
7677
end
7778
end

‎lib/pact/hal/entity.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def response
4848
@response
4949
end
5050

51-
def fetch(key)
52-
@links[key]
51+
def fetch(key, fallback_key = nil)
52+
@links[key] || (fallback_key && @links[fallback_key])
5353
end
5454

5555
def method_missing(method_name, *args, &block)

‎lib/pact/pact_broker/fetch_pacts.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class FetchPacts
1111
LATEST_PROVIDER_TAG_RELATION = 'pb:latest-provider-pacts-with-tag'.freeze
1212
LATEST_PROVIDER_RELATION = 'pb:latest-provider-pacts'.freeze
1313
PACTS = 'pacts'.freeze
14+
PB_PACTS = 'pb:pacts'.freeze
1415
HREF = 'href'.freeze
1516

1617
def initialize(provider, tags, broker_base_url, http_client_options)
@@ -79,7 +80,7 @@ def get_latest_pacts_for_provider
7980
end
8081

8182
def get_pact_urls(link_by_provider)
82-
link_by_provider.fetch(PACTS).collect do |pact|
83+
link_by_provider.fetch(PB_PACTS, PACTS).collect do |pact|
8384
Pact::Provider::PactURI.new(pact[HREF], http_client_options)
8485
end
8586
end
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
require 'pact/hal/entity'
2+
require 'pact/hal/http_client'
3+
require 'pact/provider/pact_uri'
4+
5+
module Pact
6+
module PactBroker
7+
class FetchWipPacts
8+
attr_reader :provider, :tags, :broker_base_url, :http_client_options, :http_client, :index_entity
9+
10+
WIP_PROVIDER_RELATION = 'pb:wip-provider-pacts'.freeze
11+
PACTS = 'pacts'.freeze
12+
PB_PACTS = 'pb:pacts'.freeze
13+
HREF = 'href'.freeze
14+
15+
def initialize(provider, broker_base_url, http_client_options)
16+
@provider = provider
17+
@http_client_options = http_client_options
18+
@broker_base_url = broker_base_url
19+
@http_client = Pact::Hal::HttpClient.new(http_client_options)
20+
end
21+
22+
def self.call(provider, broker_base_url, http_client_options)
23+
new(provider, broker_base_url, http_client_options).call
24+
end
25+
26+
def call
27+
log_message
28+
if get_index.success?
29+
get_wip_pacts_for_provider
30+
else
31+
raise Pact::Error.new("Error retrieving #{broker_base_url} status=#{index_entity.response.code} #{index_entity.response.raw_body}")
32+
end
33+
end
34+
35+
private
36+
37+
def get_index
38+
@index_entity = Pact::Hal::Link.new({ "href" => broker_base_url }, http_client).get
39+
end
40+
41+
def get_wip_pacts_for_provider
42+
link = index_entity._link(WIP_PROVIDER_RELATION)
43+
if link
44+
get_pact_urls(link.expand(provider: provider).get)
45+
else
46+
[]
47+
end
48+
end
49+
50+
def get_pact_urls(link_by_provider)
51+
link_by_provider.fetch(PB_PACTS, PACTS).collect do |pact|
52+
Pact::Provider::PactURI.new(pact[HREF], http_client_options)
53+
end
54+
end
55+
56+
def log_message
57+
message = "INFO: Fetching WIP pacts for #{provider} from #{broker_base_url}"
58+
Pact.configuration.output_stream.puts message
59+
end
60+
end
61+
end
62+
end

‎lib/pact/provider/pact_spec_runner.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def run
3636
ensure
3737
::RSpec.reset
3838
Pact.clear_provider_world
39+
Pact.clear_consumer_world
3940
end
4041
end
4142

@@ -90,7 +91,7 @@ def run_specs
9091
::RSpec::Core::CommandLine.new(NoConfigurationOptions.new)
9192
.run(::RSpec.configuration.output_stream, ::RSpec.configuration.error_stream)
9293
end
93-
exit_code
94+
options[:wip] ? 0 : exit_code
9495
end
9596

9697
def rspec_runner_options
@@ -118,7 +119,8 @@ def pact_jsons
118119
def initialize_specs
119120
pact_sources.each do | pact_source |
120121
options = {
121-
criteria: @options[:criteria]
122+
criteria: @options[:criteria],
123+
wip: @options[:wip]
122124
}
123125
honour_pactfile pact_source.uri, ordered_pact_json(pact_source.pact_json), options
124126
end
@@ -144,6 +146,8 @@ def configure_output
144146
end
145147

146148
::RSpec.configuration.full_backtrace = @options[:full_backtrace]
149+
150+
::RSpec.configuration.failure_color = :yellow if @options[:wip]
147151
end
148152

149153
def ordered_pact_json(pact_json)

‎lib/pact/provider/rspec.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ module ClassMethods
2121
include ::RSpec::Core::DSL
2222

2323
def honour_pactfile pact_uri, pact_json, options
24-
Pact.configuration.output_stream.puts "INFO: Reading pact at #{pact_uri}"
24+
pact_description = options[:wip] ? "WIP pact" : "pact"
25+
Pact.configuration.output_stream.puts "INFO: Reading #{pact_description} at #{pact_uri}"
2526
Pact.configuration.output_stream.puts "INFO: Filtering interactions by: #{options[:criteria]}" if options[:criteria] && options[:criteria].any?
2627
consumer_contract = Pact::ConsumerContract.from_json(pact_json)
27-
::RSpec.describe "Verifying a pact between #{consumer_contract.consumer.name} and #{consumer_contract.provider.name}", pactfile_uri: pact_uri do
28+
::RSpec.describe "Verifying a #{pact_description} between #{consumer_contract.consumer.name} and #{consumer_contract.provider.name}", pactfile_uri: pact_uri do
2829
honour_consumer_contract consumer_contract, options.merge(pact_json: pact_json, pact_uri: pact_uri)
2930
end
3031
end
@@ -72,7 +73,8 @@ def describe_interaction interaction, options
7273
pact: :verify,
7374
pact_interaction: interaction,
7475
pact_interaction_example_description: interaction_description_for_rerun_command(interaction),
75-
pact_uri: options[:pact_uri]
76+
pact_uri: options[:pact_uri],
77+
pact_wip: options[:wip]
7678
}
7779

7880
describe description_for(interaction), metadata do

‎lib/pact/provider/rspec/formatter_rspec_3.rb

+18-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,21 @@ def failed_interactions_count(summary)
4242
summary.failed_examples.collect{ |e| e.metadata[:pact_interaction_example_description] }.uniq.size
4343
end
4444

45+
def wip?(summary)
46+
summary.failed_examples.any?{ |e| e.metadata[:pact_wip] }
47+
end
48+
49+
def failure_title summary
50+
if wip?(summary)
51+
"#{failed_interactions_count(summary)} pending"
52+
else
53+
::RSpec::Core::Formatters::Helpers.pluralize(failed_interactions_count(summary), "failure")
54+
end
55+
end
56+
4557
def totals_line summary
4658
line = ::RSpec::Core::Formatters::Helpers.pluralize(interactions_count(summary), "interaction")
47-
line << ", " << ::RSpec::Core::Formatters::Helpers.pluralize(failed_interactions_count(summary), "failure")
59+
line << ", " << failure_title(summary)
4860
line
4961
end
5062

@@ -57,7 +69,11 @@ def color_for_summary summary
5769
end
5870

5971
def print_rerun_commands summary
60-
output.puts("\nFailed interactions:\n\n")
72+
if wip?(summary)
73+
output.puts("\nPending interactions: (Failures listed here are expected and do not affect your suite's status)\n\n")
74+
else
75+
output.puts("\nFailed interactions:\n\n")
76+
end
6177
interaction_rerun_commands(summary).each do | message |
6278
output.puts(message)
6379
end

‎lib/pact/tasks/task_helper.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ module TaskHelper
1010

1111
extend self
1212

13-
def execute_pact_verify pact_uri = nil, pact_helper = nil, rspec_opts = nil
14-
execute_cmd verify_command(pact_helper || Pact::Provider::PactHelperLocater.pact_helper_path, pact_uri, rspec_opts)
13+
def execute_pact_verify pact_uri = nil, pact_helper = nil, rspec_opts = nil, verification_opts = {}
14+
execute_cmd verify_command(pact_helper || Pact::Provider::PactHelperLocater.pact_helper_path, pact_uri, rspec_opts, verification_opts)
1515
end
1616

1717
def handle_verification_failure
1818
exit_status = yield
1919
abort if exit_status != 0
2020
end
2121

22-
def verify_command pact_helper, pact_uri, rspec_opts
22+
def verify_command pact_helper, pact_uri, rspec_opts, verification_opts
2323
command_parts = []
2424
# Clear SPEC_OPTS, otherwise we can get extra formatters, creating duplicate output eg. CI Reporting.
2525
# Allow deliberate configuration using rspec_opts in VerificationTask.
@@ -28,6 +28,7 @@ def verify_command pact_helper, pact_uri, rspec_opts
2828
command_parts << "-S pact verify"
2929
command_parts << "--pact-helper" << Shellwords.escape(pact_helper.end_with?(".rb") ? pact_helper : pact_helper + ".rb")
3030
(command_parts << "--pact-uri" << pact_uri) if pact_uri
31+
command_parts << "--wip" if verification_opts[:wip]
3132
command_parts << "--pact-broker-username" << ENV['PACT_BROKER_USERNAME'] if ENV['PACT_BROKER_USERNAME']
3233
command_parts << "--pact-broker-password" << ENV['PACT_BROKER_PASSWORD'] if ENV['PACT_BROKER_PASSWORD']
3334
command_parts << "--backtrace" if ENV['BACKTRACE'] == 'true'

‎lib/pact/tasks/verification_task.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ class VerificationTask < ::Rake::TaskLib
3030

3131
attr_reader :pact_spec_configs
3232
attr_accessor :rspec_opts
33+
attr_accessor :wip
3334

3435
def initialize(name)
3536
@rspec_opts = nil
37+
@wip = false
3638
@pact_spec_configs = []
3739
@name = name
3840
yield self
@@ -74,7 +76,7 @@ def rake_task
7476
require 'pact/tasks/task_helper'
7577

7678
exit_statuses = pact_spec_configs.collect do | config |
77-
Pact::TaskHelper.execute_pact_verify config[:uri], config[:pact_helper], rspec_opts
79+
Pact::TaskHelper.execute_pact_verify config[:uri], config[:pact_helper], rspec_opts, { wip: wip }
7880
end
7981

8082
Pact::TaskHelper.handle_verification_failure do

‎spec/lib/pact/hal/entity_spec.rb

+17-4
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,31 @@ module Hal
7575
end
7676

7777
describe 'fetch' do
78-
context 'when the key exist' do
78+
context 'when the key exists' do
7979
it 'returns fetched value' do
80-
expect(subject.fetch('pb:provider')).to be do
81-
{href: 'http://provider'}
82-
end
80+
expect(subject.fetch('pb:provider')).to eq("href" => 'http://provider')
8381
end
8482
end
83+
8584
context "when the key doesn't not exist" do
8685
it 'returns nil' do
8786
expect(subject.fetch('i-dont-exist')).to be nil
8887
end
8988
end
89+
90+
context "when a fallback key is provided" do
91+
context "when the fallback value exists" do
92+
it "returns the fallback value" do
93+
expect(subject.fetch('i-dont-exist', 'pb:provider')).to eq("href" => 'http://provider')
94+
end
95+
end
96+
97+
context "when the fallback value does not exist" do
98+
it "returns nil" do
99+
expect(subject.fetch('i-dont-exist', 'i-also-dont-exist')).to be nil
100+
end
101+
end
102+
end
90103
end
91104
end
92105
end

‎spec/lib/pact/pact_broker/fetch_pacts_spec.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ module PactBroker
55
describe FetchPacts do
66

77
describe "call" do
8+
before do
9+
allow(Pact.configuration).to receive(:output_stream).and_return(double('output stream').as_null_object)
10+
stub_request(:get, "http://broker.org/").to_return(status: 500, body: "foo", headers: {})
11+
end
12+
813
let(:provider) { "Foo"}
914
let(:tags) { ["master", "prod"] }
1015
let(:broker_base_url) { "http://broker.org" }
1116
let(:http_client_options) { {} }
1217

13-
before do
14-
stub_request(:get, "http://broker.org/").to_return(status: 500, body: "foo", headers: {})
15-
end
16-
1718
subject { FetchPacts.call(provider, tags, broker_base_url, http_client_options)}
1819

1920
let(:subject_with_rescue) do
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
require 'pact/pact_broker/fetch_wip_pacts'
2+
3+
module Pact
4+
module PactBroker
5+
describe FetchWipPacts do
6+
describe "call" do
7+
before do
8+
allow(Pact.configuration).to receive(:output_stream).and_return(double('output stream').as_null_object)
9+
end
10+
11+
let(:provider) { "Foo"}
12+
let(:broker_base_url) { "http://broker.org" }
13+
let(:http_client_options) { {} }
14+
subject { FetchWipPacts.call(provider, broker_base_url, http_client_options)}
15+
16+
context "when there is an error retrieving the index resource" do
17+
before do
18+
stub_request(:get, "http://broker.org/").to_return(status: 500, body: "foo", headers: {})
19+
end
20+
21+
let(:subject_with_rescue) do
22+
begin
23+
subject
24+
rescue Pact::Error
25+
# can't be bothered stubbing out everything to make the rest of the code execute nicely
26+
# when all we care about is the message
27+
end
28+
end
29+
30+
it "raises a Pact::Error" do
31+
expect { subject }.to raise_error Pact::Error, /500.*foo/
32+
end
33+
end
34+
35+
context "when the pb:wip-provider-pacts relation does not exist" do
36+
before do
37+
stub_request(:get, "http://broker.org/").to_return(status: 200, body: response_body, headers: response_headers)
38+
end
39+
40+
let(:response_headers) { { "Content-Type" => "application/hal+json" } }
41+
let(:response_body) do
42+
{
43+
_links: {}
44+
}.to_json
45+
end
46+
47+
it "returns an empty list" do
48+
expect(subject).to eq []
49+
end
50+
end
51+
end
52+
end
53+
end
54+
end

‎spec/lib/pact/provider/rspec/formatter_rspec_3_spec.rb

+16-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ module RSpec
1919
pact_interaction: interaction,
2020
pactfile_uri: pactfile_uri,
2121
pact_interaction_example_description: description,
22-
pact_json: pact_json
22+
pact_json: pact_json,
23+
pact_wip: wip
2324
}
2425
end
2526
let(:metadata_2) { metadata.merge(pact_interaction_example_description: 'another interaction')}
@@ -33,6 +34,7 @@ module RSpec
3334
let(:summary) { double("summary", failure_count: 1, failed_examples: failed_examples, examples: examples)}
3435
let(:pact_executing_language) { 'ruby' }
3536
let(:pact_interaction_rerun_command) { Pact::TaskHelper::PACT_INTERACTION_RERUN_COMMAND }
37+
let(:wip) { nil }
3638

3739
subject { Formatter.new output }
3840

@@ -102,6 +104,19 @@ module RSpec
102104
subject.dump_summary summary
103105
end
104106
end
107+
108+
context "when wip is true" do
109+
let(:wip) { true }
110+
111+
it "reports failures as pending" do
112+
expect(output_result).to include("1 pending")
113+
expect(output_result).to_not include("1 failure")
114+
end
115+
116+
it "explains that failures will not affect the test results" do
117+
expect(output_result).to include "Pending interactions: (Failures listed here are expected and do not affect your suite's status)"
118+
end
119+
end
105120
end
106121
end
107122
end

‎spec/lib/pact/tasks/task_helper_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ module Pact
88
let(:ruby_path) { "/path/to/ruby" }
99
let(:pact_uri) { "/pact/uri" }
1010
let(:default_pact_helper_path) { "/pact/helper/path.rb" }
11+
let(:verification_options) { { wip: wip } }
12+
let(:wip) { nil }
1113

1214
before do
1315
stub_const("FileUtils::RUBY", ruby_path)
@@ -117,6 +119,14 @@ module Pact
117119
end
118120
end
119121

122+
context "with wip: true" do
123+
let(:wip) { true }
124+
it "executes the command with --wip" do
125+
expect(TaskHelper).to receive(:execute_cmd).with(/ --wip\b/)
126+
TaskHelper.execute_pact_verify(pact_uri, nil, nil, verification_options)
127+
end
128+
end
129+
120130
context "with PACT_BROKER_USERNAME set" do
121131
before do
122132
ENV['PACT_BROKER_USERNAME'] = 'pact_username'

‎spec/lib/pact/tasks/verification_task_spec.rb

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'spec_helper'
22
require 'pact/tasks/verification_task'
3+
require 'pact/tasks/task_helper'
34

45
module Pact
56
describe VerificationTask do
@@ -8,6 +9,7 @@ module Pact
89
@pact_uri = 'http://example.org/pact.json'
910
@task_name = 'pact:verify:pact_rake_spec'
1011
@task_name_with_explict_pact_helper = 'pact:verify:pact_rake_spec_with_explict_pact_helper'
12+
@task_name_wip = 'pact:verify:pact_rake_spec_wip'
1113
@consumer = 'some-consumer'
1214
@criteria = {:description => /wiffle/}
1315

@@ -18,15 +20,17 @@ module Pact
1820
VerificationTask.new(:pact_rake_spec) do | pact |
1921
pact.uri @pact_uri
2022
end
23+
24+
VerificationTask.new(:pact_rake_spec_wip) do | pact |
25+
pact.uri @pact_uri
26+
pact.wip = true
27+
end
2128
end
2229

2330
before do
2431
allow(Pact::TaskHelper).to receive(:execute_pact_verify).and_return(0)
2532
end
2633

27-
let(:exit_code) {0}
28-
29-
3034
describe '.initialize' do
3135
context 'with an explict pact_helper' do
3236
it 'creates the tasks' do
@@ -41,29 +45,33 @@ module Pact
4145
end
4246

4347
describe 'execute' do
44-
4548
context "with no explicit pact_helper" do
4649
it 'verifies the pacts using the TaskHelper' do
47-
expect(Pact::TaskHelper).to receive(:execute_pact_verify).with(@pact_uri, nil, nil)
50+
expect(Pact::TaskHelper).to receive(:execute_pact_verify).with(@pact_uri, nil, nil, { wip: false })
4851
Rake::Task[@task_name].execute
4952
end
5053
end
5154

5255
context "with an explict pact_helper" do
5356
let(:verification_config) { [ uri: @pact_uri, pact_helper: @pact_helper] }
54-
it 'verifies the pacts using the TaskHelper' do
55-
expect(Pact::TaskHelper).to receive(:execute_pact_verify).with(@pact_uri, @pact_helper, nil)
57+
it 'verifies the pacts using specified pact_helper' do
58+
expect(Pact::TaskHelper).to receive(:execute_pact_verify).with(@pact_uri, @pact_helper, nil, { wip: false })
5659
Rake::Task[@task_name_with_explict_pact_helper].execute
5760
end
5861
end
5962

60-
context 'when all specs pass' do
63+
context "with wip: true" do
64+
it 'verifies the pacts with wip: true' do
65+
expect(Pact::TaskHelper).to receive(:execute_pact_verify).with(@pact_uri, anything, anything, { wip: true })
66+
Rake::Task[@task_name_wip].execute
67+
end
68+
end
6169

70+
context 'when all specs pass' do
6271
it 'does not raise an exception' do
6372
Rake::Task[@task_name].execute
6473
end
6574
end
66-
6775
end
6876
end
6977
end

‎spec/service_providers/helper.rb

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require 'pact/consumer/rspec'
2+
3+
Pact.service_consumer 'Pact Ruby' do
4+
has_pact_with 'Pact Broker' do
5+
mock_service :pact_broker do
6+
port 1234
7+
pact_specification_version '2.0.0'
8+
end
9+
end
10+
end

‎spec/service_providers/pact_ruby_fetch_pacts_test.rb

+15-19
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
require 'pact/consumer/rspec'
1+
require_relative 'helper'
22
require 'pact/pact_broker/fetch_pacts'
3-
require 'pact/provider/pact_uri'
43

5-
Pact.service_consumer 'Pact Ruby' do
6-
has_pact_with 'Pact Broker' do
7-
mock_service :pact_broker do
8-
port 1234
9-
pact_specification_version '2.0.0'
10-
end
11-
end
12-
end
134

145
describe Pact::PactBroker::FetchPacts, pact: true do
6+
7+
before do
8+
allow($stdout).to receive(:puts)
9+
end
10+
1511
let(:get_headers) { { Accept: 'application/hal+json' } }
1612

1713
describe 'fetch pacts' do
@@ -71,7 +67,7 @@
7167
status: 200,
7268
body: {
7369
_links: {
74-
pacts: [
70+
'pb:pacts' => [
7571
{
7672
href: Pact.term('http://pact-broker-url-for-consumer-1', %r{http://.*})
7773
},
@@ -111,7 +107,7 @@
111107
status: 200,
112108
body: {
113109
_links: {
114-
pacts: [
110+
'pb:pacts' => [
115111
{
116112
href: Pact.term('http://pact-broker-url-for-consumer-1-tag-1', %r{http://.*})
117113
},
@@ -134,7 +130,7 @@
134130
status: 200,
135131
body: {
136132
_links: {
137-
pacts: [
133+
'pb:pacts' => [
138134
{
139135
href: Pact.term('http://pact-broker-url-for-consumer-1-tag-2', %r{http://.*})
140136
},
@@ -177,7 +173,7 @@
177173
status: 200,
178174
body: {
179175
_links: {
180-
pacts: []
176+
'pb:pacts' => []
181177
}
182178
}
183179
)
@@ -193,7 +189,7 @@
193189
status: 200,
194190
body: {
195191
_links: {
196-
pacts: [
192+
'pb:pacts' => [
197193
{
198194
href: Pact.term('http://pact-broker-url-for-consumer-1-master', %r{http://.*})
199195
},
@@ -233,7 +229,7 @@
233229
status: 200,
234230
body: {
235231
_links: {
236-
pacts: []
232+
'pb:pacts' => []
237233
}
238234
}
239235
)
@@ -262,7 +258,7 @@
262258
status: 200,
263259
body: {
264260
_links: {
265-
pacts: [
261+
'pb:pacts' => [
266262
{
267263
href: Pact.term('http://pact-broker-url-for-consumer-1-tag-1', %r{http://.*})
268264
},
@@ -286,7 +282,7 @@
286282
status: 200,
287283
body: {
288284
_links: {
289-
pacts: [
285+
'pb:pacts' => [
290286
{
291287
href: Pact.term('http://pact-broker-url-for-consumer-1-tag-2-all', %r{http://.*})
292288
},
@@ -329,7 +325,7 @@
329325
status: 200,
330326
body: {
331327
_links: {
332-
pacts: [
328+
'pb:pacts' => [
333329
{
334330
href: Pact.term('http://pact-broker-url-for-consumer-1-all', %r{http://.*})
335331
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
require_relative 'helper'
2+
require 'pact/pact_broker/fetch_wip_pacts'
3+
4+
describe Pact::PactBroker::FetchWipPacts, pact: true do
5+
before do
6+
allow($stdout).to receive(:puts)
7+
end
8+
9+
let(:get_headers) { { Accept: 'application/hal+json' } }
10+
11+
describe 'fetch pacts' do
12+
let(:provider) { 'provider-1' }
13+
let(:broker_base_url) { pact_broker.mock_service_base_url + '/' }
14+
let(:basic_auth_options) { { username: 'foo', password: 'bar' } }
15+
16+
before do
17+
pact_broker
18+
.given('the relations for retrieving WIP pacts exist in the index resource')
19+
.upon_receiving('a request for the index resource')
20+
.with(
21+
method: :get,
22+
path: '/',
23+
headers: get_headers
24+
)
25+
.will_respond_with(
26+
status: 200,
27+
body: {
28+
_links: {
29+
'pb:wip-provider-pacts' => {
30+
href: Pact.term(
31+
generate: broker_base_url + 'pacts/provider/{provider}/wip',
32+
matcher: %r{/pacts/provider/{provider}/wip$}
33+
)
34+
}
35+
}
36+
}
37+
)
38+
end
39+
40+
context 'retrieving WIP pacts by provider' do
41+
before do
42+
pact_broker
43+
.given('consumer-1 has a WIP pact with provider provider-1')
44+
.upon_receiving('a request to retrieve the WIP pacts for provider')
45+
.with(
46+
method: :get,
47+
path: '/pacts/provider/provider-1/wip',
48+
headers: get_headers
49+
)
50+
.will_respond_with(
51+
status: 200,
52+
body: {
53+
_links: {
54+
'pb:pacts' => [
55+
{
56+
href: Pact.term('http://pact-broker-url-for-consumer-1', %r{http://.*})
57+
}
58+
]
59+
}
60+
}
61+
)
62+
end
63+
64+
it 'returns the array of pact urls' do
65+
pacts = Pact::PactBroker::FetchWipPacts.call(provider, broker_base_url, basic_auth_options)
66+
expect(pacts).to eq(
67+
[
68+
Pact::Provider::PactURI.new('http://pact-broker-url-for-consumer-1', basic_auth_options)
69+
]
70+
)
71+
end
72+
end
73+
end
74+
end

‎spec/support/bar_pact_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def call env
2525
end
2626

2727
honours_pact_with 'Foo' do
28-
pact_uri './spec/support/foo-bar.json'
28+
pact_uri './spec/pacts/foo-bar.json'
2929
end
3030
end
3131
end

‎tasks/foo-bar.rake

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Pact::VerificationTask.new('foobar') do | pact |
2929
pact.uri nil, pact_helper: './spec/support/bar_pact_helper.rb'
3030
end
3131

32+
Pact::VerificationTask.new('foobar:wip') do | pact |
33+
pact.uri './spec/pacts/foo-bar-wip.json', pact_helper: './spec/support/bar_pact_helper.rb'
34+
pact.wip = true
35+
end
3236

3337
Pact::VerificationTask.new(:foobar_using_broker) do | pact |
3438
pact.uri "#{BROKER_BASE_URL}/pacts/provider/Bar/consumer/Foo/version/1.0.0", :pact_helper => './spec/support/bar_pact_helper.rb', username: BROKER_USERNAME, password: BROKER_PASSWORD

‎tasks/pact-test.rake

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ Pact::VerificationTask.new('test_app:fail') do | pact |
5353
pact.uri './spec/support/test_app_fail.json', pact_helper: './spec/support/pact_helper.rb'
5454
end
5555

56+
Pact::VerificationTask.new('test_app:wip') do | pact |
57+
pact.uri './spec/support/test_app_fail.json', pact_helper: './spec/support/pact_helper.rb'
58+
pact.wip = true
59+
end
60+
61+
5662
task :bethtest => ['pact:tests:all','pact:tests:all:with_active_support']
5763

5864
namespace :pact do
@@ -68,6 +74,7 @@ namespace :pact do
6874
Rake::Task['pact:verify:test_app:content_type'].execute
6975
Rake::Task['pact:verify:case_insensitive_response_header_matching'].execute
7076
Rake::Task['pact:verify:term_v2'].execute
77+
Rake::Task['pact:verify:test_app:wip'].execute
7178
end
7279

7380
desc "All the verification tests with active support loaded"

0 commit comments

Comments
 (0)
Please sign in to comment.