pact 1.44.1 → 1.45.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4377cccb8581a6f7215bf6f451bf97ac5b32d9d2a2c1f0a1fd05925ae5dd2f83
4
- data.tar.gz: e4b78191ae99e50678b1034843168edc125b1ba1a4fb2686bc25e50609b0c4dc
3
+ metadata.gz: 021b58b1630e4e9943572668e342498886c0373a728d88bb0acba4f2f05f8a73
4
+ data.tar.gz: ca7709d98dd311e2ded9d210b0ff4c51ecd38f62f278728f511d689a638055e9
5
5
  SHA512:
6
- metadata.gz: cb2ae0b2b047c760b8336401fe4c82e01df60f2f3b8c3ec8cc217b99f443269713fc7f57d425e684a4b6e59a90ce17664a1eff08653eb9d440805ebb2873e27e
7
- data.tar.gz: 5aceeb5ae1f627fa20635cd0d1bb6d6fcc6774df37ca9bb7d083cd4b72a7ac724c55b2c96258ee11d75ab11625fb720a023974c407c1c289afe6d106abe02192
6
+ metadata.gz: 21df8b8dc7ad42d9128ebdd174001d2a013b8eedf815222a54279b78f2b48ea5bdd8fc1e39e5d9c38ce2e881f650b0bde027914a11ccb55cfa7558bca2de8dd2
7
+ data.tar.gz: 15218777fc8b7560508c00eb50f297732d7cb8458411e777390ad4a9b0e68f21b12ba84630021e5110c144f8c2c05154f205f6d890d4b43dd3122a5f6033d63b
@@ -1,3 +1,18 @@
1
+ <a name="v1.45.0"></a>
2
+ ### v1.45.0 (2020-01-21)
3
+
4
+
5
+ #### Features
6
+
7
+ * use custom json formatter when --format json is specified and send it straight to stdout or the configured file ([6c703a1](/../../commit/6c703a1))
8
+ * support pending pacts in json formatter ([2c0d20d](/../../commit/2c0d20d))
9
+
10
+
11
+ #### Bug Fixes
12
+
13
+ * show pending test output in yellow instead of red ([e8d4a55](/../../commit/e8d4a55))
14
+
15
+
1
16
  <a name="v1.44.1"></a>
2
17
  ### v1.44.1 (2020-01-20)
3
18
 
@@ -3,7 +3,6 @@ require 'pact/cli/spec_criteria'
3
3
  module Pact
4
4
  module Cli
5
5
  class RunPactVerification
6
-
7
6
  attr_reader :options
8
7
 
9
8
  def initialize options
@@ -15,6 +14,7 @@ module Pact
15
14
  end
16
15
 
17
16
  def call
17
+ configure_output
18
18
  initialize_rspec
19
19
  setup_load_path
20
20
  load_pact_helper
@@ -83,6 +83,14 @@ module Pact
83
83
  request_customizer: options[:request_customizer]
84
84
  }
85
85
  end
86
+
87
+ def configure_output
88
+ if options[:format] == 'json' && !options[:out]
89
+ # Don't want to mess up the JSON parsing with messages to stdout, so send it to stderr
90
+ require 'pact/configuration'
91
+ Pact.configuration.output_stream = Pact.configuration.error_stream
92
+ end
93
+ end
86
94
  end
87
95
  end
88
96
  end
@@ -9,9 +9,8 @@ require 'pact/provider/pact_source'
9
9
  require 'pact/provider/help/write'
10
10
  require 'pact/provider/verification_results/publish_all'
11
11
  require 'pact/provider/rspec/pact_broker_formatter'
12
-
13
- require_relative 'rspec'
14
-
12
+ require 'pact/provider/rspec/json_formatter'
13
+ require 'pact/provider/rspec'
15
14
 
16
15
  module Pact
17
16
  module Provider
@@ -91,7 +90,7 @@ module Pact
91
90
  ::RSpec::Core::CommandLine.new(NoConfigurationOptions.new)
92
91
  .run(::RSpec.configuration.output_stream, ::RSpec.configuration.error_stream)
