Skip to content

Commit 9536513

Browse files
committed
Merge branch 'master' into feat/message-contracts
2 parents f1a2cd4 + 157a1cc commit 9536513

File tree

8 files changed

+82
-58
lines changed

8 files changed

+82
-58
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
<a name="v1.21.0"></a>
2+
### v1.21.0 (2018-03-19)
3+
4+
5+
#### Features
6+
7+
* update pact-support to ~>1.3 ([17cfbf8](/../../commit/17cfbf8))
8+
* do not create reports/pacts/help.md when executing verify from a wrapper language ([ea6de47](/../../commit/ea6de47))
9+
10+
111
<a name="v1.20.0"></a>
212
### v1.20.0 (2017-12-10)
313

lib/pact/provider/rspec.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,17 @@ def describe_response expected_response, interaction_context
145145
let(:diff_options) { { with: differ, diff_formatter: diff_formatter } }
146146

147147
if expected_response.status
148-
it "has status code #{expected_response.status}" do
148+
it "has status code #{expected_response.status}" do | example |
149+
set_metadata(example, :pact_actual_status, response_status)
149150
expect(response_status).to eql expected_response_status
150151
end
151152
end
152153

153154
if expected_response.headers
154155
describe "includes headers" do
155156
expected_response.headers.each do |name, expected_header_value|
156-
it "\"#{name}\" which #{expected_desc_for_it(expected_header_value)}" do
157+
it "\"#{name}\" which #{expected_desc_for_it(expected_header_value)}" do | example |
158+
set_metadata(example, :pact_actual_headers, response.headers)
157159
header_value = response.headers[name]
158160
expect(header_value).to match_header(name, expected_header_value)
159161
end
@@ -162,8 +164,9 @@ def describe_response expected_response, interaction_context
162164
end
163165

164166
if expected_response.body
165-
it "has a matching body" do
166-
expect(response_body).to match_term expected_response_body, diff_options
167+
it "has a matching body" do | example |
168+
set_metadata(example, :pact_actual_body, response_body)
169+
expect(response_body).to match_term expected_response_body, diff_options, example
167170
end
168171
end
169172
end
@@ -176,7 +179,6 @@ def description_for interaction
176179
def interaction_description_for_rerun_command interaction
177180
description_for(interaction).capitalize + ( interaction.provider_state ? " given #{interaction.provider_state}" : "")
178181
end
179-
180182
end
181183

182184
# The "arrange" and "act" parts of the test really only need to be run once,

lib/pact/provider/rspec/matchers.rb

+14-31
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
require 'pact/rspec'
55
require 'pact/shared/json_differ'
66

7-
87
module Pact
98
module RSpec
109
module Matchers
11-
1210
module RSpec2Delegator
1311
# For backwards compatiblity with rspec-2
1412
def method_missing(method, *args, &block)
@@ -21,33 +19,40 @@ def method_missing(method, *args, &block)
2119
end
2220

2321
class MatchTerm
24-
2522
include Pact::Matchers::Messages
2623
include RSpec2Delegator
2724

28-
def initialize expected, differ, diff_formatter
25+
def initialize expected, differ, diff_formatter, example
2926
@expected = expected
3027
@differ = differ
3128
@diff_formatter = diff_formatter
29+
@example = example
3230
end
3331

3432
def matches? actual
3533
@actual = actual
36-
(@difference = @differ.call(@expected, @actual)).empty?
34+
@difference = @differ.call(@expected, @actual)
35+
unless @difference.empty?
36+
Pact::RSpec.with_rspec_3 do
37+
@example.metadata[:pact_diff] = @difference
38+
end
39+
Pact::RSpec.with_rspec_2 do
40+
@example.example.metadata[:pact_diff] = @difference
41+
end
42+
end
43+
@difference.empty?
3744
end
3845

3946
def failure_message
4047
match_term_failure_message @difference, @actual, @diff_formatter, Pact::RSpec.color_enabled?
4148
end
42-
4349
end
4450

45-
def match_term expected, options
46-
MatchTerm.new(expected, options.fetch(:with), options.fetch(:diff_formatter))
51+
def match_term expected, options, example
52+
MatchTerm.new(expected, options.fetch(:with), options.fetch(:diff_formatter), example)
4753
end
4854

