pact-consumer-minitest 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +3 -0
- data/example/animal-service/Gemfile +14 -0
- data/example/animal-service/Rakefile +5 -0
- data/example/animal-service/config.ru +3 -0
- data/example/animal-service/db/animal_db.sqlite3 +0 -0
- data/example/animal-service/lib/animal_service/animal_repository.rb +12 -0
- data/example/animal-service/lib/animal_service/api.rb +28 -0
- data/example/animal-service/lib/animal_service/db.rb +5 -0
- data/example/animal-service/spec/service_consumers/pact_helper.rb +11 -0
- data/example/animal-service/spec/service_consumers/provider_states_for_zoo_app.rb +26 -0
- data/example/zoo-app/Gemfile +12 -0
- data/example/zoo-app/Rakefile +7 -0
- data/example/zoo-app/lib/zoo_app/animal_service_client.rb +43 -0
- data/example/zoo-app/lib/zoo_app/models/alligator.rb +15 -0
- data/example/zoo-app/spec/pacts/zoo_app-animal_service.json +67 -0
- data/example/zoo-app/spec/service_providers/animal_service_client_spec.rb +74 -0
- data/example/zoo-app/spec/service_providers/pact_helper.rb +15 -0
- data/example/zoo-app/spec/spec_helper.rb +3 -0
- data/lib/pact/consumer/minitest.rb +41 -0
- data/lib/pact/consumer/minitest/version.rb +7 -0
- data/pact-consumer-minitest.gemspec +27 -0
- data/spec/integration/minitest_spec.rb +42 -0
- data/spec/integration/minitest_unit.rb +35 -0
- data/spec/lib/pact/consumer/minitest_spec.rb +43 -0
- data/spec/pacts/my_other_service_consumer-my_other_service_provider.json +31 -0
- data/spec/pacts/my_service_consumer-my_service_provider.json +31 -0
- data/spec/support/client.rb +27 -0
- data/spec/support/test.rb +34 -0
- data/tasks/test.rake +23 -0
- metadata +183 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
N2M4N2ZiYmZhNDg3OGEwMjk4MDgzZTBlMDQyMWUxNmNmNmNjZWY3OA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NDA0ZDIwNGExZTdhNjRhYWQyOWUwYjcwZTQ4MTdmNDJlMTUxZDNlNQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NjhlZGNmOWQyNTVmNjc0MDliZDlkMjc3NzI3MzJmOGY1ZmI5MjkxMTEzYWMy
|
10
|
+
YTE2ZmQ5NDBmZGUyOTg4MWY5NTMzZjg2NzYyYmM0YmE4NjdkZWIyZmZhNTlj
|
11
|
+
ZDQ0MjJjZGM5MTg4ZTc5NzQyZDUwOWNiNTQ4Yzc1MTRjMGEwZWY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MjM5NDJmMzQ3OTdhNTU0YmMyYWQ1NGU2NDQ3Y2EzODI5NTQ4MTk1MDliMTY3
|
14
|
+
YzQyYjFjMzc3OTM3NDQ1MTY1NWZmZmMxOTU5MmVmZTk1Yzk0YzE5ZDFkZDk0
|
15
|
+
NWZiNzliYmNjMWQ5ZGE4ZjE5MWJlMTYwOTRmMDI2NzI4N2RiNTc=
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
log/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Beth
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Pact::Consumer::Minitest
|
2
|
+
|
3
|
+
Provides Pact Consumer support for Minitest.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'pact-consumer-minitest'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install pact-consumer-minitest
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
See the README for the [pact](https://github.com/realestate-com-au/pact) gem for full instructions on how to use Pact.
|
22
|
+
|
23
|
+
To use Pact with Minitest, instead of requiring `"pact/consumer/rspec"`, require `"pact/consumer/minitest"` and include `Pact::Consumer::Minitest` in your spec or unit test.
|
24
|
+
|
25
|
+
See an example [here](/example/zoo-app/spec/service_providers/animal_service_client_spec.rb).
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it ( https://github.com/[my-github-username]/pact-consumer-minitest/fork )
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
Binary file
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require_relative 'animal_repository'
|
3
|
+
|
4
|
+
module AnimalService
|
5
|
+
|
6
|
+
class Api < Sinatra::Base
|
7
|
+
|
8
|
+
set :raise_errors, false
|
9
|
+
set :show_exceptions, false
|
10
|
+
|
11
|
+
error do
|
12
|
+
e = env['sinatra.error']
|
13
|
+
content_type :json
|
14
|
+
status 500
|
15
|
+
{error: e.message, backtrace: e.backtrace}.to_json
|
16
|
+
end
|
17
|
+
|
18
|
+
get '/alligators/:name' do
|
19
|
+
if (alligator = AnimalRepository.find_alligator_by_name(params[:name]))
|
20
|
+
content_type :json
|
21
|
+
alligator.to_json
|
22
|
+
else
|
23
|
+
status 404
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'sequel'
|
2
|
+
require 'animal_service/db'
|
3
|
+
require 'animal_service/animal_repository'
|
4
|
+
|
5
|
+
Pact.provider_states_for "Zoo App" do
|
6
|
+
|
7
|
+
set_up do
|
8
|
+
AnimalService::DATABASE[:animals].truncate
|
9
|
+
end
|
10
|
+
|
11
|
+
provider_state "there is an alligator named Mary" do
|
12
|
+
set_up do
|
13
|
+
AnimalService::DATABASE[:animals].insert(name: 'Mary')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
provider_state "there is not an alligator named Mary" do
|
18
|
+
no_op
|
19
|
+
end
|
20
|
+
|
21
|
+
provider_state "an error occurs retrieving an alligator" do
|
22
|
+
set_up do
|
23
|
+
allow(AnimalService::AnimalRepository).to receive(:find_alligator_by_name).and_raise("Argh!!!")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'zoo_app/models/alligator'
|
3
|
+
|
4
|
+
module ZooApp
|
5
|
+
|
6
|
+
class AnimalServiceError < StandardError; end
|
7
|
+
|
8
|
+
class AnimalServiceClient
|
9
|
+
|
10
|
+
include HTTParty
|
11
|
+
base_uri 'animal-service.com'
|
12
|
+
|
13
|
+
def self.find_alligators
|
14
|
+
response = get("/alligators", :headers => {'Accept' => 'application/json'})
|
15
|
+
handle_response response do
|
16
|
+
parse_body(response).collect do | hash |
|
17
|
+
ZooApp::Animals::Alligator.new(hash)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.find_alligator_by_name name
|
23
|
+
response = get("/alligators/#{name}", :headers => {'Accept' => 'application/json'})
|
24
|
+
when_successful(response) do
|
25
|
+
ZooApp::Animals::Alligator.new(parse_body(response))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.when_successful response
|
30
|
+
if response.success?
|
31
|
+
yield
|
32
|
+
elsif response.code == 404
|
33
|
+
nil
|
34
|
+
else
|
35
|
+
raise AnimalServiceError.new(response.body)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.parse_body response
|
40
|
+
JSON.parse(response.body, {:symbolize_names => true})
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
{
|
2
|
+
"provider": {
|
3
|
+
"name": "Animal Service"
|
4
|
+
},
|
5
|
+
"consumer": {
|
6
|
+
"name": "Zoo App"
|
7
|
+
},
|
8
|
+
"interactions": [
|
9
|
+
{
|
10
|
+
"description": "a request for an alligator",
|
11
|
+
"provider_state": "an error occurs retrieving an alligator",
|
12
|
+
"request": {
|
13
|
+
"method": "get",
|
14
|
+
"path": "/alligators/Mary",
|
15
|
+
"headers": {
|
16
|
+
"Accept": "application/json"
|
17
|
+
}
|
18
|
+
},
|
19
|
+
"response": {
|
20
|
+
"status": 500,
|
21
|
+
"headers": {
|
22
|
+
"Content-Type": "application/json;charset=utf-8"
|
23
|
+
},
|
24
|
+
"body": {
|
25
|
+
"error": "Argh!!!"
|
26
|
+
}
|
27
|
+
}
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"description": "a request for an alligator",
|
31
|
+
"provider_state": "there is an alligator named Mary",
|
32
|
+
"request": {
|
33
|
+
"method": "get",
|
34
|
+
"path": "/alligators/Mary",
|
35
|
+
"headers": {
|
36
|
+
"Accept": "application/json"
|
37
|
+
}
|
38
|
+
},
|
39
|
+
"response": {
|
40
|
+
"status": 200,
|
41
|
+
"headers": {
|
42
|
+
"Content-Type": "application/json;charset=utf-8"
|
43
|
+
},
|
44
|
+
"body": {
|
45
|
+
"name": "Mary"
|
46
|
+
}
|
47
|
+
}
|
48
|
+
},
|
49
|
+
{
|
50
|
+
"description": "a request for an alligator",
|
51
|
+
"provider_state": "there is not an alligator named Mary",
|
52
|
+
"request": {
|
53
|
+
"method": "get",
|
54
|
+
"path": "/alligators/Mary",
|
55
|
+
"headers": {
|
56
|
+
"Accept": "application/json"
|
57
|
+
}
|
58
|
+
},
|
59
|
+
"response": {
|
60
|
+
"status": 404
|
61
|
+
}
|
62
|
+
}
|
63
|
+
],
|
64
|
+
"metadata": {
|
65
|
+
"pactSpecificationVersion": "1.0.0"
|
66
|
+
}
|
67
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require_relative 'pact_helper'
|
2
|
+
require 'zoo_app/animal_service_client'
|
3
|
+
|
4
|
+
module ZooApp
|
5
|
+
describe AnimalServiceClient do
|
6
|
+
|
7
|
+
include Pact::Consumer::Minitest
|
8
|
+
|
9
|
+
before do
|
10
|
+
AnimalServiceClient.base_uri animal_service.mock_service_base_url
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".find_alligator_by_name" do
|
14
|
+
describe "when an alligator by the given name exists" do
|
15
|
+
|
16
|
+
before do
|
17
|
+
animal_service.given("there is an alligator named Mary").
|
18
|
+
upon_receiving("a request for an alligator").with(
|
19
|
+
method: :get,
|
20
|
+
path: '/alligators/Mary',
|
21
|
+
headers: {'Accept' => 'application/json'} ).
|
22
|
+
will_respond_with(
|
23
|
+
status: 200,
|
24
|
+
headers: {'Content-Type' => 'application/json;charset=utf-8'},
|
25
|
+
body: {name: 'Mary'}
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns the alligator" do
|
30
|
+
assert_equal(AnimalServiceClient.find_alligator_by_name("Mary"), ZooApp::Animals::Alligator.new(name: 'Mary'))
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "when an alligator by the given name does not exist" do
|
36
|
+
|
37
|
+
before do
|
38
|
+
animal_service.given("there is not an alligator named Mary").
|
39
|
+
upon_receiving("a request for an alligator").with(
|
40
|
+
method: :get,
|
41
|
+
path: '/alligators/Mary',
|
42
|
+
headers: {'Accept' => 'application/json'} ).
|
43
|
+
will_respond_with(status: 404)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns nil" do
|
47
|
+
assert_equal(AnimalServiceClient.find_alligator_by_name("Mary"), nil)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "when an error occurs retrieving the alligator" do
|
53
|
+
|
54
|
+
before do
|
55
|
+
animal_service.given("an error occurs retrieving an alligator").
|
56
|
+
upon_receiving("a request for an alligator").with(
|
57
|
+
method: :get,
|
58
|
+
path: '/alligators/Mary',
|
59
|
+
headers: {'Accept' => 'application/json'}).
|
60
|
+
will_respond_with(
|
61
|
+
status: 500,
|
62
|
+
headers: { 'Content-Type' => 'application/json;charset=utf-8'},
|
63
|
+
body: {error: 'Argh!!!'})
|
64
|
+
end
|
65
|
+
|
66
|
+
it "raises an error" do
|
67
|
+
error = ->{ AnimalServiceClient.find_alligator_by_name("Mary") }.must_raise AnimalServiceError
|
68
|
+
error.message.must_match /Argh/
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require 'pact/consumer/minitest'
|
3
|
+
|
4
|
+
Pact.configure do | config |
|
5
|
+
config.doc_generator = :markdown
|
6
|
+
end
|
7
|
+
|
8
|
+
Pact.service_consumer 'Zoo App' do
|
9
|
+
has_pact_with "Animal Service" do
|
10
|
+
mock_service :animal_service do
|
11
|
+
port 1234
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "pact/consumer/minitest/version"
|
2
|
+
require 'pact/consumer'
|
3
|
+
require 'pact/consumer/spec_hooks'
|
4
|
+
|
5
|
+
module Pact
|
6
|
+
module Consumer
|
7
|
+
module Minitest
|
8
|
+
|
9
|
+
include Pact::Consumer::ConsumerContractBuilders
|
10
|
+
|
11
|
+
def pact_spec_hooks
|
12
|
+
@@pact_spec_hooks ||= Pact::Consumer::SpecHooks.new
|
13
|
+
end
|
14
|
+
|
15
|
+
module_function :pact_spec_hooks
|
16
|
+
|
17
|
+
def before_suite
|
18
|
+
unless defined?(@@before_suite_hook_ran) && @@before_suite_hook_ran
|
19
|
+
pact_spec_hooks.before_all
|
20
|
+
@@before_suite_hook_ran = true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def before_setup
|
25
|
+
super
|
26
|
+
before_suite
|
27
|
+
pact_spec_hooks.before_each self.class.name
|
28
|
+
end
|
29
|
+
|
30
|
+
def after_teardown
|
31
|
+
super
|
32
|
+
pact_spec_hooks.after_each self.class.name
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Minitest.after_run do
|
40
|
+
Pact::Consumer::Minitest.pact_spec_hooks.after_suite
|
41
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pact/consumer/minitest/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pact-consumer-minitest"
|
8
|
+
spec.version = Pact::Consumer::Minitest::VERSION
|
9
|
+
spec.authors = ["Beth Skurrie"]
|
10
|
+
spec.email = ["beth@bethesque.com"]
|
11
|
+
spec.summary = %q{Provides Minitest support for the Pact Consumer gem}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "pact", "~> 1.3"
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "minitest"
|
24
|
+
spec.add_development_dependency "mocha"
|
25
|
+
spec.add_development_dependency "httparty"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require './spec/support/client.rb'
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'minitest'
|
5
|
+
require 'pact/consumer/minitest'
|
6
|
+
|
7
|
+
Pact.service_consumer "My Service Consumer" do
|
8
|
+
has_pact_with "My Service Provider" do
|
9
|
+
mock_service :my_service_provider do
|
10
|
+
port 1234
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe MyServiceProviderClient do
|
16
|
+
|
17
|
+
include Pact::Consumer::Minitest
|
18
|
+
|
19
|
+
before do
|
20
|
+
MyServiceProviderClient.base_uri 'localhost:1234'
|
21
|
+
end
|
22
|
+
|
23
|
+
subject { MyServiceProviderClient.new }
|
24
|
+
|
25
|
+
describe "get_something" do
|
26
|
+
|
27
|
+
before do
|
28
|
+
my_service_provider.given("something exists").
|
29
|
+
upon_receiving("a request for something").with(method: :get, path: '/something', query: '').
|
30
|
+
will_respond_with(
|
31
|
+
status: 200,
|
32
|
+
headers: {'Content-Type' => 'application/json'},
|
33
|
+
body: {name: 'A small something'} )
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns a Something" do
|
37
|
+
assert_equal(subject.get_something, Something.new('A small something'))
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require './spec/support/client.rb'
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'minitest'
|
5
|
+
require 'pact/consumer/minitest'
|
6
|
+
|
7
|
+
Pact.service_consumer "My Other Service Consumer" do
|
8
|
+
has_pact_with "My Other Service Provider" do
|
9
|
+
mock_service :my_other_service_provider do
|
10
|
+
port 1235
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class MyOtherServiceProviderClientTest < Minitest::Test
|
16
|
+
|
17
|
+
include Pact::Consumer::Minitest
|
18
|
+
|
19
|
+
def setup
|
20
|
+
my_other_service_provider.given("something exists").
|
21
|
+
upon_receiving("a request for something").with(method: :get, path: '/something', query: '').
|
22
|
+
will_respond_with(
|
23
|
+
status: 200,
|
24
|
+
headers: {'Content-Type' => 'application/json'},
|
25
|
+
body: {name: 'A small something'} )
|
26
|
+
|
27
|
+
MyServiceProviderClient.base_uri 'localhost:1235'
|
28
|
+
@subject = MyServiceProviderClient.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_that_get_something_returns_something
|
32
|
+
assert_equal(@subject.get_something, Something.new('A small something'))
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require 'minitest'
|
3
|
+
require 'pact/consumer/minitest'
|
4
|
+
require 'mocha/mini_test'
|
5
|
+
require './spec/support/test'
|
6
|
+
|
7
|
+
describe Pact::Consumer::Minitest do
|
8
|
+
|
9
|
+
before do
|
10
|
+
pact_test.reset
|
11
|
+
pact_test.expects(:pact_spec_hooks).returns(spec_hooks).at_least_once
|
12
|
+
spec_hooks.stubs(:before_all)
|
13
|
+
spec_hooks.stubs(:before_each)
|
14
|
+
spec_hooks.stubs(:after_each)
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:spec_hooks) { Pact::Consumer::SpecHooks.new }
|
18
|
+
let(:pact_test) { TestTest.new }
|
19
|
+
|
20
|
+
describe "before_setup" do
|
21
|
+
|
22
|
+
it "ensures SpecHooks.before_all is only called once per suite" do
|
23
|
+
spec_hooks.expects(:before_all)
|
24
|
+
pact_test.before_setup
|
25
|
+
pact_test.before_setup
|
26
|
+
end
|
27
|
+
|
28
|
+
it "invokes SpecHooks.before_each" do
|
29
|
+
spec_hooks.expects(:before_each).with('TestTest')
|
30
|
+
pact_test.before_setup
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "after_teardown" do
|
36
|
+
it "invokes SpecHooks.after_each" do
|
37
|
+
spec_hooks.expects(:after_each).with('TestTest')
|
38
|
+
pact_test.after_teardown
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
{
|
2
|
+
"provider": {
|
3
|
+
"name": "My Other Service Provider"
|
4
|
+
},
|
5
|
+
"consumer": {
|
6
|
+
"name": "My Other Service Consumer"
|
7
|
+
},
|
8
|
+
"interactions": [
|
9
|
+
{
|
10
|
+
"description": "a request for something",
|
11
|
+
"provider_state": "something exists",
|
12
|
+
"request": {
|
13
|
+
"method": "get",
|
14
|
+
"path": "/something",
|
15
|
+
"query": ""
|
16
|
+
},
|
17
|
+
"response": {
|
18
|
+
"status": 200,
|
19
|
+
"headers": {
|
20
|
+
"Content-Type": "application/json"
|
21
|
+
},
|
22
|
+
"body": {
|
23
|
+
"name": "A small something"
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
],
|
28
|
+
"metadata": {
|
29
|
+
"pactSpecificationVersion": "1.0.0"
|
30
|
+
}
|
31
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
{
|
2
|
+
"provider": {
|
3
|
+
"name": "My Service Provider"
|
4
|
+
},
|
5
|
+
"consumer": {
|
6
|
+
"name": "My Service Consumer"
|
7
|
+
},
|
8
|
+
"interactions": [
|
9
|
+
{
|
10
|
+
"description": "a request for something",
|
11
|
+
"provider_state": "something exists",
|
12
|
+
"request": {
|
13
|
+
"method": "get",
|
14
|
+
"path": "/something",
|
15
|
+
"query": ""
|
16
|
+
},
|
17
|
+
"response": {
|
18
|
+
"status": 200,
|
19
|
+
"headers": {
|
20
|
+
"Content-Type": "application/json"
|
21
|
+
},
|
22
|
+
"body": {
|
23
|
+
"name": "A small something"
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
],
|
28
|
+
"metadata": {
|
29
|
+
"pactSpecificationVersion": "1.0.0"
|
30
|
+
}
|
31
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
class Something
|
4
|
+
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
def initialize name
|
8
|
+
@name = name
|
9
|
+
end
|
10
|
+
|
11
|
+
def == other
|
12
|
+
other.is_a?(Something) && other.name == name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class MyServiceProviderClient
|
17
|
+
|
18
|
+
include HTTParty
|
19
|
+
|
20
|
+
base_uri 'http://my-service'
|
21
|
+
|
22
|
+
def get_something
|
23
|
+
name = JSON.parse(self.class.get("/something").body)['name']
|
24
|
+
Something.new(name)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module BaseTest
|
2
|
+
|
3
|
+
# Need this to support the 'super' calls
|
4
|
+
def before_setup; end
|
5
|
+
def after_teardown; end
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
module Pact
|
10
|
+
module Consumer
|
11
|
+
module Minitest
|
12
|
+
def reset
|
13
|
+
# Dirty hack to clear @@before_suite_hook_ran flag
|
14
|
+
# for tests
|
15
|
+
@@before_suite_hook_ran = false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class TestTest
|
22
|
+
include BaseTest
|
23
|
+
include Pact::Consumer::Minitest
|
24
|
+
end
|
25
|
+
|
26
|
+
module Pact
|
27
|
+
module Consumer
|
28
|
+
class SpecHooks
|
29
|
+
def after_suite
|
30
|
+
# Override - will try and actually shutdown mock servers otherwise
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/tasks/test.rake
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
Rake::TestTask.new(:test) do |t|
|
4
|
+
t.pattern = "spec/lib/**/*_spec.rb"
|
5
|
+
end
|
6
|
+
|
7
|
+
Rake::TestTask.new (:integration) do |t|
|
8
|
+
t.pattern = "spec/integration/**/*.rb"
|
9
|
+
end
|
10
|
+
|
11
|
+
namespace :pact do
|
12
|
+
|
13
|
+
desc "Ensure pact file is written"
|
14
|
+
task 'test:pactfile' do
|
15
|
+
pact_path = './spec/pacts/my_service_consumer-my_service_provider.json'
|
16
|
+
FileUtils.rm_rf pact_path
|
17
|
+
Rake::Task['integration'].execute
|
18
|
+
fail "Did not find expected pact file at #{pact_path}" unless File.exist?(pact_path)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
task :default => [:test, :integration, :'pact:test:pactfile']
|
metadata
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pact-consumer-minitest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Beth Skurrie
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pact
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mocha
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: httparty
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- beth@bethesque.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- example/animal-service/Gemfile
|
124
|
+
- example/animal-service/Rakefile
|
125
|
+
- example/animal-service/config.ru
|
126
|
+
- example/animal-service/db/animal_db.sqlite3
|
127
|
+
- example/animal-service/lib/animal_service/animal_repository.rb
|
128
|
+
- example/animal-service/lib/animal_service/api.rb
|
129
|
+
- example/animal-service/lib/animal_service/db.rb
|
130
|
+
- example/animal-service/spec/service_consumers/pact_helper.rb
|
131
|
+
- example/animal-service/spec/service_consumers/provider_states_for_zoo_app.rb
|
132
|
+
- example/zoo-app/Gemfile
|
133
|
+
- example/zoo-app/Rakefile
|
134
|
+
- example/zoo-app/lib/zoo_app/animal_service_client.rb
|
135
|
+
- example/zoo-app/lib/zoo_app/models/alligator.rb
|
136
|
+
- example/zoo-app/spec/pacts/zoo_app-animal_service.json
|
137
|
+
- example/zoo-app/spec/service_providers/animal_service_client_spec.rb
|
138
|
+
- example/zoo-app/spec/service_providers/pact_helper.rb
|
139
|
+
- example/zoo-app/spec/spec_helper.rb
|
140
|
+
- lib/pact/consumer/minitest.rb
|
141
|
+
- lib/pact/consumer/minitest/version.rb
|
142
|
+
- pact-consumer-minitest.gemspec
|
143
|
+
- spec/integration/minitest_spec.rb
|
144
|
+
- spec/integration/minitest_unit.rb
|
145
|
+
- spec/lib/pact/consumer/minitest_spec.rb
|
146
|
+
- spec/pacts/my_other_service_consumer-my_other_service_provider.json
|
147
|
+
- spec/pacts/my_service_consumer-my_service_provider.json
|
148
|
+
- spec/support/client.rb
|
149
|
+
- spec/support/test.rb
|
150
|
+
- tasks/test.rake
|
151
|
+
homepage: ''
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata: {}
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ! '>='
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ! '>='
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 2.1.11
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: Provides Minitest support for the Pact Consumer gem
|
175
|
+
test_files:
|
176
|
+
- spec/integration/minitest_spec.rb
|
177
|
+
- spec/integration/minitest_unit.rb
|
178
|
+
- spec/lib/pact/consumer/minitest_spec.rb
|
179
|
+
- spec/pacts/my_other_service_consumer-my_other_service_provider.json
|
180
|
+
- spec/pacts/my_service_consumer-my_service_provider.json
|
181
|
+
- spec/support/client.rb
|
182
|
+
- spec/support/test.rb
|
183
|
+
has_rdoc:
|