Skip to content

Commit 0ae9b71

Browse files
committed
Merge branch 'master' into feat/message-contracts
2 parents 0f22db2 + 5c98b9f commit 0ae9b71

29 files changed

+163
-96
lines changed

.travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ rvm:
44
- 2.1.8
55
- 2.2.4
66
- 2.3.1
7+
- 2.4.3
8+
- 2.5.0
79
- jruby-9.1.13.0
810
gemfile:
911
- gemfiles/default.gemfile
@@ -19,5 +21,9 @@ matrix:
1921
gemfile: gemfiles/ruby_under_22.gemfile
2022
- rvm: 2.3.1
2123
gemfile: gemfiles/ruby_under_22.gemfile
24+
- rvm: 2.4.3
25+
gemfile: gemfiles/ruby_under_22.gemfile
26+
- rvm: 2.5.0
27+
gemfile: gemfiles/ruby_under_22.gemfile
2228
- rvm: jruby-9.1.13.0
2329
gemfile: gemfiles/ruby_under_22.gemfile

CHANGELOG.md

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1-
Do this to generate your change history
1+
<a name="v1.3.1"></a>
2+
### v1.3.1 (2018-03-19)
23

3-
git log --pretty=format:' * %h - %s (%an, %ad)'
4+
#### Bug Fixes
5+
6+
* dynamically load pact/matchers ([d80e0ff](/../../commit/d80e0ff))
7+
8+
9+
<a name="v1.3.0"></a>
10+
### v1.3.0 (2018-03-19)
11+
12+
#### Features
13+
14+
* do not automatically create tmp/pacts dir ([de9e25e](/../../commit/de9e25e))
15+
16+
17+
<a name="v1.2.5"></a>
18+
### v1.2.5 (2018-02-16)
19+
20+
#### Bug Fixes
21+
22+
* replace backslashes in pact dir path with forward slashes ([a1b5013](/../../commit/a1b5013))
423

524
### 1.2.4 (2017-10-30)
625
* 80bbdcc - fix: remove unused dependency on rack-test (Beth Skurrie, Mon Oct 30 09:52:22 2017 +1100)

RELEASING.md

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
# Releasing
22

3-
1. Increment the version in `lib/pact/support/version.rb`
4-
2. Update the `CHANGELOG.md` using:
3+
Run
54

6-
$ git log --pretty=format:' * %h - %s (%an, %ad)' vX.Y.Z..HEAD
7-
8-
3. Add files to git
9-
10-
$ git add CHANGELOG.md lib/pact/support/version.rb
11-
$ git commit -m "chore(release): version $(ruby -r ./lib/pact/support/version.rb -e "puts Pact::Support::VERSION")"
12-
13-
3. Release:
14-
15-
$ bundle exec rake release
5+
script/release.sh [major|minor|patch] # default is minor

lib/pact/configuration.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def logger
7272

7373
# Should this be deprecated in favour of register_diff_formatter???
7474
def diff_formatter= diff_formatter
75-
register_diff_formatter /.*/, diff_formatter
76-
register_diff_formatter nil, diff_formatter
75+
register_diff_formatter(/.*/, diff_formatter)
76+
register_diff_formatter(nil, diff_formatter)
7777
end
7878

7979
def register_diff_formatter content_type, diff_formatter
@@ -174,11 +174,9 @@ def self.configuration
174174

175175
def self.configure
176176
yield configuration
177-
FileUtils::mkdir_p configuration.tmp_dir
178177
end
179178

180179
def self.clear_configuration
181180
@configuration = nil
182181
end
183-
184182
end

lib/pact/consumer_contract/file_name.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ def file_name consumer_name, provider_name, options = {}
88
end
99

1010
def file_path consumer_name, provider_name, pact_dir = Pact.configuration.pact_dir, options = {}
11-
File.join(pact_dir, file_name(consumer_name, provider_name, options))
11+
File.join(windows_safe(pact_dir), file_name(consumer_name, provider_name, options))
1212
end
1313

1414
def filenamify name
1515
name.downcase.gsub(/\s/, '_')
1616
end
17+
18+
def windows_safe(pact_dir)
19+
pact_dir.gsub("\\", "/")
20+
end
1721
end
1822
end

lib/pact/consumer_contract/query_string.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require 'pact/shared/active_support_support'
2-
require 'pact/matchers'
32

43
module Pact
54
class QueryString

