pact 1.0.34 → 1.0.35
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +10 -2
- data/Gemfile.lock +1 -1
- data/README.md +31 -5
- data/lib/pact/configuration.rb +1 -1
- data/lib/pact/matchers/index_not_found.rb +1 -1
- data/lib/pact/matchers/unexpected_index.rb +1 -1
- data/lib/pact/matchers/unexpected_key.rb +1 -1
- data/lib/pact/provider/configuration.rb +4 -2
- data/lib/pact/provider/rspec.rb +1 -0
- data/lib/pact/provider/{provider_state.rb → state/provider_state.rb} +41 -3
- data/lib/pact/provider/{provider_state_configured_modules.rb → state/provider_state_configured_modules.rb} +1 -1
- data/lib/pact/provider/state/provider_state_manager.rb +42 -0
- data/lib/pact/provider/{provider_state_proxy.rb → state/provider_state_proxy.rb} +5 -1
- data/lib/pact/provider/test_methods.rb +5 -11
- data/lib/pact/provider/world.rb +8 -4
- data/lib/pact/shared/key_not_found.rb +1 -1
- data/lib/pact/version.rb +1 -1
- data/spec/lib/pact/provider/state/provider_state_manager_spec.rb +89 -0
- data/spec/lib/pact/provider/{provider_state_proxy_spec.rb → state/provider_state_proxy_spec.rb} +24 -4
- data/spec/lib/pact/provider/state/provider_state_spec.rb +213 -0
- data/spec/lib/pact/provider/world_spec.rb +9 -1
- metadata +18 -9
- data/spec/lib/pact/provider/provider_state_spec.rb +0 -161
data/CHANGELOG.md
CHANGED
@@ -2,11 +2,19 @@ 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.
|
5
|
+
### 1.0.35 (19 March 2014)
|
6
|
+
|
7
|
+
* 44c6806 - Updated README.md with new set_up and tear_down instructions (bethesque, 29 seconds ago)
|
8
|
+
* 3c426b7 - Added set_up/tear_down to manage base provider state.
|
9
|
+
* 697a5be - Changed default logging level to DEBUG (bethesque, 32 minutes ago)
|
10
|
+
* 48483b2 - Fixed JSON serialisation of matcher results with active_support loaded (bethesque, 49 minutes ago)
|
11
|
+
* 0be5b01 - Updated description of Shokkenki (bethesque, 7 hours ago)
|
12
|
+
|
13
|
+
### 1.0.34 (17 March 2014)
|
6
14
|
|
7
15
|
* 6c923f4 - In the pact file, replaced $.metadata.pact_gem.version with $.metadata.pactSpecificationVersion as the gem version is irrelevant - it is the serialization format that matters, and that hasn't changed yet. Also, recording the gem version creates extra changes to be committed when the gem is upgraded, and is meaningless for pacts generated/verified by the JVM code. (Beth Skurrie, 5 minutes ago)
|
8
16
|
|
9
|
-
### 1.0.33 (13 March
|
17
|
+
### 1.0.33 (13 March 2014)
|
10
18
|
|
11
19
|
* 49456cc - Added the ability to configure modules that can be used in provider state definitions (Beth Skurrie, 75
|
12
20
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -110,7 +110,7 @@ describe MyServiceProviderClient, :pact => true do
|
|
110
110
|
# Configure your client to point to the stub service on localhost using the port you have specified
|
111
111
|
MyServiceProviderClient.base_uri 'localhost:1234'
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
subject { MyServiceProviderClient.new }
|
115
115
|
|
116
116
|
describe "get_something" do
|
@@ -287,8 +287,36 @@ end
|
|
287
287
|
require_relative 'provider_states_for_my_service_consumer.rb'
|
288
288
|
```
|
289
289
|
|
290
|
-
|
290
|
+
To define code that should run before/after each interaction, regardless of whether a provider state is specified or not:
|
291
|
+
|
292
|
+
```ruby
|
293
|
+
|
294
|
+
Pact.provider_states_for 'My Service Consumer' do
|
295
|
+
|
296
|
+
set_up do
|
297
|
+
# eg. create API user, start database cleaner transaction
|
298
|
+
end
|
299
|
+
|
300
|
+
tear_down do
|
301
|
+
# eg. clean database
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
```
|
306
|
+
|
307
|
+
Or for global set up/tear down for all consumers:
|
308
|
+
|
309
|
+
```ruby
|
310
|
+
Pact.set_up do
|
311
|
+
# eg. start database cleaner transaction
|
312
|
+
# Avoid using the global set up for creating data as it will make your tests brittle.
|
313
|
+
# You don't want changes to one consumer pact to affect another one.
|
314
|
+
end
|
291
315
|
|
316
|
+
Pact.tear_down do
|
317
|
+
# eg. clean database
|
318
|
+
end
|
319
|
+
```
|
292
320
|
|
293
321
|
### Verifying pacts
|
294
322
|
|
@@ -376,7 +404,7 @@ See [Frequently Asked Questions](https://github.com/realestate-com-au/pact/blob/
|
|
376
404
|
|
377
405
|
[Pact Broker Client](https://github.com/bethesque/pact_broker-client) - Contains rake tasks for publishing pacts to the pact_broker.
|
378
406
|
|
379
|
-
[Shokkenki](https://github.com/brentsnook/shokkenki) - Another Consumer Driven Contract gem written by one of Pact's original authors, Brent Snook.
|
407
|
+
[Shokkenki](https://github.com/brentsnook/shokkenki) - Another Consumer Driven Contract gem written by one of Pact's original authors, Brent Snook. Shokkenki allows matchers to be composed using jsonpath expressions and allows auto-generation of mock response values based on regular expressions.
|
380
408
|
|
381
409
|
## TODO
|
382
410
|
|
@@ -386,12 +414,10 @@ Short term:
|
|
386
414
|
|
387
415
|
Long term:
|
388
416
|
- Provide more flexible matching (eg the keys should match, and the classes of the values should match, but the values of each key do not need to be equal). This is to make the pact verification less brittle.
|
389
|
-
- Add support for verifying pact against running server
|
390
417
|
- Add XML support
|
391
418
|
- Improve display of interaction diffs
|
392
419
|
- Decouple Rspec from Pact and make rspec-pact gem for easy integration
|
393
420
|
|
394
|
-
|
395
421
|
## Contributing
|
396
422
|
|
397
423
|
1. Fork it
|
data/lib/pact/configuration.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'pact/provider/pact_verification'
|
2
2
|
require 'pact/shared/dsl'
|
3
|
-
require 'pact/provider/
|
3
|
+
require 'pact/provider/state/provider_state'
|
4
|
+
require 'pact/provider/state/provider_state_configured_modules'
|
4
5
|
|
5
6
|
module Pact
|
6
7
|
|
@@ -13,6 +14,7 @@ module Pact
|
|
13
14
|
end
|
14
15
|
|
15
16
|
Pact.send(:extend, Pact::Provider::DSL)
|
17
|
+
Pact.send(:extend, Pact::Provider::State::DSL)
|
16
18
|
|
17
19
|
module Configuration
|
18
20
|
|
@@ -46,7 +48,7 @@ module Pact
|
|
46
48
|
end
|
47
49
|
|
48
50
|
def include mod
|
49
|
-
Pact::Provider::ProviderStateConfiguredModules.instance_eval do
|
51
|
+
Pact::Provider::State::ProviderStateConfiguredModules.instance_eval do
|
50
52
|
include mod
|
51
53
|
end
|
52
54
|
end
|
data/lib/pact/provider/rspec.rb
CHANGED
@@ -84,6 +84,7 @@ module Pact
|
|
84
84
|
end
|
85
85
|
|
86
86
|
def describe_response response, interaction_context
|
87
|
+
# TODO : Hide the interaction_context from the output line as it is confusing
|
87
88
|
describe "returns a response which" do
|
88
89
|
if response['status']
|
89
90
|
it "has status code #{response['status']}" do
|
@@ -1,14 +1,24 @@
|
|
1
1
|
require 'pact/shared/dsl'
|
2
|
-
require 'pact/provider/provider_state_configured_modules'
|
2
|
+
require 'pact/provider/state/provider_state_configured_modules'
|
3
3
|
|
4
4
|
module Pact
|
5
|
-
module Provider
|
5
|
+
module Provider::State
|
6
|
+
|
7
|
+
BASE_PROVIDER_STATE_NAME = "__base_provider_state__"
|
6
8
|
|
7
9
|
module DSL
|
8
10
|
def provider_state name, &block
|
9
11
|
ProviderStates.provider_state(name, &block).register
|
10
12
|
end
|
11
13
|
|
14
|
+
def set_up &block
|
15
|
+
ProviderStates.base_provider_state.register.register_set_up &block
|
16
|
+
end
|
17
|
+
|
18
|
+
def tear_down &block
|
19
|
+
ProviderStates.base_provider_state.register_tear_down &block
|
20
|
+
end
|
21
|
+
|
12
22
|
def provider_states_for name, &block
|
13
23
|
ProviderStates.current_namespaces << name
|
14
24
|
instance_eval(&block)
|
@@ -21,6 +31,12 @@ module Pact
|
|
21
31
|
ProviderState.build(name, current_namespaces.join('.'), &block)
|
22
32
|
end
|
23
33
|
|
34
|
+
def self.base_provider_state
|
35
|
+
fullname = namespaced_name BASE_PROVIDER_STATE_NAME, {:for => current_namespaces.first }
|
36
|
+
provider_states[fullname] ||
|
37
|
+
ProviderState.new(BASE_PROVIDER_STATE_NAME, current_namespaces.join('.'))
|
38
|
+
end
|
39
|
+
|
24
40
|
def self.register name, provider_state
|
25
41
|
provider_states[name] = provider_state
|
26
42
|
end
|
@@ -34,8 +50,17 @@ module Pact
|
|
34
50
|
end
|
35
51
|
|
36
52
|
def self.get name, options = {}
|
53
|
+
fullname = namespaced_name name, options
|
54
|
+
(provider_states[fullname] || provider_states[fullname.to_sym] || provider_states[name])
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.get_base opts = {}
|
58
|
+
fullname = namespaced_name BASE_PROVIDER_STATE_NAME, opts
|
59
|
+
provider_states[fullname] || NoOpProviderState
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.namespaced_name name, options = {}
|
37
63
|
fullname = options[:for] ? "#{options[:for]}.#{name}" : name
|
38
|
-
(provider_states[fullname] || provider_states[fullname.to_sym]) || provider_states[name]
|
39
64
|
end
|
40
65
|
end
|
41
66
|
|
@@ -72,6 +97,7 @@ module Pact
|
|
72
97
|
|
73
98
|
def register
|
74
99
|
ProviderStates.register(namespaced(name), self)
|
100
|
+
self
|
75
101
|
end
|
76
102
|
|
77
103
|
def finalize
|
@@ -130,5 +156,17 @@ module Pact
|
|
130
156
|
end
|
131
157
|
end
|
132
158
|
end
|
159
|
+
|
160
|
+
class NoOpProviderState
|
161
|
+
|
162
|
+
def self.set_up
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
def self.tear_down
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
133
171
|
end
|
134
172
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Pact
|
2
|
+
module Provider::State
|
3
|
+
class ProviderStateManager
|
4
|
+
|
5
|
+
attr_reader :provider_state_name, :consumer
|
6
|
+
|
7
|
+
def initialize provider_state_name, consumer
|
8
|
+
@provider_state_name = provider_state_name
|
9
|
+
@consumer = consumer
|
10
|
+
end
|
11
|
+
|
12
|
+
def set_up_provider_state
|
13
|
+
get_global_base_provider_state.set_up
|
14
|
+
get_consumer_base_provider_state.set_up
|
15
|
+
if provider_state_name
|
16
|
+
get_provider_state.set_up
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def tear_down_provider_state
|
21
|
+
if provider_state_name
|
22
|
+
get_provider_state.tear_down
|
23
|
+
end
|
24
|
+
get_consumer_base_provider_state.tear_down
|
25
|
+
get_global_base_provider_state.tear_down
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_provider_state
|
29
|
+
Pact.world.provider_states.get(provider_state_name, :for => consumer)
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_consumer_base_provider_state
|
33
|
+
Pact.world.provider_states.get_base(:for => consumer)
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_global_base_provider_state
|
37
|
+
Pact.world.provider_states.get_base
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Pact
|
2
|
-
module Provider
|
2
|
+
module Provider::State
|
3
3
|
class ProviderStateProxy
|
4
4
|
|
5
5
|
attr_reader :missing_provider_states
|
@@ -16,6 +16,10 @@ module Pact
|
|
16
16
|
provider_state
|
17
17
|
end
|
18
18
|
|
19
|
+
def get_base options = {}
|
20
|
+
ProviderStates.get_base options
|
21
|
+
end
|
22
|
+
|
19
23
|
private
|
20
24
|
|
21
25
|
def error_message name, consumer
|
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'pact/logging'
|
2
2
|
require 'rack/test'
|
3
3
|
require 'pact/consumer_contract/interaction'
|
4
|
-
require 'pact/provider/provider_state'
|
5
|
-
require 'pact/provider/provider_state_proxy'
|
4
|
+
require 'pact/provider/state/provider_state'
|
5
|
+
require 'pact/provider/state/provider_state_proxy'
|
6
6
|
require 'pact/provider/request'
|
7
7
|
require 'pact/provider/world'
|
8
|
+
require 'pact/provider/state/provider_state_manager'
|
8
9
|
|
9
10
|
module Pact
|
10
11
|
module Provider
|
@@ -34,20 +35,13 @@ module Pact
|
|
34
35
|
end
|
35
36
|
|
36
37
|
def set_up_provider_state provider_state_name, consumer
|
37
|
-
|
38
|
-
get_provider_state(provider_state_name, consumer).set_up
|
39
|
-
end
|
38
|
+
State::ProviderStateManager.new(provider_state_name, consumer).set_up_provider_state
|
40
39
|
end
|
41
40
|
|
42
41
|
def tear_down_provider_state provider_state_name, consumer
|
43
|
-
|
44
|
-
get_provider_state(provider_state_name, consumer).tear_down
|
45
|
-
end
|
42
|
+
State::ProviderStateManager.new(provider_state_name, consumer).tear_down_provider_state
|
46
43
|
end
|
47
44
|
|
48
|
-
def get_provider_state provider_state_name, consumer
|
49
|
-
Pact.world.provider_states.get(provider_state_name, :for => consumer)
|
50
|
-
end
|
51
45
|
end
|
52
46
|
end
|
53
47
|
end
|
data/lib/pact/provider/world.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
|
+
require 'pact/provider/state/provider_state_proxy'
|
2
|
+
|
1
3
|
module Pact
|
2
4
|
|
3
5
|
def self.world
|
4
6
|
@world ||= Pact::Provider::World.new
|
5
7
|
end
|
6
8
|
|
9
|
+
# internal api, for testing only
|
10
|
+
def self.clear_world
|
11
|
+
@world = nil
|
12
|
+
end
|
13
|
+
|
7
14
|
module Provider
|
8
15
|
class World
|
9
16
|
|
10
|
-
def initialize
|
11
|
-
end
|
12
|
-
|
13
17
|
def provider_states
|
14
|
-
@provider_states_proxy ||= Pact::Provider::ProviderStateProxy.new
|
18
|
+
@provider_states_proxy ||= Pact::Provider::State::ProviderStateProxy.new
|
15
19
|
end
|
16
20
|
|
17
21
|
end
|
data/lib/pact/version.rb
CHANGED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pact/provider/state/provider_state_manager'
|
3
|
+
|
4
|
+
module Pact::Provider::State
|
5
|
+
|
6
|
+
|
7
|
+
describe ProviderStateManager do
|
8
|
+
|
9
|
+
PROVIDER_STATE_MESSAGES = []
|
10
|
+
|
11
|
+
before do
|
12
|
+
PROVIDER_STATE_MESSAGES.clear
|
13
|
+
Pact.clear_world
|
14
|
+
|
15
|
+
Pact.set_up do
|
16
|
+
PROVIDER_STATE_MESSAGES << :global_base_set_up
|
17
|
+
end
|
18
|
+
|
19
|
+
Pact.tear_down do
|
20
|
+
PROVIDER_STATE_MESSAGES << :global_base_tear_down
|
21
|
+
end
|
22
|
+
|
23
|
+
Pact.provider_states_for "a consumer with provider states" do
|
24
|
+
set_up do
|
25
|
+
PROVIDER_STATE_MESSAGES << :consumer_base_set_up
|
26
|
+
end
|
27
|
+
|
28
|
+
tear_down do
|
29
|
+
PROVIDER_STATE_MESSAGES << :consumer_base_tear_down
|
30
|
+
end
|
31
|
+
|
32
|
+
provider_state "a custom state" do
|
33
|
+
set_up do
|
34
|
+
PROVIDER_STATE_MESSAGES << :custom_consumer_state_set_up
|
35
|
+
end
|
36
|
+
|
37
|
+
tear_down do
|
38
|
+
PROVIDER_STATE_MESSAGES << :custom_consumer_state_tear_down
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
let(:provider_state_manager) { ProviderStateManager.new("a custom state", "a consumer with provider states") }
|
46
|
+
|
47
|
+
describe "set_up_provider_state" do
|
48
|
+
|
49
|
+
subject { provider_state_manager.set_up_provider_state }
|
50
|
+
|
51
|
+
it "sets up the global base state" do
|
52
|
+
subject
|
53
|
+
expect(PROVIDER_STATE_MESSAGES[0]).to eq :global_base_set_up
|
54
|
+
end
|
55
|
+
|
56
|
+
it "sets up the consumer base state" do
|
57
|
+
subject
|
58
|
+
expect(PROVIDER_STATE_MESSAGES[1]).to eq :consumer_base_set_up
|
59
|
+
end
|
60
|
+
|
61
|
+
it "sets up the consumer custom state" do
|
62
|
+
subject
|
63
|
+
expect(PROVIDER_STATE_MESSAGES[2]).to eq :custom_consumer_state_set_up
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "tear_down_provider_state" do
|
68
|
+
|
69
|
+
subject { provider_state_manager.tear_down_provider_state }
|
70
|
+
|
71
|
+
it "tears down the consumer custom state" do
|
72
|
+
subject
|
73
|
+
expect(PROVIDER_STATE_MESSAGES[0]).to eq :custom_consumer_state_tear_down
|
74
|
+
end
|
75
|
+
|
76
|
+
it "tears down the consumer base state" do
|
77
|
+
subject
|
78
|
+
expect(PROVIDER_STATE_MESSAGES[1]).to eq :consumer_base_tear_down
|
79
|
+
end
|
80
|
+
|
81
|
+
it "tears down the global base state" do
|
82
|
+
subject
|
83
|
+
expect(PROVIDER_STATE_MESSAGES[2]).to eq :global_base_tear_down
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
data/spec/lib/pact/provider/{provider_state_proxy_spec.rb → state/provider_state_proxy_spec.rb}
RENAMED
@@ -1,22 +1,24 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'pact/provider/provider_state_proxy'
|
2
|
+
require 'pact/provider/state/provider_state_proxy'
|
3
3
|
|
4
4
|
module Pact
|
5
|
-
module Provider
|
5
|
+
module Provider::State
|
6
6
|
describe ProviderStateProxy do
|
7
7
|
|
8
8
|
let(:provider_state_proxy) { ProviderStateProxy.new }
|
9
9
|
|
10
|
+
let(:options) { { :for => 'some consumer'} }
|
11
|
+
let(:provider_state) { double("provider_state")}
|
12
|
+
|
10
13
|
describe "get" do
|
11
14
|
let(:name) { "some state" }
|
12
|
-
let(:options) { { :for => 'some consumer'} }
|
13
|
-
let(:provider_state) { double("provider_state")}
|
14
15
|
|
15
16
|
subject { provider_state_proxy.get name, options }
|
16
17
|
|
17
18
|
before do
|
18
19
|
ProviderStates.stub(:get).and_return(provider_state)
|
19
20
|
end
|
21
|
+
|
20
22
|
context "when the provider state exists" do
|
21
23
|
|
22
24
|
it "retrieves the provider state from ProviderState" do
|
@@ -55,6 +57,24 @@ module Pact
|
|
55
57
|
|
56
58
|
|
57
59
|
end
|
60
|
+
|
61
|
+
describe "get_base" do
|
62
|
+
|
63
|
+
before do
|
64
|
+
ProviderStates.stub(:get_base).and_return(provider_state)
|
65
|
+
end
|
66
|
+
|
67
|
+
subject { provider_state_proxy.get_base options }
|
68
|
+
|
69
|
+
it "calls through to ProviderStates" do
|
70
|
+
ProviderStates.should_receive(:get_base).with(options)
|
71
|
+
subject
|
72
|
+
end
|
73
|
+
|
74
|
+
it "returns the state" do
|
75
|
+
expect(subject).to eq provider_state
|
76
|
+
end
|
77
|
+
end
|
58
78
|
end
|
59
79
|
end
|
60
80
|
end
|
@@ -0,0 +1,213 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pact/provider/state/provider_state'
|
3
|
+
|
4
|
+
module Pact
|
5
|
+
module Provider::State
|
6
|
+
|
7
|
+
describe ProviderStates do
|
8
|
+
MESSAGES = []
|
9
|
+
|
10
|
+
before do
|
11
|
+
MESSAGES.clear
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'global ProviderState' do
|
15
|
+
|
16
|
+
|
17
|
+
Pact.provider_state :no_alligators do
|
18
|
+
set_up do
|
19
|
+
MESSAGES << 'set_up'
|
20
|
+
end
|
21
|
+
tear_down do
|
22
|
+
MESSAGES << 'tear_down'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Pact.provider_state 'some alligators' do
|
27
|
+
no_op
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
subject { ProviderStates.get('no_alligators') }
|
32
|
+
|
33
|
+
describe 'set_up' do
|
34
|
+
it 'should call the block passed to set_up' do
|
35
|
+
subject.set_up
|
36
|
+
MESSAGES.should eq ['set_up']
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'tear_down' do
|
41
|
+
it 'should call the block passed to set_up' do
|
42
|
+
subject.tear_down
|
43
|
+
MESSAGES.should eq ['tear_down']
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.get' do
|
48
|
+
context 'when the name is a matching symbol' do
|
49
|
+
it 'will return the ProviderState' do
|
50
|
+
ProviderStates.get('no_alligators').should_not be_nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
context 'when the name is a matching string' do
|
54
|
+
it 'will return the ProviderState' do
|
55
|
+
ProviderStates.get('some alligators').should_not be_nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'no_op' do
|
62
|
+
context "when a no_op is defined instead of a set_up or tear_down" do
|
63
|
+
it "treats set_up and tear_down as empty blocks" do
|
64
|
+
Pact.provider_state 'with_no_op' do
|
65
|
+
no_op
|
66
|
+
end
|
67
|
+
ProviderStates.get('with_no_op').set_up
|
68
|
+
ProviderStates.get('with_no_op').tear_down
|
69
|
+
end
|
70
|
+
end
|
71
|
+
context "when a no_op is defined with a set_up" do
|
72
|
+
it "raises an error" do
|
73
|
+
expect do
|
74
|
+
Pact.provider_state 'with_no_op_and_set_up' do
|
75
|
+
no_op
|
76
|
+
set_up do
|
77
|
+
|
78
|
+
end
|
79
|
+
end.to raise_error(/Provider state \"with_no_op_and_set_up\" has been defined as a no_op but it also has a set_up block. Please remove one or the other./)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
context "when a no_op is defined with a tear_down" do
|
84
|
+
it "raises an error" do
|
85
|
+
expect do
|
86
|
+
Pact.provider_state 'with_no_op_and_set_up' do
|
87
|
+
no_op
|
88
|
+
tear_down do
|
89
|
+
|
90
|
+
end
|
91
|
+
end.to raise_error(/Provider state \"with_no_op_and_set_up\" has been defined as a no_op but it also has a tear_down block. Please remove one or the other./)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
describe 'namespaced ProviderStates' do
|
100
|
+
|
101
|
+
NAMESPACED_MESSAGES = []
|
102
|
+
|
103
|
+
Pact.provider_states_for 'a consumer' do
|
104
|
+
provider_state 'the weather is sunny' do
|
105
|
+
set_up do
|
106
|
+
NAMESPACED_MESSAGES << 'sunny!'
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
Pact.provider_state 'the weather is cloudy' do
|
112
|
+
set_up do
|
113
|
+
NAMESPACED_MESSAGES << 'cloudy :('
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
before do
|
118
|
+
NAMESPACED_MESSAGES.clear
|
119
|
+
end
|
120
|
+
|
121
|
+
describe '.get' do
|
122
|
+
context 'for a consumer' do
|
123
|
+
it 'has a namespaced name' do
|
124
|
+
ProviderStates.get('the weather is sunny', :for => 'a consumer').should_not be_nil
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'falls back to a global state of the same name if one is not found for the specified consumer' do
|
128
|
+
ProviderStates.get('the weather is cloudy', :for => 'a consumer').should_not be_nil
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
describe 'set_up' do
|
135
|
+
context 'for a consumer' do
|
136
|
+
it 'runs its own setup' do
|
137
|
+
ProviderStates.get('the weather is sunny', :for => 'a consumer').set_up
|
138
|
+
NAMESPACED_MESSAGES.should eq ['sunny!']
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "base_provider_state" do
|
145
|
+
Pact.provider_states_for "a consumer with base state" do
|
146
|
+
set_up do
|
147
|
+
MESSAGES << "setting up base provider state"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context "when the base state has been declared" do
|
152
|
+
it "creates a base state for the provider" do
|
153
|
+
ProviderStates.get_base(:for => "a consumer with base state").set_up
|
154
|
+
expect(MESSAGES).to eq ["setting up base provider state"]
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
context "when a base state has not been declared" do
|
160
|
+
it "returns a no op state" do
|
161
|
+
ProviderStates.get_base(:for => "a consumer that does not exist").set_up
|
162
|
+
ProviderStates.get_base(:for => "a consumer that does not exist").tear_down
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "global base_provider_state" do
|
169
|
+
|
170
|
+
before(:all) do
|
171
|
+
Pact.set_up do
|
172
|
+
MESSAGES << "setting up global base provider state"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context "when the base state has been declared" do
|
177
|
+
it "creates a base state for the provider" do
|
178
|
+
ProviderStates.get_base.set_up
|
179
|
+
expect(MESSAGES).to eq ["setting up global base provider state"]
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
context "when a base state has not been declared" do
|
185
|
+
it "returns a no op state" do
|
186
|
+
ProviderStates.get_base.set_up
|
187
|
+
ProviderStates.get_base.tear_down
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe "invalid provider state" do
|
193
|
+
context "when no set_up or tear_down is provided" do
|
194
|
+
it "raises an error to prevent someone forgetting about the set_up and putting the set_up code directly in the provider_state block and wasting 20 minutes trying to work out why their provider states aren't working properly" do
|
195
|
+
expect do
|
196
|
+
Pact.provider_state 'invalid' do
|
197
|
+
end
|
198
|
+
end.to raise_error(/Please provide a set_up or tear_down block for provider state \"invalid\"/)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
context "when a no_op is defined" do
|
202
|
+
it "does not raise an error" do
|
203
|
+
expect do
|
204
|
+
Pact.provider_state 'valid' do
|
205
|
+
no_op
|
206
|
+
end
|
207
|
+
end.not_to raise_error
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
@@ -11,6 +11,14 @@ describe Pact do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
describe ".clear_world" do
|
15
|
+
it "clears the world" do
|
16
|
+
original_world = Pact.world
|
17
|
+
Pact.clear_world
|
18
|
+
expect(original_world).to_not be Pact.world
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
14
22
|
end
|
15
23
|
|
16
24
|
module Pact
|
@@ -20,7 +28,7 @@ module Pact
|
|
20
28
|
subject { World.new }
|
21
29
|
describe "provider_states" do
|
22
30
|
it "returns a provider state proxy" do
|
23
|
-
expect(subject.provider_states).to be_instance_of ProviderStateProxy
|
31
|
+
expect(subject.provider_states).to be_instance_of State::ProviderStateProxy
|
24
32
|
end
|
25
33
|
it "returns the same object each time" do
|
26
34
|
expect(subject.provider_states).to be subject.provider_states
|
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.35
|
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: 2014-03-
|
16
|
+
date: 2014-03-19 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: randexp
|
@@ -357,11 +357,12 @@ files:
|
|
357
357
|
- lib/pact/provider/pact_spec_runner.rb
|
358
358
|
- lib/pact/provider/pact_verification.rb
|
359
359
|
- lib/pact/provider/print_missing_provider_states.rb
|
360
|
-
- lib/pact/provider/provider_state.rb
|
361
|
-
- lib/pact/provider/provider_state_configured_modules.rb
|
362
|
-
- lib/pact/provider/provider_state_proxy.rb
|
363
360
|
- lib/pact/provider/request.rb
|
364
361
|
- lib/pact/provider/rspec.rb
|
362
|
+
- lib/pact/provider/state/provider_state.rb
|
363
|
+
- lib/pact/provider/state/provider_state_configured_modules.rb
|
364
|
+
- lib/pact/provider/state/provider_state_manager.rb
|
365
|
+
- lib/pact/provider/state/provider_state_proxy.rb
|
365
366
|
- lib/pact/provider/test_methods.rb
|
366
367
|
- lib/pact/provider/verification_report.rb
|
367
368
|
- lib/pact/provider/world.rb
|
@@ -411,10 +412,11 @@ files:
|
|
411
412
|
- spec/lib/pact/provider/pact_helper_locator_spec.rb
|
412
413
|
- spec/lib/pact/provider/pact_spec_runner_spec.rb
|
413
414
|
- spec/lib/pact/provider/print_missing_provider_states_spec.rb
|
414
|
-
- spec/lib/pact/provider/provider_state_proxy_spec.rb
|
415
|
-
- spec/lib/pact/provider/provider_state_spec.rb
|
416
415
|
- spec/lib/pact/provider/request_spec.rb
|
417
416
|
- spec/lib/pact/provider/rspec_spec.rb
|
417
|
+
- spec/lib/pact/provider/state/provider_state_manager_spec.rb
|
418
|
+
- spec/lib/pact/provider/state/provider_state_proxy_spec.rb
|
419
|
+
- spec/lib/pact/provider/state/provider_state_spec.rb
|
418
420
|
- spec/lib/pact/provider/world_spec.rb
|
419
421
|
- spec/lib/pact/reification_spec.rb
|
420
422
|
- spec/lib/pact/shared/dsl_spec.rb
|
@@ -451,12 +453,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
451
453
|
- - ! '>='
|
452
454
|
- !ruby/object:Gem::Version
|
453
455
|
version: '0'
|
456
|
+
segments:
|
457
|
+
- 0
|
458
|
+
hash: 548296881377135136
|
454
459
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
455
460
|
none: false
|
456
461
|
requirements:
|
457
462
|
- - ! '>='
|
458
463
|
- !ruby/object:Gem::Version
|
459
464
|
version: '0'
|
465
|
+
segments:
|
466
|
+
- 0
|
467
|
+
hash: 548296881377135136
|
460
468
|
requirements: []
|
461
469
|
rubyforge_project:
|
462
470
|
rubygems_version: 1.8.23
|
@@ -496,10 +504,11 @@ test_files:
|
|
496
504
|
- spec/lib/pact/provider/pact_helper_locator_spec.rb
|
497
505
|
- spec/lib/pact/provider/pact_spec_runner_spec.rb
|
498
506
|
- spec/lib/pact/provider/print_missing_provider_states_spec.rb
|
499
|
-
- spec/lib/pact/provider/provider_state_proxy_spec.rb
|
500
|
-
- spec/lib/pact/provider/provider_state_spec.rb
|
501
507
|
- spec/lib/pact/provider/request_spec.rb
|
502
508
|
- spec/lib/pact/provider/rspec_spec.rb
|
509
|
+
- spec/lib/pact/provider/state/provider_state_manager_spec.rb
|
510
|
+
- spec/lib/pact/provider/state/provider_state_proxy_spec.rb
|
511
|
+
- spec/lib/pact/provider/state/provider_state_spec.rb
|
503
512
|
- spec/lib/pact/provider/world_spec.rb
|
504
513
|
- spec/lib/pact/reification_spec.rb
|
505
514
|
- spec/lib/pact/shared/dsl_spec.rb
|
@@ -1,161 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'pact/provider/provider_state'
|
3
|
-
|
4
|
-
module Pact
|
5
|
-
module Provider
|
6
|
-
|
7
|
-
describe 'global ProviderState' do
|
8
|
-
|
9
|
-
MESSAGES = []
|
10
|
-
|
11
|
-
Pact.provider_state :no_alligators do
|
12
|
-
set_up do
|
13
|
-
MESSAGES << 'set_up'
|
14
|
-
end
|
15
|
-
tear_down do
|
16
|
-
MESSAGES << 'tear_down'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
Pact.provider_state 'some alligators' do
|
21
|
-
no_op
|
22
|
-
end
|
23
|
-
|
24
|
-
before do
|
25
|
-
MESSAGES.clear
|
26
|
-
end
|
27
|
-
|
28
|
-
subject { ProviderStates.get('no_alligators') }
|
29
|
-
|
30
|
-
describe 'set_up' do
|
31
|
-
it 'should call the block passed to set_up' do
|
32
|
-
subject.set_up
|
33
|
-
MESSAGES.should eq ['set_up']
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe 'tear_down' do
|
38
|
-
it 'should call the block passed to set_up' do
|
39
|
-
subject.tear_down
|
40
|
-
MESSAGES.should eq ['tear_down']
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '.get' do
|
45
|
-
context 'when the name is a matching symbol' do
|
46
|
-
it 'will return the ProviderState' do
|
47
|
-
ProviderStates.get('no_alligators').should_not be_nil
|
48
|
-
end
|
49
|
-
end
|
50
|
-
context 'when the name is a matching string' do
|
51
|
-
it 'will return the ProviderState' do
|
52
|
-
ProviderStates.get('some alligators').should_not be_nil
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe 'no_op' do
|
59
|
-
context "when a no_op is defined instead of a set_up or tear_down" do
|
60
|
-
it "treats set_up and tear_down as empty blocks" do
|
61
|
-
Pact.provider_state 'with_no_op' do
|
62
|
-
no_op
|
63
|
-
end
|
64
|
-
ProviderStates.get('with_no_op').set_up
|
65
|
-
ProviderStates.get('with_no_op').tear_down
|
66
|
-
end
|
67
|
-
end
|
68
|
-
context "when a no_op is defined with a set_up" do
|
69
|
-
it "raises an error" do
|
70
|
-
expect do
|
71
|
-
Pact.provider_state 'with_no_op_and_set_up' do
|
72
|
-
no_op
|
73
|
-
set_up do
|
74
|
-
|
75
|
-
end
|
76
|
-
end.to raise_error(/Provider state \"with_no_op_and_set_up\" has been defined as a no_op but it also has a set_up block. Please remove one or the other./)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
context "when a no_op is defined with a tear_down" do
|
81
|
-
it "raises an error" do
|
82
|
-
expect do
|
83
|
-
Pact.provider_state 'with_no_op_and_set_up' do
|
84
|
-
no_op
|
85
|
-
tear_down do
|
86
|
-
|
87
|
-
end
|
88
|
-
end.to raise_error(/Provider state \"with_no_op_and_set_up\" has been defined as a no_op but it also has a tear_down block. Please remove one or the other./)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
|
96
|
-
describe 'namespaced ProviderStates' do
|
97
|
-
|
98
|
-
NAMESPACED_MESSAGES = []
|
99
|
-
|
100
|
-
Pact.provider_states_for 'a consumer' do
|
101
|
-
provider_state 'the weather is sunny' do
|
102
|
-
set_up do
|
103
|
-
NAMESPACED_MESSAGES << 'sunny!'
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
Pact.provider_state 'the weather is cloudy' do
|
109
|
-
set_up do
|
110
|
-
NAMESPACED_MESSAGES << 'cloudy :('
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
before do
|
115
|
-
NAMESPACED_MESSAGES.clear
|
116
|
-
end
|
117
|
-
|
118
|
-
describe '.get' do
|
119
|
-
context 'for a consumer' do
|
120
|
-
it 'has a namespaced name' do
|
121
|
-
ProviderStates.get('the weather is sunny', :for => 'a consumer').should_not be_nil
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'falls back to a global state of the same name if one is not found for the specified consumer' do
|
125
|
-
ProviderStates.get('the weather is cloudy', :for => 'a consumer').should_not be_nil
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
describe 'set_up' do
|
132
|
-
context 'for a consumer' do
|
133
|
-
it 'runs its own setup' do
|
134
|
-
ProviderStates.get('the weather is sunny', :for => 'a consumer').set_up
|
135
|
-
NAMESPACED_MESSAGES.should eq ['sunny!']
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe "invalid provider state" do
|
142
|
-
context "when no set_up or tear_down is provided" do
|
143
|
-
it "raises an error to prevent someone forgetting about the set_up and putting the set_up code directly in the provider_state block and wasting 20 minutes trying to work out why their provider states aren't working properly" do
|
144
|
-
expect do
|
145
|
-
Pact.provider_state 'invalid' do
|
146
|
-
end
|
147
|
-
end.to raise_error(/Please provide a set_up or tear_down block for provider state \"invalid\"/)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
context "when a no_op is defined" do
|
151
|
-
it "does not raise an error" do
|
152
|
-
expect do
|
153
|
-
Pact.provider_state 'valid' do
|
154
|
-
no_op
|
155
|
-
end
|
156
|
-
end.not_to raise_error
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|