pact 1.28.0 → 1.29.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5574afeb058510333631c49794bddac105131115
4
- data.tar.gz: 89806235aea0cdbee6639a035e2f5a8a31d1111b
3
+ metadata.gz: b4544628feb78e41d434d8df2fa467c3795b0849
4
+ data.tar.gz: 22c2d7a7caa71c7da7dd33e232a44ba5374f3fd9
5
5
  SHA512:
6
- metadata.gz: '0390c191e18ee7442e1a72ec3aca47094d1e540f84d7c47c5b4284e0263f177464fb3230892e0266d6aa7c880e28beeabbebb17d394878e644ba339028019728'
7
- data.tar.gz: fd382cd61c88b3ad551c0de1c6490567d4f09d5b1f5bf1b1ea58b9ff3b4f77339f74c7b432b53b94355d42aea0f9f1816bd1a3c6f4b7203c461d4352a2333064
6
+ metadata.gz: e1e6ddfcaad18582eb50938d8599e02d19a68efc4053f26e677ccd44125d3c855d4447a13e11a900652612ba1eec1d13759d18fbf32824f8d4c686d06601f9fc
7
+ data.tar.gz: 572c7b4c21f1143d3352620f4596f923917dc974c590b78a2cc9cd2fed071d9d5a5cf2ffe41e369e9cfda4ae6201713760ff3e263a6a74a34ccec747b5b3bcd4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ <a name="v1.29.0"></a>
2
+ ### v1.29.0 (2018-07-24)
3
+
4
+
5
+ #### Features
6
+
7
+ * return plain string URLs from Pact::PactBroker.fetch_pact_uris ([1aa1989](/../../commit/1aa1989))
8
+ * use beta:wip-provider-pacts rather than pb:wip-provider-pacts to fetch WIP pacts ([3bb0501](/../../commit/3bb0501))
9
+ * allow WIP pacts to be verified without causing the process to return an non zero exit code ([9e6de46](/../../commit/9e6de46))
10
+
11
+
12
+ #### Bug Fixes
13
+
14
+ * add missing require ([0aa2d2a](/../../commit/0aa2d2a))
15
+ * default pact specification version to 2 ([917891a](/../../commit/917891a))
16
+
17
+
1
18
  <a name="v1.28.0"></a>
2
19
  ### v1.28.0 (2018-06-24)
3
20
 
data/lib/pact/cli.rb CHANGED
@@ -8,6 +8,7 @@ module Pact
8
8
  desc 'verify', "Verify a pact"
9
9
  method_option :pact_helper, aliases: "-h", desc: "Pact helper file", :required => true
10
10
  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
11
12
  method_option :pact_broker_username, aliases: "-u", desc: "Pact broker user name"
12
13
  method_option :pact_broker_password, aliases: "-w", desc: "Pact broker password"
13
14
  method_option :backtrace, aliases: "-b", desc: "Show full backtrace", :default => false, :type => :boolean
@@ -33,6 +34,5 @@ module Pact
33
34
  require 'pact/doc/generator'
34
35
  Pact::Doc::Generate.call(options[:pact_dir], options[:doc_dir], [Pact::Doc::Markdown::Generator])
35
36
  end
36
-
37
37
  end
38
38
  end
@@ -71,7 +71,8 @@ module Pact
71
71
  full_backtrace: options[:backtrace],
72
72
  criteria: SpecCriteria.call(options),
73
73
  format: options[:format],
74
- out: options[:out]
74
+ out: options[:out],
75
+ wip: options[:wip]
75
76
  }
76
77
  end
77
78
  end
@@ -20,7 +20,7 @@ module Pact
20
20
  @port = nil
21
21
  @standalone = false
22
22
  @verify = true
23
- @pact_specification_version = nil
23
+ @pact_specification_version = '2'
24
24
  @finalized = false
25
25
  end
26
26
 
@@ -48,8 +48,8 @@ module Pact
48
48
  @response
49
49
  end
50
50
 
51
- def fetch(key)
52
- @links[key]
51
+ def fetch(key, fallback_key = nil)
52
+ @links[key] || (fallback_key && @links[fallback_key])
53
53
  end