lib/pact/helpers.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ def like_datetime datetime
3737
Pact::Term.new(generate: datetime, matcher: /^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)$/)
3838
end
3939

40-
def like_datetime_with_miliseconds datetime
40+
def like_datetime_with_milliseconds datetime
4141
Pact::Term.new(generate: datetime, matcher: /^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d{3}([+-][0-2]\d:[0-5]\d|Z)$/)
4242
end
4343

44+
alias_method :like_datetime_with_miliseconds, :like_datetime_with_milliseconds
45+
4446
def like_date date
4547
Pact::Term.new(generate: date, matcher: /^\d{4}-[01]\d-[0-3]\d$/)
4648
end

lib/pact/matchers/extract_diff_messages.rb

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# @api public. Used by lib/pact/provider/rspec/pact_broker_formatter.rb
12
module Pact
23
module Matchers
34
class ExtractDiffMessages
@@ -13,17 +14,21 @@ def self.call diff, options = {}
1314
end
1415

1516
def to_hash
16-
diff
17+
to_a
1718
end
1819

1920
def call
20-
to_s
21+
to_a
2122
end
2223

2324
def to_s
2425
diff_messages(diff).join("\n")
2526
end
2627

28+
def to_a
29+
diff_messages(diff)
30+
end
31+
2732
def diff_messages obj, path = [], messages = []
2833
case obj
2934
when Hash then handle_hash obj, path, messages
@@ -51,7 +56,7 @@ def handle_array array, path, messages
5156

5257
def handle_difference difference, path, messages
5358
if difference.message
54-
message = "* #{difference.message}"
59+
message = difference.message
5560
message = message.gsub("<path>", path_to_s(path))
5661
message = message.gsub("<parent_path>", parent_path_to_s(path))
5762
messages << message

lib/pact/matchers/matchers.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def type_difference_message expected, actual
224224
expected_desc = class_name_with_value_in_brackets(expected)
225225
expected_desc.gsub!("(", "(like ")
226226
actual_desc = class_name_with_value_in_brackets(actual)
227-
message = "Expected #{expected_desc} but got #{actual_desc} at <path>"
227+
"Expected #{expected_desc} but got #{actual_desc} at <path>"
228228
end
229229
end
230230
end

lib/pact/matchers/unix_diff_formatter.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def initialize diff, options = {}
1717
@actual = options.fetch(:actual, {})
1818
@include_explanation = options.fetch(:include_explanation, true)
1919
@differ = Pact::Matchers::Differ.new(@colour)
20-
@messages = Pact::Matchers::ExtractDiffMessages.call(diff)
20+
@messages = Pact::Matchers::ExtractDiffMessages.call(diff).collect{ | message| "* #{message}" }.join("\n")
2121
end
2222

2323
def self.call diff, options = {}

lib/pact/matching_rules/jsonpath.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class JsonPath
1313
def initialize(path)
1414
scanner = StringScanner.new(path)
1515
@path = []
16-
bracket_count = 0
1716
while not scanner.eos?
1817
if token = scanner.scan(/\$/)
1918
@path << token
@@ -49,10 +48,10 @@ def initialize(path)
4948
@path.last << token
5049
end
5150
end
51+
end
5252

53-
def to_s
54-
path.join
55-
end
53+
def to_s
54+
path.join
5655
end
5756
end
5857
end

lib/pact/reification.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ def self.from_term(term)
1515
when Pact::Term, Regexp, Pact::SomethingLike, Pact::ArrayLike
1616
from_term(term.generate)
1717
when Hash
18-
term.inject({}) do |mem, (key,term)|
19-
mem[key] = from_term(term)
18+
term.inject({}) do |mem, (key,t)|
19+
mem[key] = from_term(t)
2020
mem
2121
end
2222
when Array

lib/pact/shared/form_differ.rb

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
require 'pact/matchers/matchers'
21
require 'uri'
32

43
module Pact
54
class FormDiffer
65

7-
extend Matchers
8-
96
def self.call expected, actual, options = {}
10-
diff to_hash(expected), to_hash(actual), options
7+
require 'pact/matchers' # avoid recursive loop between this file and pact/matchers
8+
::Pact::Matchers.diff to_hash(expected), to_hash(actual), options
119
end
1210

1311
def self.to_hash form_body
@@ -19,8 +17,8 @@ def self.to_hash form_body
1917
end
2018