4955
class MatchHeader
50-
5156
include Pact::Matchers
5257
include Pact::Matchers::Messages
5358
include RSpec2Delegator
@@ -65,33 +70,11 @@ def matches? actual
6570
def failure_message
6671
match_header_failure_message @header_name, @expected, @actual
6772
end
68-
6973
end
7074

7175
def match_header header_name, expected
7276
MatchHeader.new(header_name, expected)
7377
end
74-
7578
end
7679
end
7780
end
78-
79-
80-
# RSpec::Matchers.define :match_header do |header_name, expected|
81-
82-
# include Pact::Matchers
83-
# include Pact::Matchers::Messages
84-
85-
# match do |actual|
86-
# diff(expected, actual).empty?
87-
# end
88-
89-
# def failure_message_for_should(actual)
90-
# match_header_failure_message header_name, expected, actual
91-
# end
92-
93-
# # failure_message_for_should do | actual |
94-
# # match_header_failure_message header_name, expected, actual
95-
# # end
96-
97-
# end

lib/pact/provider/rspec/pact_broker_formatter.rb

+19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'rspec/core/formatters'
22
require 'pact/provider/verification_results/publish_all'
33
require 'term/ansicolor'
4+
require 'pact/matchers/extract_diff_messages'
45

56
module Pact
67
module Provider
@@ -59,6 +60,24 @@ def format_example(example)
5960
message: ::Term::ANSIColor.uncolor(example.exception.message)
6061
}
6162
end
63+
64+
if example.metadata[:pact_actual_status]
65+
hash[:actualStatus] = example.metadata[:pact_actual_status]
66+
end
67+
68+
if example.metadata[:pact_actual_headers]
69+
hash[:actualHeaders] = example.metadata[:pact_actual_headers]
70+
end
71+
72+
if example.metadata[:pact_actual_body]
73+
hash[:actualBody] = example.metadata[:pact_actual_body]
74+
end
75+
76+
if example.metadata[:pact_diff]
77+
hash[:differences] = Pact::Matchers::ExtractDiffMessages.call(example.metadata[:pact_diff])
78+
.to_a
79+
.collect{ | description | {description: description} }
80+
end
6281
end
6382
end
6483
end

lib/pact/provider/test_methods.rb

+10
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ def set_up_provider_state provider_state_name, consumer, options = {}
4141
def tear_down_provider_state provider_state_name, consumer, options = {}
4242
Pact.configuration.provider_state_tear_down.call(provider_state_name, consumer, options)
4343
end
44+
45+
def set_metadata example, key, value
46+
Pact::RSpec.with_rspec_3 do
47+
example.metadata[key] = value
48+
end
49+
50+
Pact::RSpec.with_rspec_2 do
51+
example.example.metadata[key] = value
52+
end
53+
end
4454
end
4555
end
4656
end

lib/pact/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Remember to bump pact-provider-proxy when this changes major version
22
module Pact
3-
VERSION = "1.20.1"
3+
VERSION = "1.21.0"
44
end

pact.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Gem::Specification.new do |gem|
2828
gem.add_runtime_dependency 'webrick'
2929
gem.add_runtime_dependency 'term-ansicolor', '~> 1.0'
3030

31-
gem.add_runtime_dependency 'pact-support', '~> 1.2', '>= 1.2.4'
31+
gem.add_runtime_dependency 'pact-support', '~> 1.4'
3232
gem.add_runtime_dependency 'pact-mock_service', '~> 2.0'
3333

3434
gem.add_development_dependency 'rake', '~> 10.0.3'

spec/lib/pact/provider/rspec_spec.rb

+20-20
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,53 @@
88

99
let(:diff_formatter) { Pact::Matchers::UnixDiffFormatter }
1010

11-
it 'does not match a hash to an array' do
11+
it 'does not match a hash to an array' do | example |
1212
expect({})
13-
.to_not match_term([], with: Pact::JsonDiffer, diff_formatter: diff_formatter)
13+
.to_not match_term([], { with: Pact::JsonDiffer, diff_formatter: diff_formatter }, example)
1414
end
1515

