pact 1.0.3 → 1.0.4
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.
- data/CHANGELOG.md +4 -1
- data/Gemfile.lock +1 -1
- data/README.md +6 -5
- data/lib/pact/tasks.rb +2 -0
- data/lib/pact/verification_task.rb +8 -3
- data/lib/pact/version.rb +1 -1
- data/lib/tasks/pact.rake +5 -5
- metadata +3 -3
- data/lib/pact/rake_task.rb +0 -64
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -117,9 +117,12 @@ end
|
|
117
117
|
|
118
118
|
#### Configure your service provider rack app
|
119
119
|
|
120
|
-
Create a `pact_helper.rb` in your service provider project. The file must be called pact_helper.rb so the verification tasks can find it, however there is some flexibility in where it can be stored. The recommended place is `specs/service_providers/pact_helper.rb`.
|
120
|
+
Create a `pact_helper.rb` in your service provider project. The file must be called pact_helper.rb so the built in verification tasks can find it, 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 'spec_helper'
|
124
|
+
require 'provider_states_for_my_consumer' #See next section on setting up provider states
|
125
|
+
|
123
126
|
Pact.service_provider "My Provider" do
|
124
127
|
app { MyApp.new }
|
125
128
|
end
|
@@ -185,16 +188,14 @@ Here is an example pact:verify:head task, pointing the the pact file for "some_c
|
|
185
188
|
|
186
189
|
```ruby
|
187
190
|
Pact::VerificationTask.new(:head) do | pact |
|
188
|
-
pact.uri 'http://our_build_server/MY-CONSUMER-BUILD/latestSuccessful/artifact/Pacts/some_consumer-this_service provider.json'
|
189
|
-
support_file: './spec/consumers/pact_helper'
|
191
|
+
pact.uri 'http://our_build_server/MY-CONSUMER-BUILD/latestSuccessful/artifact/Pacts/some_consumer-this_service provider.json'
|
190
192
|
end
|
191
193
|
```
|
192
194
|
|
193
195
|
```ruby
|
194
196
|
# Ideally we'd like to be able to create a production task like this, but firewalls are making this tricky right now.
|
195
197
|
Pact::VerificationTask.new(:production) do | pact |
|
196
|
-
pact.uri 'http://our_prod_server/pacts/some_consumer-this_service_provider.json'
|
197
|
-
support_file: './spec/consumers/pact_helper'
|
198
|
+
pact.uri 'http://our_prod_server/pacts/some_consumer-this_service_provider.json'
|
198
199
|
end
|
199
200
|
```
|
200
201
|
|
data/lib/pact/tasks.rb
ADDED
@@ -11,15 +11,20 @@ require_relative 'pact_task_helper'
|
|
11
11
|
end
|
12
12
|
|
13
13
|
The pact.uri may be a local file system path or a remote URL.
|
14
|
-
|
14
|
+
|
15
|
+
To run a pact:verify:xxx task you need to define a pact_helper.rb, ideally in spec/service_consumers.
|
16
|
+
It should contain your service_provider definition, and load any provider state definition files.
|
17
|
+
It should also load all your app's dependencies (eg by calling out to spec_helper)
|
18
|
+
|
15
19
|
Eg.
|
16
20
|
|
21
|
+
require 'spec_helper'
|
22
|
+
require 'provider_states_for_my_consumer'
|
23
|
+
|
17
24
|
Pact.service_provider "My Provider" do
|
18
25
|
app { TestApp.new }
|
19
26
|
end
|
20
27
|
|
21
|
-
It should also load all your app's dependencies (eg by calling out to spec_helper)
|
22
|
-
|
23
28
|
=end
|
24
29
|
|
25
30
|
|
data/lib/pact/version.rb
CHANGED
data/lib/tasks/pact.rake
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'pact'
|
2
2
|
require 'pact/pact_task_helper'
|
3
3
|
|
4
|
-
|
4
|
+
|
5
5
|
namespace :pact do
|
6
6
|
|
7
|
+
include PactTaskHelper
|
8
|
+
|
7
9
|
desc "Runs the specified pact file against the service provider"
|
8
|
-
task :verify, :pact_uri
|
9
|
-
puts 'BLSH'
|
10
|
+
task :verify, :pact_uri do | t, args |
|
10
11
|
require 'pact/provider/pact_spec_runner'
|
11
12
|
puts "Using pact at uri #{args[:pact_uri]}"
|
12
|
-
|
13
|
-
pact_spec_config = {uri: args[:pact_uri], support_file: args[:support_file]}
|
13
|
+
pact_spec_config = {uri: args[:pact_uri]}
|
14
14
|
exit_status = Pact::Provider::PactSpecRunner.run([pact_spec_config])
|
15
15
|
fail failure_message if exit_status != 0
|
16
16
|
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.4
|
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-15 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: randexp
|
@@ -299,9 +299,9 @@ files:
|
|
299
299
|
- lib/pact/provider/provider_state.rb
|
300
300
|
- lib/pact/provider/rspec.rb
|
301
301
|
- lib/pact/provider/test_methods.rb
|
302
|
-
- lib/pact/rake_task.rb
|
303
302
|
- lib/pact/reification.rb
|
304
303
|
- lib/pact/request.rb
|
304
|
+
- lib/pact/tasks.rb
|
305
305
|
- lib/pact/term.rb
|
306
306
|
- lib/pact/verification_task.rb
|
307
307
|
- lib/pact/version.rb
|
data/lib/pact/rake_task.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'rake/tasklib'
|
2
|
-
|
3
|
-
|
4
|
-
module Pact
|
5
|
-
|
6
|
-
##
|
7
|
-
# To enable `rake pact`, put something like this in your Rakefile:
|
8
|
-
#
|
9
|
-
# ```
|
10
|
-
# require 'pact/rake_task'
|
11
|
-
#
|
12
|
-
# Pact::RakeTask.new do |pact|
|
13
|
-
# pact.file 'spec/pacts/some-pact.json',
|
14
|
-
# from_url: 'http://example.com/some-pact.json'
|
15
|
-
# pact.file 'spec/pacts/other-pact.json',
|
16
|
-
# from_url: 'http://example.com/other-pact.json'
|
17
|
-
# end
|
18
|
-
# ```
|
19
|
-
class RakeTask < ::Rake::TaskLib
|
20
|
-
attr_reader :connections
|
21
|
-
|
22
|
-
def initialize(name = :pact)
|
23
|
-
@connections = []
|
24
|
-
|
25
|
-
yield self
|
26
|
-
|
27
|
-
namespace name do
|
28
|
-
desc "Update integration pacts from external sources"
|
29
|
-
task :pull do
|
30
|
-
connections.each do |conn|
|
31
|
-
body = fetch conn[:url]
|
32
|
-
File.open(conn[:file], 'w') {|f| f.write body }
|
33
|
-
puts "Wrote #{conn[:url]} to #{conn[:file]}"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
task name => "#{name}:pull" # default task for the namespace
|
38
|
-
end
|
39
|
-
|
40
|
-
def file(filename, options = {})
|
41
|
-
url = options.fetch(:from_url)
|
42
|
-
@connections << {file: filename, url: url}
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
# written with plain Net::HTTP to avoid bringing in extra dependencies
|
47
|
-
def fetch(url_string, redirection_limit = 5)
|
48
|
-
raise 'Too many HTTP redirects' if redirection_limit == 0
|
49
|
-
url = URI.parse(url_string)
|
50
|
-
response = Net::HTTP.get_response(url)
|
51
|
-
case response
|
52
|
-
when Net::HTTPSuccess then
|
53
|
-
response.body
|
54
|
-
when Net::HTTPRedirection then
|
55
|
-
location = response['Location']
|
56
|
-
fetch(location, redirection_limit - 1)
|
57
|
-
else
|
58
|
-
response.value # raise the appropriate error
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
|
64
|
-
end
|