2119
def self.ensure_values_are_arrays hash
22-
hash.each_with_object({}) do | (key, value), hash |
23-
hash[key.to_s] = [*value]
20+
hash.each_with_object({}) do | (key, value), h |
21+
h[key.to_s] = [*value]
2422
end
2523
end
2624

@@ -30,6 +28,5 @@ def self.decode_www_form string
3028
hash[key] << value
3129
end
3230
end
33-
3431
end
3532
end

lib/pact/shared/json_differ.rb

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
require 'pact/matchers/matchers'
2-
31
module Pact
42
class JsonDiffer
53

6-
extend Matchers
7-
8-
# Delegates to https://github.com/bethesque/pact-support/blob/master/lib/pact/matchers/matchers.rb#L25
4+
# Delegates to https://github.com/pact-foundation/pact-support/blob/master/lib/pact/matchers/matchers.rb#L25
95
def self.call expected, actual, options = {}
10-
diff expected, actual, options
6+
require 'pact/matchers' # avoid recursive loop between this file and pact/matchers
7+
::Pact::Matchers.diff expected, actual, options
118
end
12-
13-
149
end
1510
end

lib/pact/shared/request.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
require 'pact/matchers'
21
require 'pact/symbolize_keys'
32
require 'pact/consumer_contract/headers'
43
require 'pact/consumer_contract/query'

lib/pact/shared/text_differ.rb

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
require 'pact/matchers/matchers'
2-
require 'pact/matchers/difference'
31

42
module Pact
53
class TextDiffer
64

7-
extend Matchers
8-
95
def self.call expected, actual, options = {}
10-
diff expected, actual, options
6+
require 'pact/matchers' # avoid recursive loop between this file and pact/matchers
7+
::Pact::Matchers.diff expected, actual, options
118
end
129

1310
end

lib/pact/support/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Pact
22
module Support
3-
VERSION = "1.2.99.alpha.1"
3+
VERSION = "1.4.0"
44
end
55
end

pact-support.gemspec

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ Gem::Specification.new do |gem|
2828
gem.add_runtime_dependency 'awesome_print', '~> 1.1'
2929

3030
gem.add_development_dependency 'rake', '~> 10.0.3'
31-
gem.add_development_dependency 'webmock', '~> 2.0.0'
31+
gem.add_development_dependency 'webmock', '~> 3.3'
3232
gem.add_development_dependency 'pry'
3333
gem.add_development_dependency 'fakefs', '~> 0.11.2'
3434
gem.add_development_dependency 'hashie', '~> 2.0'
3535
gem.add_development_dependency 'activesupport'
3636
gem.add_development_dependency 'appraisal'
37+
gem.add_development_dependency 'conventional-changelog', '~>1.3'
38+
gem.add_development_dependency 'bump', '~> 0.5'
3739
end

script/release.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
set -e
3+
4+
git checkout -- lib/pact/support/version.rb
5+
bundle exec bump ${1:-minor} --no-commit
6+
bundle exec rake generate_changelog
7+
git add CHANGELOG.md lib/pact/support/version.rb
8+
git commit -m "Releasing version $(ruby -r ./lib/pact/support/version.rb -e "puts Pact::Support::VERSION")"
9+
bundle exec rake release

spec/lib/pact/consumer_contract/file_name_spec.rb

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@
33
module Pact
44
describe FileName do
55
describe "file_path" do
6-
let(:subject) { FileName.file_path 'foo', 'bar', 'tmp/pacts' }
6+
7+
subject { FileName.file_path 'foo', 'bar', 'tmp/pacts' }
78
it { is_expected.to eq 'tmp/pacts/foo-bar.json' }
89

910
context "when unique is true" do
10-
let(:subject) { FileName.file_path 'foo', 'bar', 'tmp/pacts', unique: true }
11+
subject { FileName.file_path 'foo', 'bar', 'tmp/pacts', unique: true }
1112
it { is_expected.to match %r{tmp/pacts/foo-bar-\d+.json} }
1213
end
14+
15+
context "when the path includes backslashes" do
16+
subject { FileName.file_path 'foo', 'bar', 'c:\tmp\pacts' }
17+
18+
it "changes them to forward slashes" do
19+
expect(subject).to eq "c:/tmp/pacts/foo-bar.json"
20+
end
21+
end
1322
end
1423
end
1524
end

0 commit comments

Comments
 (0)