54
54
 
55
55
  def method_missing(method_name, *args, &block)
@@ -0,0 +1,19 @@
1
+ require 'pact/pact_broker/fetch_pacts'
2
+ require 'pact/pact_broker/fetch_wip_pacts'
3
+
4
+ #
5
+ # @public Use by Pact Provider Verifier
6
+ #
7
+ module Pact
8
+ module PactBroker
9
+ extend self
10
+
11
+ def fetch_pact_uris *args
12
+ Pact::PactBroker::FetchPacts.call(*args).collect(&:uri)
13
+ end
14
+
15
+ def fetch_wip_pact_uris *args
16
+ Pact::PactBroker::FetchWipPacts.call(*args).collect(&:uri)
17
+ end
18
+ end
19
+ end
@@ -11,6 +11,7 @@ module Pact
11
11
  LATEST_PROVIDER_TAG_RELATION = 'pb:latest-provider-pacts-with-tag'.freeze
12
12
  LATEST_PROVIDER_RELATION = 'pb:latest-provider-pacts'.freeze
13
13
  PACTS = 'pacts'.freeze
14
+ PB_PACTS = 'pb:pacts'.freeze
14
15
  HREF = 'href'.freeze
15
16
 
16
17
  def initialize(provider, tags, broker_base_url, http_client_options)
@@ -33,11 +34,11 @@ module Pact
33
34
 
34
35
  def call
35
36
  log_message
36
- if get_index.success?
37
+ if index.success?
37
38
  if any_tags?
38
- get_tagged_pacts_for_provider
39
+ tagged_pacts_for_provider
39
40
  else
40
- get_latest_pacts_for_provider
41
+ latest_pacts_for_provider
41
42
  end
42
43
  else
43
44
  raise Pact::Error.new("Error retrieving #{broker_base_url} status=#{index_entity.response.code} #{index_entity.response.raw_body}")
@@ -50,18 +51,18 @@ module Pact
50
51
  tags && tags.any?
51
52
  end
52
53
 
53
- def get_tagged_pacts_for_provider
54
+ def tagged_pacts_for_provider
54
55
  tags.collect do |tag|
55
- link = get_link(tag)
56
- urls = get_pact_urls(link.expand(provider: provider, tag: tag[:name]).get)
57
- if urls == [] && tag[:fallback]
58
- urls = get_pact_urls(link.expand(provider: provider, tag: tag[:fallback]).get)
56
+ link = link_for(tag)
57
+ urls = pact_urls(link.expand(provider: provider, tag: tag[:name]).get)
58
+ if urls.empty? && tag[:fallback]
59
+ urls = pact_urls(link.expand(provider: provider, tag: tag[:fallback]).get)
59
60
  end
60
61
  urls
61
62
  end.flatten
62
63
  end
63
64
 
64
- def get_link(tag)
65
+ def link_for(tag)
65
66
  if !tag[:all]
66
67
  index_entity._link(LATEST_PROVIDER_TAG_RELATION)
67
68
  else
@@ -69,17 +70,17 @@ module Pact
69
70
  end
70
71
  end
71
72
 
72
- def get_index
73
- @index_entity = Pact::Hal::Link.new({ "href" => broker_base_url }, http_client).get
73
+ def index
74
+ @index_entity ||= Pact::Hal::Link.new({ "href" => broker_base_url }, http_client).get
74
75
  end
75
76
 
76
- def get_latest_pacts_for_provider
77
+ def latest_pacts_for_provider
77
78
  link = index_entity._link(LATEST_PROVIDER_RELATION)
78
- get_pact_urls(link.expand(provider: provider).get)
79
+ pact_urls(link.expand(provider: provider).get)
79
80
  end
80
81
 
81
- def get_pact_urls(link_by_provider)
82
- link_by_provider.fetch(PACTS).collect do |pact|
82
+ def pact_urls(link_by_provider)
83
+ link_by_provider.fetch(PB_PACTS, PACTS).collect do |pact|
83
84
  Pact::Provider::PactURI.new(pact[HREF], http_client_options)
84
85
  end
