pact 1.0.28 → 1.0.29
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/lib/pact/provider/rspec.rb +39 -8
- data/lib/pact/version.rb +1 -1
- data/spec/support/stubbing.json +22 -0
- data/spec/support/stubbing.rb +25 -0
- data/tasks/pact-test.rake +6 -1
- metadata +5 -7
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@ Do this to generate your change history
|
|
2
2
|
|
3
3
|
git log --date=relative --pretty=format:' * %h - %s (%an, %ad)'
|
4
4
|
|
5
|
+
### 1.0.29 (12 December 2013)
|
6
|
+
|
7
|
+
* 8ffde69 - Providing before :all like functionality using before :each to get the dual benefits of faster tests and the ability to use stubbing (Beth, 53 seconds ago)
|
8
|
+
* d30a78b - Added test to ensure rspec stubbing always works (Beth Skurrie, 15 hours ago)
|
9
|
+
|
5
10
|
### 1.0.28 (11 December 2013)
|
6
11
|
|
7
12
|
* 24f9ea0 - Changed provider set up and tear down back to running in before :each, as rspec stubbing is not supported in before :all (Beth, 15 seconds ago)
|
data/Gemfile.lock
CHANGED
data/lib/pact/provider/rspec.rb
CHANGED
@@ -62,25 +62,32 @@ module Pact
|
|
62
62
|
|
63
63
|
describe description_for(interaction), :pact => :verify do
|
64
64
|
|
65
|
+
interaction_context = InteractionContext.new
|
66
|
+
|
65
67
|
before do
|
66
|
-
|
67
|
-
|
68
|
+
interaction_context.run_once :before do
|
69
|
+
set_up_provider_state interaction.provider_state, options[:consumer]
|
70
|
+
replay_interaction interaction
|
71
|
+
interaction_context.last_response = last_response
|
72
|
+
end
|
68
73
|
end
|
69
74
|
|
70
75
|
after do
|
71
|
-
|
76
|
+
interaction_context.run_once :after do
|
77
|
+
tear_down_provider_state interaction.provider_state, options[:consumer]
|
78
|
+
end
|
72
79
|
end
|
73
80
|
|
74
|
-
describe_response interaction.response
|
81
|
+
describe_response interaction.response, interaction_context
|
75
82
|
end
|
76
83
|
|
77
84
|
end
|
78
85
|
|
79
|
-
def describe_response response
|
86
|
+
def describe_response response, interaction_context
|
80
87
|
describe "returns a response which" do
|
81
88
|
if response['status']
|
82
89
|
it "has status code #{response['status']}" do
|
83
|
-
expect(last_response.status).to eql response['status']
|
90
|
+
expect(interaction_context.last_response.status).to eql response['status']
|
84
91
|
end
|
85
92
|
end
|
86
93
|
|
@@ -88,7 +95,7 @@ module Pact
|
|
88
95
|
describe "includes headers" do
|
89
96
|
response['headers'].each do |name, value|
|
90
97
|
it "\"#{name}\" with value \"#{value}\"" do
|
91
|
-
expect(last_response.headers[name]).to match_term value
|
98
|
+
expect(interaction_context.last_response.headers[name]).to match_term value
|
92
99
|
end
|
93
100
|
end
|
94
101
|
end
|
@@ -96,7 +103,7 @@ module Pact
|
|
96
103
|
|
97
104
|
if response['body']
|
98
105
|
it "has a matching body" do
|
99
|
-
expect(parse_body_from_response(last_response)).to match_term response['body']
|
106
|
+
expect(parse_body_from_response(interaction_context.last_response)).to match_term response['body']
|
100
107
|
end
|
101
108
|
end
|
102
109
|
end
|
@@ -111,6 +118,30 @@ module Pact
|
|
111
118
|
end
|
112
119
|
|
113
120
|
end
|
121
|
+
|
122
|
+
# The "arrange" and "act" parts of the test really only need to be run once,
|
123
|
+
# however, stubbing is not supported in before :all, so this is a
|
124
|
+
# wee hack to enable before :all like functionality using before :each.
|
125
|
+
# In an ideal world, the test setup and execution should be quick enough for
|
126
|
+
# the difference between :all and :each to be unnoticable, but the annoying
|
127
|
+
# reality is, sometimes it does make a difference. This is for you, V!
|
128
|
+
|
129
|
+
class InteractionContext
|
130
|
+
|
131
|
+
attr_accessor :last_response
|
132
|
+
|
133
|
+
def initialize
|
134
|
+
@already_run = []
|
135
|
+
end
|
136
|
+
|
137
|
+
def run_once id
|
138
|
+
unless @already_run.include?(id)
|
139
|
+
yield
|
140
|
+
@already_run << id
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
114
145
|
end
|
115
146
|
end
|
116
147
|
end
|
data/lib/pact/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"consumer": {
|
3
|
+
"name": "Consumer"
|
4
|
+
},
|
5
|
+
"provider": {
|
6
|
+
"name": "Provider"
|
7
|
+
},
|
8
|
+
"interactions": [
|
9
|
+
{
|
10
|
+
"description": "A test request",
|
11
|
+
"request": {
|
12
|
+
"method": "get",
|
13
|
+
"path": "/"
|
14
|
+
},
|
15
|
+
"response": {
|
16
|
+
"status": 200,
|
17
|
+
"body": "stubbing works"
|
18
|
+
},
|
19
|
+
"provider_state": "something is stubbed"
|
20
|
+
}
|
21
|
+
]
|
22
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'pact/provider/rspec'
|
2
|
+
require 'rspec/mocks'
|
3
|
+
|
4
|
+
class StubbedThing
|
5
|
+
def self.stub_me
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class App
|
10
|
+
def self.call env
|
11
|
+
[200, {}, [StubbedThing.stub_me]]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Pact.provider_states_for 'Consumer' do
|
16
|
+
provider_state 'something is stubbed' do
|
17
|
+
set_up do
|
18
|
+
StubbedThing.stub(:stub_me).and_return("stubbing works")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Pact.service_provider 'Provider' do
|
24
|
+
app { App }
|
25
|
+
end
|
data/tasks/pact-test.rake
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
+
require 'pact/tasks'
|
2
|
+
|
3
|
+
Pact::VerificationTask.new(:stubbing) do | pact |
|
4
|
+
pact.uri './spec/support/stubbing.json', :pact_helper => './spec/support/stubbing.rb'
|
5
|
+
end
|
1
6
|
|
2
7
|
namespace :pact do
|
3
8
|
|
4
9
|
desc 'Runs pact tests against a sample application, testing failure and success.'
|
5
|
-
task :tests do
|
10
|
+
task :tests => ['pact:verify:stubbing'] do
|
6
11
|
|
7
12
|
require 'pact/provider/pact_spec_runner'
|
8
13
|
require 'open3'
|
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.29
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -415,6 +415,8 @@ files:
|
|
415
415
|
- spec/support/missing_provider_states_output.txt
|
416
416
|
- spec/support/pact_helper.rb
|
417
417
|
- spec/support/shared_examples_for_request.rb
|
418
|
+
- spec/support/stubbing.json
|
419
|
+
- spec/support/stubbing.rb
|
418
420
|
- spec/support/test_app_fail.json
|
419
421
|
- spec/support/test_app_pass.json
|
420
422
|
- tasks/pact-test.rake
|
@@ -432,18 +434,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
432
434
|
- - ! '>='
|
433
435
|
- !ruby/object:Gem::Version
|
434
436
|
version: '0'
|
435
|
-
segments:
|
436
|
-
- 0
|
437
|
-
hash: -54424747332292177
|
438
437
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
439
438
|
none: false
|
440
439
|
requirements:
|
441
440
|
- - ! '>='
|
442
441
|
- !ruby/object:Gem::Version
|
443
442
|
version: '0'
|
444
|
-
segments:
|
445
|
-
- 0
|
446
|
-
hash: -54424747332292177
|
447
443
|
requirements: []
|
448
444
|
rubyforge_project:
|
449
445
|
rubygems_version: 1.8.23
|
@@ -502,5 +498,7 @@ test_files:
|
|
502
498
|
- spec/support/missing_provider_states_output.txt
|
503
499
|
- spec/support/pact_helper.rb
|
504
500
|
- spec/support/shared_examples_for_request.rb
|
501
|
+
- spec/support/stubbing.json
|
502
|
+
- spec/support/stubbing.rb
|
505
503
|
- spec/support/test_app_fail.json
|
506
504
|
- spec/support/test_app_pass.json
|