93
92
  end
94
- (all_pacts_pending? || options[:ignore_failures]) ? 0 : exit_code
93
+ pending_mode? ? 0 : exit_code
95
94
  end
96
95
 
97
96
  def rspec_runner_options
@@ -118,12 +117,12 @@ module Pact
118
117
 
119
118
  def initialize_specs
120
119
  pact_sources.each do | pact_source |
121
- options = {
122
- criteria: @options[:criteria],
123
- ignore_failures: @options[:ignore_failures],
124
- request_customizer: @options[:request_customizer]
120
+ spec_options = {
121
+ criteria: options[:criteria],
122
+ ignore_failures: options[:ignore_failures],
123
+ request_customizer: options[:request_customizer]
125
124
  }
126
- honour_pactfile pact_source.uri, ordered_pact_json(pact_source.pact_json), options
125
+ honour_pactfile pact_source.uri, ordered_pact_json(pact_source.pact_json), spec_options
127
126
  end
128
127
  end
129
128
 
@@ -134,10 +133,13 @@ module Pact
134
133
 
135
134
  output = options[:out] || Pact.configuration.output_stream
136
135
  if options[:format]
137
- ::RSpec.configuration.add_formatter options[:format], output
138
- if !options[:out]
139
- # Don't want to mess up the JSON parsing with messages to stdout, so send it to stderr
140
- Pact.configuration.output_stream = Pact.configuration.error_stream
136
+ if options[:format] == 'json'
137
+ # To avoid mixing JSON and logging, the output_stream will be set to the error_stream
138
+ # in the pact-provider-verifier.
139
+ # Send JSON to a file if configured, or straight to $stdout
140
+ ::RSpec.configuration.add_formatter Pact::Provider::RSpec::JsonFormatter, options[:out] || $stdout
141
+ else
142
+ ::RSpec.configuration.add_formatter options[:format], output
141
143
  end
142
144
  else
143
145
  # Sometimes the formatter set in the cli.rb get set with an output of StringIO.. don't know why
@@ -148,7 +150,7 @@ module Pact
148
150
 
149
151
  ::RSpec.configuration.full_backtrace = @options[:full_backtrace]
150
152
 
151
- ::RSpec.configuration.failure_color = :yellow if @options[:ignore_failures]
153
+ ::RSpec.configuration.failure_color = :yellow if pending_mode?
152
154
  end
153
155
 
154
156
  def ordered_pact_json(pact_json)
@@ -169,6 +171,10 @@ module Pact
169
171
  false
170
172
  end
171
173
 
174
+ def pending_mode?
175
+ (all_pacts_pending? || options[:ignore_failures])
176
+ end
177
+
172
178
  def executing_with_ruby?
173
179
  ENV['PACT_EXECUTING_LANGUAGE'] == 'ruby'
174
180
  end
@@ -6,13 +6,13 @@ require 'pact/provider/help/prompt_text'
6
6
  module Pact
7
7
  module Provider
8
8
  module RSpec
9
-
10
9
  class Formatter < ::RSpec::Core::Formatters::DocumentationFormatter
11
10
 
12
11
  class NilFormatter < ::RSpec::Core::Formatters::BaseFormatter
13
12
  Pact::RSpec.with_rspec_3 do
14
13
  ::RSpec::Core::Formatters.register self, :start, :example_group_started, :close
15
14
  end
15
+
16
16
  def dump_summary(summary)
17
17
  end
18
18
  end
@@ -0,0 +1,86 @@
1
+ require 'rspec/core/formatters/json_formatter'
2
+
3
+ module Pact
4
+ module Provider
5
+ module RSpec
6
+ class JsonFormatter < ::RSpec::Core::Formatters::JsonFormatter
7
+ ::RSpec::Core::Formatters.register self, :message, :dump_summary, :dump_profile, :stop, :seed, :close
8
+
9
+ def dump_summary(summary)
10
+ super(create_custom_summary(summary))
11
+ output_hash[:summary][:notices] = pact_broker_notices(summary)
12
+ end
13
+
14
+ def format_example(example)
15
+ {
16
+ :id => example.id,
17
+ :description => example.description,
18
+ :full_description => example.full_description,
19
+ :status => calculate_status(example),
20
+ :file_path => example.metadata[:file_path],
21
+ :line_number => example.metadata[:line_number],
22
+ :run_time => example.execution_result.run_time,
23
+ :mismatches => extract_differences(example)
24
+ }
25
+ end
26
+
27
+ def stop(notification)
28
+ output_hash[:examples] = notification.examples.map do |example|
29
+ format_example(example).tap do |hash|
30
+ e = example.exception
31
+ # No point providing a backtrace for a mismatch, too much noise
32
+ if e && ! e.is_a?(::RSpec::Expectations::ExpectationNotMetError)
33
+ hash[:exception] = {
34
+ :class => e.class.name,
35
+ :message => e.message,
36
+ :backtrace => e.backtrace,
37
+ }
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def calculate_status(example)
44
+ if example.execution_result.status == :failed && example.metadata[:pact_ignore_failures]
45
+ 'pending'
46
+ else
47
+ example.execution_result.status.to_s
48
+ end
49
+ end
50
+
51
+ # There will most likely be only one pact associated with this RSpec execution, because
52
+ # the most likely user of this formatter is the Go implementation that parses the JSON
53
+ # and builds Go tests from them.
54
+ # If the JSON formatter is used by someone else and they have multiple pacts, all the notices
55
+ # for the pacts will be mushed together in one collection, so it will be hard to know which notice
56
+ # belongs to which pact.
57
+ def pact_broker_notices(summary)
58
+ pact_uris(summary).collect{ |pact_uri| pact_uri.metadata[:notices] }.compact.flatten
59
+ end
60
+
61
+ def pact_uris(summary)
62
+ summary.examples.collect(&:metadata).collect{ |metadata| metadata[:pact_uri] }.uniq
63
+ end
64
+
65
+ def create_custom_summary(summary)
66
+ ::RSpec::Core::Notifications::SummaryNotification.new(
67
+ summary.duration,
68
+ summary.examples,
69
+ summary.examples.select{ | example | example.execution_result.status == :failed && !example.metadata[:pact_ignore_failures] },
70
+ summary.examples.select{ | example | example.execution_result.status == :failed && example.metadata[:pact_ignore_failures] },
71
+ summary.load_time,
72
+ summary.errors_outside_of_examples_count
73
+ )
74
+ end
75
+
76
+ def extract_differences(example)
77
+ if example.metadata[:pact_diff]
78
+ Pact::Matchers::ExtractDiffMessages.call(example.metadata[:pact_diff]).to_a
79
+ else
80
+ []
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -66,7 +66,7 @@ module Pact
66
66
  if example.metadata[:pact_diff]
67
67
  hash[:differences] = Pact::Matchers::ExtractDiffMessages.call(example.metadata[:pact_diff])
68
68
  .to_a
69
- .collect{ | description | {description: description} }
69
+ .collect{ | description | { description: description } }
70
70
  end
71
71
  end
72
72
  end
@@ -1,4 +1,4 @@
1
1
  # Remember to bump pact-provider-proxy when this changes major version
2
2
  module Pact
3
- VERSION = "1.44.1"
3
+ VERSION = "1.45.0"
4
4
  end
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.44.1
4
+ version: 1.45.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: 2020-01-20 00:00:00.000000000 Z
15
+ date: 2020-01-21 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rspec
@@ -361,6 +361,7 @@ files:
361
361
  - lib/pact/provider/rspec/custom_options_file
362
362
  - lib/pact/provider/rspec/formatter_rspec_2.rb
363
363
  - lib/pact/provider/rspec/formatter_rspec_3.rb
364
+ - lib/pact/provider/rspec/json_formatter.rb
364
365
  - lib/pact/provider/rspec/matchers.rb
365
366
  - lib/pact/provider/rspec/pact_broker_formatter.rb
366
367
  - lib/pact/provider/state/provider_state.rb