85
86
  end
@@ -0,0 +1,56 @@
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 = 'beta: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
+ if index.success?
28
+ wip_pacts_for_provider
29
+ else
30
+ raise Pact::Error.new("Error retrieving #{broker_base_url} status=#{index_entity.response.code} #{index_entity.response.raw_body}")
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def index
37
+ @index_entity ||= Pact::Hal::Link.new({ "href" => broker_base_url }, http_client).get
38
+ end
39
+
40
+ def wip_pacts_for_provider
41
+ link = index_entity._link(WIP_PROVIDER_RELATION)
42
+ if link
43
+ get_pact_urls(link.expand(provider: provider).get)
44
+ else
45
+ []
46
+ end
47
+ end
48
+
49
+ def get_pact_urls(link_by_provider)
50
+ link_by_provider.fetch(PB_PACTS, PACTS).collect do |pact|
51
+ Pact::Provider::PactURI.new(pact[HREF], http_client_options)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -36,6 +36,7 @@ module Pact
36
36
  ensure
37
37
  ::RSpec.reset
38
38
  Pact.clear_provider_world
39
+ Pact.clear_consumer_world
39
40
  end
40
41
  end
41
42
 
@@ -90,7 +91,7 @@ module Pact
90
91
  ::RSpec::Core::CommandLine.new(NoConfigurationOptions.new)
91
92
  .run(::RSpec.configuration.output_stream, ::RSpec.configuration.error_stream)
92
93
  end
93
- exit_code
94
+ options[:wip] ? 0 : exit_code
94
95
  end
95
96
 
96
97
  def rspec_runner_options
@@ -118,7 +119,8 @@ module Pact
118
119
  def initialize_specs
119
120
  pact_sources.each do | pact_source |
120
121
  options = {
121
- criteria: @options[:criteria]
122
+ criteria: @options[:criteria],
123
+ wip: @options[:wip]
122
124
  }
123
125
  honour_pactfile pact_source.uri, ordered_pact_json(pact_source.pact_json), options
124
126
  end
@@ -144,6 +146,8 @@ module Pact
144
146
  end
145
147
 
146
148
  ::RSpec.configuration.full_backtrace = @options[:full_backtrace]
149
+
150
+ ::RSpec.configuration.failure_color = :yellow if @options[:wip]
147
151
  end
148
152
 
149
153
  def ordered_pact_json(pact_json)
@@ -21,10 +21,11 @@ module Pact
21
21
  include ::RSpec::Core::DSL
22
22
 
23
23
  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}"
25
26
  Pact.configuration.output_stream.puts "INFO: Filtering interactions by: #{options[:criteria]}" if options[:criteria] && options[:criteria].any?
26
27
  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
28
29
  honour_consumer_contract consumer_contract, options.merge(pact_json: pact_json, pact_uri: pact_uri)
29
30
  end
30
31
  end
@@ -72,7 +73,8 @@ module Pact
72
73
  pact: :verify,
73
74
  pact_interaction: interaction,
74
75
  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]
76
78
  }
77
79
 
78
80
  describe description_for(interaction), metadata do
@@ -42,9 +42,21 @@ module Pact
42
42
  summary.failed_examples.collect{ |e| e.metadata[:pact_interaction_example_description] }.uniq.size
43
43
  end
44
44
 
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
+
45
57
  def totals_line summary
46
58
  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)
48
60
  line
49
61
  end
50
62
 
@@ -57,7 +69,11 @@ module Pact
57
69
  end
58
70
 
59
71
  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
61
77
  interaction_rerun_commands(summary).each do | message |
62
78
  output.puts(message)
63
79
  end
data/lib/pact/retry.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'pact/errors'
2
+
1
3
  module Pact
2
4
  class Retry
3
5
  class RescuableError
@@ -10,8 +10,8 @@ module Pact
10
10
 
11
11
  extend self
12
12
 
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)
15
15
  end
16
16
 
17
17
  def handle_verification_failure
@@ -19,7 +19,7 @@ module Pact
19
19
  abort if exit_status != 0
20
20
  end
21
21
 