16-
it 'does not match an array to a hash' do
16+
it 'does not match an array to a hash' do | example |
1717
expect([])
18-
.to_not match_term({}, with: Pact::JsonDiffer, diff_formatter: diff_formatter)
18+
.to_not match_term({}, { with: Pact::JsonDiffer, diff_formatter: diff_formatter }, example)
1919
end
2020

21-
it 'matches regular expressions' do
21+
it 'matches regular expressions' do | example |
2222
expect('blah')
23-
.to match_term(/[a-z]*/, with: Pact::JsonDiffer, diff_formatter: diff_formatter)
23+
.to match_term(/[a-z]*/, { with: Pact::JsonDiffer, diff_formatter: diff_formatter }, example)
2424
end
2525

26-
it 'matches pact terms' do
26+
it 'matches pact terms' do | example |
2727
expect('wootle')
28-
.to match_term Pact.term(generate: 'wootle', matcher: /woot../), with: Pact::JsonDiffer, diff_formatter: diff_formatter
28+
.to match_term Pact.term(generate: 'wootle', matcher: /woot../), { with: Pact::JsonDiffer, diff_formatter: diff_formatter }, example
2929
end
3030

31-
it 'matches all elements of arrays' do
31+
it 'matches all elements of arrays' do | example |
3232
expect(['one', 'two', ['three']])
33-
.to match_term [/one/, 'two', [Pact.term(generate: 'three', matcher: /thr../)]], with: Pact::JsonDiffer, diff_formatter: diff_formatter
33+
.to match_term [/one/, 'two', [Pact.term(generate: 'three', matcher: /thr../)]], { with: Pact::JsonDiffer, diff_formatter: diff_formatter }, example
3434
end
3535

36-
it 'matches all values of hashes' do
36+
it 'matches all values of hashes' do | example |
3737
expect({ 1 => 'one', 2 => 2, 3 => 'three' })
38-
.to match_term({ 1 => /one/, 2 => 2, 3 => Pact.term(generate: 'three', matcher: /thr../) }, with: Pact::JsonDiffer, diff_formatter: diff_formatter)
38+
.to match_term({ 1 => /one/, 2 => 2, 3 => Pact.term(generate: 'three', matcher: /thr../) }, { with: Pact::JsonDiffer, diff_formatter: diff_formatter }, example)
3939
end
4040

41-
it 'matches all other objects using ==' do
42-
expect('wootle').to match_term 'wootle', with: Pact::JsonDiffer, diff_formatter: diff_formatter
41+
it 'matches all other objects using ==' do | example |
42+
expect('wootle').to match_term 'wootle', { with: Pact::JsonDiffer, diff_formatter: diff_formatter }, example
4343
end
4444

4545
# Note: because a consumer specifies only the keys it cares about, the pact ignores keys that are returned
4646
# by the provider, but not are not specified in the pact. This means that any hash will match an
4747
# expected empty hash, because there is currently no way for a consumer to expect an absence of keys.
48-
it 'is confused by an empty hash' do
49-
expect(hello: 'everyone').to match_term({}, with: Pact::JsonDiffer, diff_formatter: diff_formatter)
48+
it 'is confused by an empty hash' do | example |
49+
expect(hello: 'everyone').to match_term({}, { with: Pact::JsonDiffer, diff_formatter: diff_formatter }, example)
5050
end
5151

52-
it 'should not be confused by an empty array' do
53-
expect(['blah']).to_not match_term([], with: Pact::JsonDiffer, diff_formatter: diff_formatter)
52+
it 'should not be confused by an empty array' do | example |
53+
expect(['blah']).to_not match_term([], { with: Pact::JsonDiffer, diff_formatter: diff_formatter }, example)
5454
end
5555

56-
it "should allow matches on an array where each item in the array only contains a subset of the actual" do
56+
it "should allow matches on an array where each item in the array only contains a subset of the actual" do | example |
5757
expect([{ name: 'Fred', age: 12 }, { name: 'John', age: 13 }])
58-
.to match_term([{ name: 'Fred' }, { name: 'John' }], with: Pact::JsonDiffer, diff_formatter: diff_formatter)
58+
.to match_term([{ name: 'Fred' }, { name: 'John' }], { with: Pact::JsonDiffer, diff_formatter: diff_formatter }, example)
5959
end
6060
end

0 commit comments

Comments
 (0)