rspec-pact-matchers 0.1.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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +56 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rspec/pact/matchers.rb +26 -0
- data/lib/rspec/pact/matchers/version.rb +7 -0
- data/rspec-pact-matchers.gemspec +38 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 90a3eb56793c69ceda26cc054a63763afa516842
|
4
|
+
data.tar.gz: 4153e63cc2bb8f477db92556cd38f478387f3ae2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 99acc645a84cbc68498a444125115cc5c8e0bf36cb596ed6321f449c5072d1ebe37dd362b34db1cc9fbbc12f692b9c2f6f0d046d1ba0c293ec0440d40b4b02fa
|
7
|
+
data.tar.gz: 2ab6c6d8a2139bc0b6866600a3d2d073ff7f5395284351e36407f622fd3a37dac0fa1da7866305a0edc782f0059121172cb0c798e3b12f64e3abedd011288113
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Beth Skurrie
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# RSpec Pact Matchers
|
2
|
+
|
3
|
+
This gem provides a `match_pact` RSpec matcher that uses the underlying matching logic from the [Pact][pact-gem] gem to compare two "JSON" object graphs (ie. Hashes, Arrays, and the simple object types that result from parsing a JSON document into a Ruby data structure). The expected JSON object graph may be "plain old Ruby", or it may use the Pact [matchers][[pact-matchers]] (`Pact.like`, `Pact.term` etc).
|
4
|
+
|
5
|
+
Note that Pact is a library designed for testing consumer contracts, and it follows [Postel's law][[postels-law]] in being "liberal in what you accept from others". This means that it allows unexpected keys in the actual document by default. If you are using the `match_pact` to test data that will be sent to another system, you should "be conservative in what you send" and use the `{allow_unexpected_keys: false}` option.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rspec-pact-matchers'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rspec-pact-matchers
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
The RSpec Pact matcher will allow
|
26
|
+
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'rspec/pact/matchers'
|
30
|
+
|
31
|
+
# Simple match, allowing extra keys
|
32
|
+
|
33
|
+
expect(thing: 'foo', other_thing: 'bar').to match_pact(thing: 'foo')
|
34
|
+
|
35
|
+
# Disallowing extra keys
|
36
|
+
|
37
|
+
expect(thing: 'foo', other_thing: 'bar').to match_pact({thing: 'foo'}, {allow_unexpected_keys: false}) # This will fail
|
38
|
+
|
39
|
+
# Using Pact matchers
|
40
|
+
|
41
|
+
expect(thing: 'foo', other_thing: 'bar').to match_pact(Pact.like(thing: 'wiffle'))
|
42
|
+
|
43
|
+
```
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pact-foundation/rspec-pact-matchers.
|
48
|
+
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
53
|
+
|
54
|
+
[pact-gem]: https://github.com/realestate-com-au/pact
|
55
|
+
[pact-matchers]: https://github.com/realestate-com-au/pact/wiki/v2-flexible-matching
|
56
|
+
[postels-law]: https://en.wikipedia.org/wiki/Robustness_principle
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rspec/pact/matchers"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "rspec/pact/matchers/version"
|
2
|
+
require "pact/support"
|
3
|
+
require "term/ansicolor"
|
4
|
+
|
5
|
+
RSpec::Matchers.define :match_pact do |expected, options = {}|
|
6
|
+
|
7
|
+
match do |actual|
|
8
|
+
@diff = Pact::Matchers.diff(expected, actual, options)
|
9
|
+
@diff.empty?
|
10
|
+
end
|
11
|
+
|
12
|
+
failure_message do |actual|
|
13
|
+
formatted_diff = Pact::Matchers::UnixDiffFormatter.call(@diff, :colour => true)
|
14
|
+
colorize(formatted_diff)
|
15
|
+
end
|
16
|
+
|
17
|
+
failure_message_when_negated do |actual|
|
18
|
+
"Expected #{actual} to not match #{expected} but it did."
|
19
|
+
end
|
20
|
+
|
21
|
+
def colorize(s)
|
22
|
+
s.split("\n").collect do |line|
|
23
|
+
::Term::ANSIColor.reset + line
|
24
|
+
end.join("\n")
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec/pact/matchers/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec-pact-matchers"
|
8
|
+
spec.version = Rspec::Pact::Matchers::VERSION
|
9
|
+
spec.authors = ["Beth Skurrie", "Mike Williams"]
|
10
|
+
spec.email = ["beth@bethesque.com", "mdub@dogbiscuit.org"]
|
11
|
+
|
12
|
+
spec.summary = %q{RSpec matcher using the Pact matching logic}
|
13
|
+
spec.homepage = "http://pact.io"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# # to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
# if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
# else
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
# "public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_runtime_dependency "pact-support", ">=1.1.2", "<2.0"
|
33
|
+
spec.add_runtime_dependency "rspec", "~> 3.0"
|
34
|
+
spec.add_runtime_dependency 'term-ansicolor', '~> 1.0'
|
35
|
+
|
36
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
37
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-pact-matchers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Beth Skurrie
|
8
|
+
- Mike Williams
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-06-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: pact-support
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 1.1.2
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '2.0'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 1.1.2
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
type: :runtime
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: term-ansicolor
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.14'
|
69
|
+
type: :development
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.14'
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: rake
|
78
|
+
requirement: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
description:
|
91
|
+
email:
|
92
|
+
- beth@bethesque.com
|
93
|
+
- mdub@dogbiscuit.org
|
94
|
+
executables: []
|
95
|
+
extensions: []
|
96
|
+
extra_rdoc_files: []
|
97
|
+
files:
|
98
|
+
- ".gitignore"
|
99
|
+
- ".rspec"
|
100
|
+
- ".travis.yml"
|
101
|
+
- Gemfile
|
102
|
+
- LICENSE.txt
|
103
|
+
- README.md
|
104
|
+
- Rakefile
|
105
|
+
- bin/console
|
106
|
+
- bin/setup
|
107
|
+
- lib/rspec/pact/matchers.rb
|
108
|
+
- lib/rspec/pact/matchers/version.rb
|
109
|
+
- rspec-pact-matchers.gemspec
|
110
|
+
homepage: http://pact.io
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.4.5
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: RSpec matcher using the Pact matching logic
|
134
|
+
test_files: []
|