22
- def verify_command pact_helper, pact_uri, rspec_opts
22
+ def verify_command pact_helper, pact_uri, rspec_opts, verification_opts
23
23
  command_parts = []
24
24
  # Clear SPEC_OPTS, otherwise we can get extra formatters, creating duplicate output eg. CI Reporting.
25
25
  # Allow deliberate configuration using rspec_opts in VerificationTask.
@@ -28,6 +28,7 @@ module Pact
28
28
  command_parts << "-S pact verify"
29
29
  command_parts << "--pact-helper" << Shellwords.escape(pact_helper.end_with?(".rb") ? pact_helper : pact_helper + ".rb")
30
30
  (command_parts << "--pact-uri" << pact_uri) if pact_uri
31
+ command_parts << "--wip" if verification_opts[:wip]
31
32
  command_parts << "--pact-broker-username" << ENV['PACT_BROKER_USERNAME'] if ENV['PACT_BROKER_USERNAME']
32
33
  command_parts << "--pact-broker-password" << ENV['PACT_BROKER_PASSWORD'] if ENV['PACT_BROKER_PASSWORD']
33
34
  command_parts << "--backtrace" if ENV['BACKTRACE'] == 'true'
@@ -30,9 +30,11 @@ module Pact
30
30
 
31
31
  attr_reader :pact_spec_configs
32
32
  attr_accessor :rspec_opts
33
+ attr_accessor :wip
33
34
 
34
35
  def initialize(name)
35
36
  @rspec_opts = nil
37
+ @wip = false
36
38
  @pact_spec_configs = []
37
39
  @name = name
38
40
  yield self
@@ -74,7 +76,7 @@ module Pact
74
76
  require 'pact/tasks/task_helper'
75
77
 
76
78
  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 }
78
80
  end
79
81
 
80
82
  Pact::TaskHelper.handle_verification_failure do
data/lib/pact/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # Remember to bump pact-provider-proxy when this changes major version
2
2
  module Pact
3
- VERSION = "1.28.0"
3
+ VERSION = "1.29.0"
4
4
  end
data/pact.gemspec CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |gem|
33
33
 
34
34
  gem.add_development_dependency 'rake', '~> 10.0.3'
35
35
  gem.add_development_dependency 'webmock', '~> 3.0'
36
- gem.add_development_dependency 'pry-byebug'
36
+ #gem.add_development_dependency 'pry-byebug'
37
37
  gem.add_development_dependency 'fakefs', '0.5' # 0.6.0 blows up
38
38
  gem.add_development_dependency 'hashie', '~> 2.0'
39
39
  gem.add_development_dependency 'activesupport'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.28.0
4
+ version: 1.29.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Fraser
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2018-06-28 00:00:00.000000000 Z
15
+ date: 2018-07-24 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: randexp
@@ -174,20 +174,6 @@ dependencies:
174
174
  - - "~>"
175
175
  - !ruby/object:Gem::Version
176
176
  version: '3.0'
177
- - !ruby/object:Gem::Dependency
178
- name: pry-byebug
179
- requirement: !ruby/object:Gem::Requirement
180
- requirements:
181
- - - ">="
182
- - !ruby/object:Gem::Version
183
- version: '0'
184
- type: :development
185
- prerelease: false
186
- version_requirements: !ruby/object:Gem::Requirement
187
- requirements:
188
- - - ">="
189
- - !ruby/object:Gem::Version
190
- version: '0'
191
177
  - !ruby/object:Gem::Dependency
192
178
  name: fakefs
193
179
  requirement: !ruby/object:Gem::Requirement
@@ -335,7 +321,9 @@ files:
335
321
  - lib/pact/hal/entity.rb
336
322
  - lib/pact/hal/http_client.rb
337
323
  - lib/pact/hal/link.rb
324
+ - lib/pact/pact_broker.rb
338
325
  - lib/pact/pact_broker/fetch_pacts.rb
326
+ - lib/pact/pact_broker/fetch_wip_pacts.rb
339
327
  - lib/pact/project_root.rb
340
328
  - lib/pact/provider.rb
341
329
  - lib/pact/provider/configuration.rb