pact 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +36 -24
- data/lib/pact/configuration.rb +2 -0
- data/lib/pact/pact_task_helper.rb +8 -0
- data/lib/pact/provider.rb +4 -1
- data/lib/pact/provider/client_project_pact_helper.rb +2 -0
- data/lib/pact/provider/dsl.rb +44 -1
- data/lib/pact/provider/matchers.rb +1 -0
- data/lib/pact/provider/pact_helper_locator.rb +22 -0
- data/lib/pact/provider/pact_spec_runner.rb +2 -16
- data/lib/pact/provider/pact_verification.rb +17 -0
- data/lib/pact/verification_task.rb +10 -8
- data/lib/pact/version.rb +1 -1
- data/lib/tasks/pact.rake +25 -11
- data/spec/lib/pact/provider/dsl_spec.rb +77 -0
- data/spec/lib/pact/provider/pact_helper_locator_spec.rb +54 -0
- data/spec/lib/pact/provider/pact_spec_runner_spec.rb +0 -38
- data/spec/lib/pact/verification_task_spec.rb +1 -0
- data/spec/support/pact_helper.rb +5 -0
- data/tasks/pact-test.rake +26 -1
- metadata +7 -2
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
### 1.0.6 (11 September 2012)
|
2
|
+
|
3
|
+
* Made reports dir configurable [Beth Skurrie]
|
4
|
+
* Changed the way the pact files are configured. They are now in the Pact.service_provider block in the pact_helper file. Require 'pact/tasks' in the Rakefile and run 'rake pact:verify' instead of setting up custom tasks. [Beth Skurrie]
|
5
|
+
|
1
6
|
### 1.0.5 (6 September 2013)
|
2
7
|
|
3
8
|
* Added verification reports when running rake pact:verify:xxx [Latheesh Padukana, Beth Skurrie]
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -115,16 +115,23 @@ end
|
|
115
115
|
|
116
116
|
### Service Provider project
|
117
117
|
|
118
|
-
#### Configure your service provider
|
118
|
+
#### Configure your service provider
|
119
119
|
|
120
|
-
Create a `pact_helper.rb` in your service provider project. The file must be called pact_helper.rb
|
120
|
+
Create a `pact_helper.rb` in your service provider project. The file must be called pact_helper.rb, however there is some flexibility in where it can be stored. The recommended place is `specs/service_providers/pact_helper.rb`.
|
121
121
|
|
122
122
|
```ruby
|
123
|
-
require '
|
124
|
-
require 'provider_states_for_my_consumer' #See next section on setting up provider states
|
123
|
+
require 'my_app' # Require the boot files for your app
|
124
|
+
require 'provider_states_for_my_consumer' # See next section on setting up provider states
|
125
125
|
|
126
126
|
Pact.service_provider "My Provider" do
|
127
127
|
app { MyApp.new }
|
128
|
+
|
129
|
+
honours_pact_with 'My Consumer' do
|
130
|
+
# This example points to a local file, however, on a real project with a continuous
|
131
|
+
# integration box, you could publish your pacts as artifacts,
|
132
|
+
# and point this to the pact published by the last successful build.
|
133
|
+
pact_uri '../path-to-your-consumer-project/specs/pacts/my_consumer-my_provider.json'
|
134
|
+
end
|
128
135
|
end
|
129
136
|
|
130
137
|
```
|
@@ -150,7 +157,6 @@ my_service.
|
|
150
157
|
```
|
151
158
|
|
152
159
|
To define service provider states that create the right data for "a thing exists" and "a thing does not exist", write the following in the service provider project.
|
153
|
-
Note that these states have been defined only for the 'My Consumer' consumer by using the Pact.provider_states_for block.
|
154
160
|
|
155
161
|
|
156
162
|
```ruby
|
@@ -180,35 +186,41 @@ end
|
|
180
186
|
|
181
187
|
If a state should be used for all consumers, the top level Pact.with_consumer can be skipped, and a global Pact.provider_state can be defined on its own.
|
182
188
|
|
183
|
-
####
|
184
|
-
|
185
|
-
You'll need to create one or more pact:verify:xxx tasks, that allow the currently checked out service provider to be tested against other versions of its consumers - most importantly, head and production.
|
186
|
-
|
187
|
-
Here is an example pact:verify:head task, pointing the the pact file for "some_consumer", found in the build artifacts of the latest successful build of "MY-CONSUMER" project.
|
189
|
+
#### Verify that the service provider honours the pact
|
188
190
|
|
189
191
|
```ruby
|
190
|
-
|
191
|
-
|
192
|
-
end
|
192
|
+
#In your Rakefile
|
193
|
+
require 'pact/tasks'
|
193
194
|
```
|
194
195
|
|
195
|
-
```
|
196
|
-
|
197
|
-
|
198
|
-
pact
|
199
|
-
|
196
|
+
```
|
197
|
+
$ rake -T
|
198
|
+
rake pact:verify # Verifies the pact files configured in the pact_helper.rb against this service provider.
|
199
|
+
rake pact:verify:at[pact_uri] # Verifies the pact at the given URI against this service provider.
|
200
|
+
$ rake pact:verify
|
200
201
|
```
|
201
202
|
|
202
|
-
|
203
|
+
#### Verification using arbitrary pact files
|
203
204
|
|
204
|
-
|
205
|
+
```
|
206
|
+
# Local URI
|
207
|
+
$ rake pact:verify:at[../path-to-your-consumer-project/specs/pacts/my_consumer-my_provider.json]
|
205
208
|
|
206
|
-
|
209
|
+
# Remote URI
|
210
|
+
$ rake pact:verify:at[http://build-box/MyConsumerBuild/latestSuccessful/artifacts/my_consumer-my_provider.json]
|
211
|
+
```
|
207
212
|
|
208
|
-
|
213
|
+
To make a shortcut task for pact at an arbitrary URI, add the following to your Rakefile.
|
209
214
|
|
210
|
-
|
211
|
-
|
215
|
+
```ruby
|
216
|
+
# This creates a rake task that can be executed by running
|
217
|
+
# $rake pact:verify:dev
|
218
|
+
Pact::VerificationTask.new(:dev) do | pact |
|
219
|
+
pact.uri '../path-to-your-consumer-project/specs/pacts/my_consumer-my_provider.json'
|
220
|
+
end
|
221
|
+
```
|
222
|
+
|
223
|
+
The pact.uri may be a local file system path or a remote URL.
|
212
224
|
|
213
225
|
|
214
226
|
### Running a standalone mock server
|
data/lib/pact/configuration.rb
CHANGED
@@ -9,6 +9,7 @@ module Pact
|
|
9
9
|
attr_accessor :logger
|
10
10
|
attr_accessor :tmp_dir
|
11
11
|
attr_accessor :pactfile_write_mode
|
12
|
+
attr_accessor :reports_dir
|
12
13
|
|
13
14
|
def log_path
|
14
15
|
log_dir + "/pact_gem.log"
|
@@ -37,6 +38,7 @@ module Pact
|
|
37
38
|
c.log_dir = default_log_dir
|
38
39
|
c.logger = default_logger c.log_path
|
39
40
|
c.pactfile_write_mode = is_rake_running? ? :overwrite : :update
|
41
|
+
c.reports_dir = File.expand_path('./reports/pacts')
|
40
42
|
c
|
41
43
|
end
|
42
44
|
|
data/lib/pact/provider.rb
CHANGED
data/lib/pact/provider/dsl.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative 'pact_verification'
|
2
|
+
|
1
3
|
module Pact
|
2
4
|
|
3
5
|
module Provider
|
@@ -15,7 +17,14 @@ module Pact
|
|
15
17
|
else
|
16
18
|
raise "Please configure your provider. See the Provider section in the README for examples."
|
17
19
|
end
|
18
|
-
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_pact_verification verification
|
23
|
+
pact_verifications << verification
|
24
|
+
end
|
25
|
+
def pact_verifications
|
26
|
+
@pact_verifications ||= []
|
27
|
+
end
|
19
28
|
end
|
20
29
|
|
21
30
|
Pact::Configuration.send(:include, Configuration)
|
@@ -39,6 +48,35 @@ module Pact
|
|
39
48
|
end
|
40
49
|
end
|
41
50
|
|
51
|
+
class VerificationDSL
|
52
|
+
def initialize consumer_name, options = {}, &block
|
53
|
+
@consumer_name = consumer_name
|
54
|
+
@ref = options.fetch(:ref, :head)
|
55
|
+
@pact_uri = nil
|
56
|
+
instance_eval(&block)
|
57
|
+
end
|
58
|
+
|
59
|
+
def pact_uri pact_uri, options = {}
|
60
|
+
@pact_uri = pact_uri
|
61
|
+
end
|
62
|
+
|
63
|
+
def task task
|
64
|
+
@task = task
|
65
|
+
end
|
66
|
+
|
67
|
+
def create_verification
|
68
|
+
validate
|
69
|
+
Pact::Provider::PactVerification.new(@consumer_name, @pact_uri, @ref)
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def validate
|
75
|
+
raise "Please provide a pact_uri for the verification" unless @pact_uri
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
42
80
|
class ServiceProviderDSL
|
43
81
|
|
44
82
|
def initialize name, &block
|
@@ -60,6 +98,11 @@ module Pact
|
|
60
98
|
@app_block = block
|
61
99
|
end
|
62
100
|
|
101
|
+
def honours_pact_with consumer_name, options = {}, &app_block
|
102
|
+
verification = VerificationDSL.new(consumer_name, options, &app_block).create_verification
|
103
|
+
Pact.configuration.add_pact_verification verification
|
104
|
+
end
|
105
|
+
|
63
106
|
def create_service_provider
|
64
107
|
validate
|
65
108
|
ServiceProviderConfig.new(@name, &@app_block)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Pact
|
2
|
+
module Provider
|
3
|
+
module PactHelperLocater
|
4
|
+
PACT_HELPER_FILE_PATTERNS = [
|
5
|
+
"spec/**/*service*consumer*/pact_helper.rb",
|
6
|
+
"spec/**/*consumer*/pact_helper.rb",
|
7
|
+
"spec/**/pact_helper.rb",
|
8
|
+
"**/pact_helper.rb"]
|
9
|
+
|
10
|
+
NO_PACT_HELPER_FOUND_MSG = "Please create a pact_helper.rb file that can be found using one of the following patterns: #{PACT_HELPER_FILE_PATTERNS.join(", ")}"
|
11
|
+
|
12
|
+
def self.pact_helper_path
|
13
|
+
pact_helper_search_results = []
|
14
|
+
PACT_HELPER_FILE_PATTERNS.find { | pattern | (pact_helper_search_results.concat(Dir.glob(pattern))).any? }
|
15
|
+
raise NO_PACT_HELPER_FOUND_MSG if pact_helper_search_results.empty?
|
16
|
+
"#{Dir.pwd}/#{pact_helper_search_results[0]}"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -16,14 +16,6 @@ module Pact
|
|
16
16
|
attr_reader :options
|
17
17
|
attr_reader :output
|
18
18
|
|
19
|
-
PACT_HELPER_FILE_PATTERNS = [
|
20
|
-
"spec/**/*service*consumer*/pact_helper.rb",
|
21
|
-
"spec/**/*consumer*/pact_helper.rb",
|
22
|
-
"spec/**/pact_helper.rb",
|
23
|
-
"**/pact_helper.rb"]
|
24
|
-
|
25
|
-
NO_PACT_HELPER_FOUND_MSG = "Please create a pact_helper.rb file that can be found using one of the following patterns: #{PACT_HELPER_FILE_PATTERNS.join(", ")}"
|
26
|
-
|
27
19
|
def initialize spec_definitions, options = {}
|
28
20
|
@spec_definitions = spec_definitions
|
29
21
|
@options = options
|
@@ -40,19 +32,13 @@ module Pact
|
|
40
32
|
|
41
33
|
def require_pact_helper spec_definition
|
42
34
|
if spec_definition[:support_file]
|
35
|
+
$stderr.puts "Specifying a support_file is deprecated. Please create a pact_helper.rb instead."
|
43
36
|
require spec_definition[:support_file]
|
44
37
|
else
|
45
|
-
require
|
38
|
+
require 'pact/provider/client_project_pact_helper'
|
46
39
|
end
|
47
40
|
end
|
48
41
|
|
49
|
-
def pact_helper_file
|
50
|
-
pact_helper_search_results = []
|
51
|
-
PACT_HELPER_FILE_PATTERNS.find { | pattern | (pact_helper_search_results.concat(Dir.glob(pattern))).any? }
|
52
|
-
raise NO_PACT_HELPER_FOUND_MSG if pact_helper_search_results.empty?
|
53
|
-
"#{Dir.pwd}/#{pact_helper_search_results[0]}"
|
54
|
-
end
|
55
|
-
|
56
42
|
def initialize_specs
|
57
43
|
spec_definitions.each do | spec_definition |
|
58
44
|
require_pact_helper spec_definition
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Pact::Provider
|
2
|
+
class PactVerification
|
3
|
+
attr_reader :consumer_name, :uri, :ref
|
4
|
+
def initialize consumer_name, uri, ref
|
5
|
+
@consumer_name = consumer_name
|
6
|
+
@uri = uri
|
7
|
+
@ref = ref
|
8
|
+
end
|
9
|
+
|
10
|
+
def == other
|
11
|
+
other.is_a?(PactVerification) &&
|
12
|
+
consumer_name == other.consumer_name &&
|
13
|
+
uri == other.uri &&
|
14
|
+
ref == other.ref
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -38,7 +38,7 @@ module Pact
|
|
38
38
|
@pact_spec_config = []
|
39
39
|
@name = name
|
40
40
|
yield self
|
41
|
-
|
41
|
+
rake_task
|
42
42
|
end
|
43
43
|
|
44
44
|
def uri(uri, options = {})
|
@@ -53,21 +53,21 @@ module Pact
|
|
53
53
|
Pact::ConsumerContract.from_uri config[:uri]
|
54
54
|
end
|
55
55
|
|
56
|
-
def publish_report config, output, result
|
56
|
+
def publish_report config, output, result, provider_ref, reports_dir
|
57
57
|
consumer_contract = parse_pactfile config
|
58
58
|
#TODO - when checking out a historical version, provider ref will be prod, however it will think it is head. Fix this!!!!
|
59
59
|
report = Provider::VerificationReport.new(
|
60
60
|
:result => result,
|
61
61
|
:output => output,
|
62
62
|
:consumer => {:name => consumer_contract.consumer.name, :ref => name},
|
63
|
-
:provider => {:name => consumer_contract.provider.name, :ref =>
|
63
|
+
:provider => {:name => consumer_contract.provider.name, :ref => provider_ref}
|
64
64
|
)
|
65
65
|
|
66
|
-
FileUtils.mkdir_p
|
67
|
-
File.open("
|
66
|
+
FileUtils.mkdir_p reports_dir
|
67
|
+
File.open("#{reports_dir}/#{report.report_file_name}", "w") { |file| file << JSON.pretty_generate(report) }
|
68
68
|
end
|
69
69
|
|
70
|
-
def
|
70
|
+
def rake_task
|
71
71
|
namespace :pact do
|
72
72
|
desc "Verify provider against the consumer pacts for #{name}"
|
73
73
|
task "verify:#{name}" do
|
@@ -76,11 +76,13 @@ module Pact
|
|
76
76
|
#TODO: Change this to accept the ConsumerContract that is already parsed, so we don't make the same request twice
|
77
77
|
pact_spec_runner = Provider::PactSpecRunner.new([config])
|
78
78
|
exit_status = pact_spec_runner.run
|
79
|
-
publish_report config, pact_spec_runner.output, exit_status == 0
|
79
|
+
publish_report config, pact_spec_runner.output, exit_status == 0, 'head', Pact.configuration.reports_dir
|
80
80
|
exit_status
|
81
81
|
end
|
82
82
|
|
83
|
-
|
83
|
+
handle_verification_failure do
|
84
|
+
exit_statuses.count{ | status | status != 0 }
|
85
|
+
end
|
84
86
|
end
|
85
87
|
end
|
86
88
|
end
|
data/lib/pact/version.rb
CHANGED
data/lib/tasks/pact.rake
CHANGED
@@ -1,17 +1,31 @@
|
|
1
|
-
require 'pact'
|
2
|
-
require 'pact/pact_task_helper'
|
3
|
-
|
4
1
|
|
5
2
|
namespace :pact do
|
6
3
|
|
7
|
-
|
4
|
+
desc "Verifies the pact files configured in the pact_helper.rb against this service provider."
|
5
|
+
task :verify do
|
6
|
+
require 'pact/provider'
|
7
|
+
require 'pact/pact_task_helper'
|
8
|
+
|
9
|
+
include PactTaskHelper
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
exit_status = Pact::Provider::PactSpecRunner.run([pact_spec_config])
|
15
|
-
fail failure_message if exit_status != 0
|
11
|
+
handle_verification_failure do
|
12
|
+
pact_verifications = Pact.configuration.pact_verifications
|
13
|
+
verification_configs = pact_verifications.collect { | pact_verification | { :uri => pact_verification.uri }}
|
14
|
+
Pact::Provider::PactSpecRunner.new(verification_configs).run
|
15
|
+
end
|
16
16
|
end
|
17
|
+
|
18
|
+
desc "Verifies the pact at the given URI against this service provider."
|
19
|
+
task 'verify:at', :pact_uri do | t, args |
|
20
|
+
require 'pact/provider'
|
21
|
+
require 'pact/pact_task_helper'
|
22
|
+
|
23
|
+
include PactTaskHelper
|
24
|
+
|
25
|
+
handle_verification_failure do
|
26
|
+
puts "Verifying pact at uri #{args[:pact_uri]}"
|
27
|
+
Pact::Provider::PactSpecRunner.new([{uri: args[:pact_uri]}]).run
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
17
31
|
end
|
@@ -39,6 +39,47 @@ module Pact::Provider
|
|
39
39
|
|
40
40
|
module DSL
|
41
41
|
|
42
|
+
describe VerificationDSL do
|
43
|
+
|
44
|
+
|
45
|
+
describe 'create_verification' do
|
46
|
+
let(:url) {'http://some/uri'}
|
47
|
+
let(:consumer_name) {'some consumer'}
|
48
|
+
let(:ref) {:prod}
|
49
|
+
let(:options) { {:ref => :prod} }
|
50
|
+
context "with valid values" do
|
51
|
+
subject do
|
52
|
+
uri = url
|
53
|
+
VerificationDSL.new(consumer_name, options) do
|
54
|
+
pact_uri uri
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "creates a Verification" do
|
59
|
+
Pact::Provider::PactVerification.should_receive(:new).with(consumer_name, url, ref)
|
60
|
+
subject.create_verification
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns a Verification" do
|
64
|
+
Pact::Provider::PactVerification.should_receive(:new).and_return('a verification')
|
65
|
+
expect(subject.create_verification).to eq('a verification')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "with a nil uri" do
|
70
|
+
subject do
|
71
|
+
VerificationDSL.new(consumer_name, options) do
|
72
|
+
pact_uri nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "raises a validation error" do
|
77
|
+
expect{ subject.create_verification}.to raise_error /Please provide a pact_uri/
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
42
83
|
describe ServiceProviderDSL do
|
43
84
|
|
44
85
|
describe "initialize" do
|
@@ -86,6 +127,42 @@ module Pact::Provider
|
|
86
127
|
end
|
87
128
|
end
|
88
129
|
end
|
130
|
+
|
131
|
+
describe 'honours_pact_with' do
|
132
|
+
before do
|
133
|
+
Pact.clear_configuration
|
134
|
+
end
|
135
|
+
|
136
|
+
context "with no optional params" do
|
137
|
+
subject do
|
138
|
+
ServiceProviderDSL.new '' do
|
139
|
+
honours_pact_with 'some-consumer' do
|
140
|
+
pact_uri 'blah'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
it 'adds a verification to the Pact.configuration' do
|
145
|
+
subject
|
146
|
+
expect(Pact.configuration.pact_verifications.first).to eq(Pact::Provider::PactVerification.new('some-consumer', 'blah', :head))
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "with all params specified" do
|
151
|
+
subject do
|
152
|
+
ServiceProviderDSL.new '' do
|
153
|
+
honours_pact_with 'some-consumer', :ref => :prod do
|
154
|
+
pact_uri 'blah'
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
it 'adds a verification to the Pact.configuration' do
|
159
|
+
subject
|
160
|
+
expect(Pact.configuration.pact_verifications.first).to eq(Pact::Provider::PactVerification.new('some-consumer', 'blah', :prod))
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
89
166
|
end
|
90
167
|
|
91
168
|
describe ServiceProviderConfig do
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pact/provider/pact_helper_locator'
|
3
|
+
|
4
|
+
module Pact::Provider
|
5
|
+
|
6
|
+
describe PactHelperLocater do
|
7
|
+
describe "pact_helper_path", :fakefs => true do
|
8
|
+
|
9
|
+
subject { PactHelperLocater.pact_helper_path }
|
10
|
+
|
11
|
+
def make_pactfile dir
|
12
|
+
FileUtils.mkdir_p ".#{dir}"
|
13
|
+
FileUtils.touch ".#{dir}/pact_helper.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
PACT_HELPER_FILE_DIRS = [
|
17
|
+
'/spec/blah/service-consumers',
|
18
|
+
'/spec/consumers',
|
19
|
+
'/spec/blah/service_consumers',
|
20
|
+
'/spec/serviceconsumers',
|
21
|
+
'/spec/consumer',
|
22
|
+
'/spec',
|
23
|
+
'/blah',
|
24
|
+
'/blah/consumer',
|
25
|
+
''
|
26
|
+
]
|
27
|
+
|
28
|
+
PACT_HELPER_FILE_DIRS.each do | dir |
|
29
|
+
context "the pact_helper is stored in #{dir}" do
|
30
|
+
it "finds the pact_helper" do
|
31
|
+
make_pactfile dir
|
32
|
+
expect(subject).to eq "#{Dir.pwd}#{dir}/pact_helper.rb"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when more than one pact_helper exists" do
|
38
|
+
it "returns the one that matches the most explict search pattern" do
|
39
|
+
make_pactfile '/spec/consumer'
|
40
|
+
FileUtils.touch 'pact_helper.rb'
|
41
|
+
expect(subject).to eq "#{Dir.pwd}/spec/consumer/pact_helper.rb"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when a file exists ending in pact_helper.rb" do
|
46
|
+
it "is not identifed as a pact helper" do
|
47
|
+
FileUtils.mkdir_p './spec'
|
48
|
+
FileUtils.touch './spec/not_pact_helper.rb'
|
49
|
+
expect { subject }.to raise_error /Please create a pact_helper.rb file/
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -3,43 +3,5 @@ require 'pact/provider/pact_spec_runner'
|
|
3
3
|
|
4
4
|
module Pact::Provider
|
5
5
|
describe PactSpecRunner do
|
6
|
-
describe "pact_helper_file", :fakefs => true do
|
7
|
-
|
8
|
-
subject { PactSpecRunner.new({}).send(:pact_helper_file) }
|
9
|
-
|
10
|
-
def make_pactfile dir
|
11
|
-
FileUtils.mkdir_p ".#{dir}"
|
12
|
-
FileUtils.touch ".#{dir}/pact_helper.rb"
|
13
|
-
end
|
14
|
-
|
15
|
-
PACT_HELPER_FILE_DIRS = [
|
16
|
-
'/spec/blah/service-consumers',
|
17
|
-
'/spec/consumers',
|
18
|
-
'/spec/blah/service_consumers',
|
19
|
-
'/spec/serviceconsumers',
|
20
|
-
'/spec/consumer',
|
21
|
-
'/spec',
|
22
|
-
'/blah',
|
23
|
-
'/blah/consumer',
|
24
|
-
''
|
25
|
-
]
|
26
|
-
|
27
|
-
PACT_HELPER_FILE_DIRS.each do | dir |
|
28
|
-
context "the pact_helper is stored in #{dir}" do
|
29
|
-
it "finds the pact_helper" do
|
30
|
-
make_pactfile dir
|
31
|
-
expect(subject).to eq "#{Dir.pwd}#{dir}/pact_helper.rb"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "when more than one pact_helper exists" do
|
37
|
-
it "returns the one that matches the most explict search pattern" do
|
38
|
-
make_pactfile '/spec/consumer'
|
39
|
-
FileUtils.touch 'pact_helper.rb'
|
40
|
-
expect(subject).to eq "#{Dir.pwd}/spec/consumer/pact_helper.rb"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
6
|
end
|
45
7
|
end
|
data/spec/support/pact_helper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'pact/provider/rspec'
|
2
3
|
# pact_helper for rake pact:tests
|
3
4
|
|
4
5
|
module Pact
|
@@ -15,6 +16,10 @@ module Pact
|
|
15
16
|
|
16
17
|
Pact.service_provider "Some Provider" do
|
17
18
|
app { TestApp.new }
|
19
|
+
|
20
|
+
honours_pact_with 'some-test-consumer' do
|
21
|
+
pact_uri './spec/support/test_app_pass.json'
|
22
|
+
end
|
18
23
|
end
|
19
24
|
|
20
25
|
|
data/tasks/pact-test.rake
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
require './lib/pact/provider/pact_spec_runner'
|
2
1
|
|
3
2
|
namespace :pact do
|
4
3
|
|
5
4
|
desc 'Runs pact tests against a sample application, testing failure and success.'
|
6
5
|
task :tests do
|
6
|
+
|
7
|
+
require 'pact/provider/pact_spec_runner'
|
8
|
+
require 'open3'
|
9
|
+
|
7
10
|
silent = true
|
8
11
|
puts "Running task pact:tests"
|
9
12
|
# Run these specs silently, otherwise expected failures will be written to stdout and look like unexpected failures.
|
@@ -14,7 +17,29 @@ namespace :pact do
|
|
14
17
|
result = Pact::Provider::PactSpecRunner.new([{ uri: './spec/support/test_app_fail.json', support_file: './spec/support/pact_helper.rb' }], silent: silent).run
|
15
18
|
fail 'Expected pact to fail' if (result == 0)
|
16
19
|
|
20
|
+
expect_to_pass "bundle exec rake pact:verify"
|
21
|
+
expect_to_pass "bundle exec rake pact:verify:at[./spec/support/test_app_pass.json]"
|
22
|
+
expect_to_fail "bundle exec rake pact:verify:at[./spec/support/test_app_fail.json]"
|
23
|
+
|
17
24
|
puts "Task pact:tests completed succesfully."
|
18
25
|
end
|
19
26
|
|
27
|
+
def expect_to_fail command
|
28
|
+
success = execute_command command
|
29
|
+
fail "Expected '#{command}' to fail" if success
|
30
|
+
end
|
31
|
+
|
32
|
+
def expect_to_pass command
|
33
|
+
success = execute_command command
|
34
|
+
fail "Expected '#{command}' to pass" unless success
|
35
|
+
end
|
36
|
+
|
37
|
+
def execute_command command
|
38
|
+
result = nil
|
39
|
+
Open3.popen3(command) {|stdin, stdout, stderr, wait_thr|
|
40
|
+
result = wait_thr.value
|
41
|
+
}
|
42
|
+
result.success?
|
43
|
+
end
|
44
|
+
|
20
45
|
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.0.
|
4
|
+
version: 1.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2013-09-
|
16
|
+
date: 2013-09-17 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: randexp
|
@@ -293,9 +293,12 @@ files:
|
|
293
293
|
- lib/pact/matchers/matchers.rb
|
294
294
|
- lib/pact/pact_task_helper.rb
|
295
295
|
- lib/pact/provider.rb
|
296
|
+
- lib/pact/provider/client_project_pact_helper.rb
|
296
297
|
- lib/pact/provider/dsl.rb
|
297
298
|
- lib/pact/provider/matchers.rb
|
299
|
+
- lib/pact/provider/pact_helper_locator.rb
|
298
300
|
- lib/pact/provider/pact_spec_runner.rb
|
301
|
+
- lib/pact/provider/pact_verification.rb
|
299
302
|
- lib/pact/provider/provider_state.rb
|
300
303
|
- lib/pact/provider/rspec.rb
|
301
304
|
- lib/pact/provider/test_methods.rb
|
@@ -326,6 +329,7 @@ files:
|
|
326
329
|
- spec/lib/pact/consumer_contract/interaction_spec.rb
|
327
330
|
- spec/lib/pact/matchers/matchers_spec.rb
|
328
331
|
- spec/lib/pact/provider/dsl_spec.rb
|
332
|
+
- spec/lib/pact/provider/pact_helper_locator_spec.rb
|
329
333
|
- spec/lib/pact/provider/pact_spec_runner_spec.rb
|
330
334
|
- spec/lib/pact/provider/provider_state_spec.rb
|
331
335
|
- spec/lib/pact/provider/rspec_spec.rb
|
@@ -386,6 +390,7 @@ test_files:
|
|
386
390
|
- spec/lib/pact/consumer_contract/interaction_spec.rb
|
387
391
|
- spec/lib/pact/matchers/matchers_spec.rb
|
388
392
|
- spec/lib/pact/provider/dsl_spec.rb
|
393
|
+
- spec/lib/pact/provider/pact_helper_locator_spec.rb
|
389
394
|
- spec/lib/pact/provider/pact_spec_runner_spec.rb
|
390
395
|
- spec/lib/pact/provider/provider_state_spec.rb
|
391
396
|
- spec/lib/pact/provider/rspec_spec.rb
|