pact 0.1.37 → 1.0.0

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.
Files changed (65) hide show
  1. data/Gemfile.lock +6 -19
  2. data/example/zoo-app/Gemfile +1 -2
  3. data/example/zoo-app/Gemfile.lock +16 -13
  4. data/example/zoo-app/spec/pacts/zoo_app-animal_service.json +6 -6
  5. data/lib/pact/consumer/app_manager.rb +8 -28
  6. data/lib/pact/consumer/consumer_contract_builder.rb +65 -36
  7. data/lib/pact/consumer/dsl.rb +20 -10
  8. data/lib/pact/consumer/interaction_builder.rb +42 -0
  9. data/lib/pact/consumer/interactions_filter.rb +41 -0
  10. data/lib/pact/consumer/mock_service.rb +26 -19
  11. data/lib/pact/consumer/rspec.rb +2 -3
  12. data/lib/pact/consumer/server.rb +90 -0
  13. data/lib/pact/consumer.rb +6 -3
  14. data/lib/pact/consumer_contract/consumer_contract.rb +103 -0
  15. data/lib/pact/consumer_contract/interaction.rb +70 -0
  16. data/lib/pact/consumer_contract/service_consumer.rb +20 -0
  17. data/lib/pact/consumer_contract/service_provider.rb +20 -0
  18. data/lib/pact/consumer_contract.rb +1 -112
  19. data/lib/pact/{producer → provider}/dsl.rb +15 -4
  20. data/lib/pact/{producer → provider}/matchers.rb +0 -0
  21. data/lib/pact/{producer → provider}/pact_spec_runner.rb +2 -2
  22. data/lib/pact/{producer/producer_state.rb → provider/provider_state.rb} +13 -22
  23. data/lib/pact/provider/rspec.rb +128 -1
  24. data/lib/pact/{producer → provider}/test_methods.rb +12 -12
  25. data/lib/pact/{producer.rb → provider.rb} +0 -0
  26. data/lib/pact/verification_task.rb +4 -4
  27. data/lib/pact/version.rb +1 -1
  28. data/lib/pact.rb +1 -1
  29. data/pact.gemspec +1 -2
  30. data/scratchpad.txt +1 -1
  31. data/spec/features/consumption_spec.rb +15 -23
  32. data/spec/features/production_spec.rb +5 -5
  33. data/spec/features/{producer_states → provider_states}/zebras.rb +3 -3
  34. data/spec/integration/pact/consumer_configuration_spec.rb +3 -66
  35. data/spec/integration/pact/provider_configuration_spec.rb +1 -1
  36. data/spec/lib/pact/consumer/consumer_contract_builder_spec.rb +59 -15
  37. data/spec/lib/pact/consumer/dsl_spec.rb +4 -5
  38. data/spec/lib/pact/consumer/interaction_builder_spec.rb +91 -0
  39. data/spec/lib/pact/consumer/interactions_spec.rb +64 -0
  40. data/spec/lib/pact/consumer/mock_service_spec.rb +2 -6
  41. data/spec/lib/pact/consumer/service_consumer_spec.rb +1 -1
  42. data/spec/lib/pact/{consumer_contract_spec.rb → consumer_contract/consumer_contract_spec.rb} +72 -28
  43. data/spec/lib/pact/{consumer → consumer_contract}/interaction_spec.rb +49 -64
  44. data/spec/lib/pact/{producer/configuration_dsl_spec.rb → provider/dsl_spec.rb} +29 -28
  45. data/spec/lib/pact/{producer/producer_state_spec.rb → provider/provider_state_spec.rb} +17 -17
  46. data/spec/lib/pact/{producer → provider}/rspec_spec.rb +1 -1
  47. data/spec/lib/pact/verification_task_spec.rb +3 -3
  48. data/spec/spec_helper.rb +1 -0
  49. data/spec/support/a_consumer-a_producer.json +1 -1
  50. data/spec/support/a_consumer-a_provider.json +34 -0
  51. data/spec/support/consumer_contract_template.json +26 -0
  52. data/spec/support/factories.rb +78 -0
  53. data/spec/support/pact_rake_support.rb +1 -1
  54. data/spec/support/test_app_fail.json +1 -1
  55. data/spec/support/test_app_pass.json +1 -1
  56. data/tasks/pact-test.rake +3 -3
  57. metadata +38 -45
  58. data/lib/pact/consumer/configuration_dsl.rb +0 -73
  59. data/lib/pact/consumer/interaction.rb +0 -74
  60. data/lib/pact/consumer/run_condor.rb +0 -4
  61. data/lib/pact/consumer/run_mock_contract_service.rb +0 -13
  62. data/lib/pact/consumer/service_consumer.rb +0 -22
  63. data/lib/pact/consumer/service_producer.rb +0 -23
  64. data/lib/pact/producer/configuration_dsl.rb +0 -62
  65. data/lib/pact/producer/rspec.rb +0 -129
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
  require 'pact/consumer/dsl'
3
- require 'pact/consumer/configuration_dsl'
4
3
 
5
4
  module Pact::Consumer::DSL
6
5
 
@@ -18,7 +17,7 @@ module Pact::Consumer::DSL
18
17
  end
19
18
  }
20
19
 
21
- let(:producer_name) { 'Mock Producer'}
20
+ let(:provider_name) { 'Mock Provider'}
22
21
  let(:consumer_contract_builder) { double('Pact::Consumer::ConsumerContractBuilder').as_null_object}
23
22
  let(:url) { "http://localhost:1234"}
24
23
 
@@ -26,7 +25,7 @@ module Pact::Consumer::DSL
26
25
  Pact::Consumer::ConsumerContractBuilder.stub(:new).and_return(consumer_contract_builder)
27
26
  subject.configure_consumer_contract_builder({})
28
27
  consumer_contract_builder.should_receive(:verify)
29
- Pact.configuration.producer_verifications.first.call
28
+ Pact.configuration.provider_verifications.first.call
30
29
  end
31
30
 
32
31
  context "when standalone" do
@@ -44,8 +43,8 @@ module Pact::Consumer::DSL
44
43
  end
45
44
  }
46
45
  it "registers the app with the AppManager" do
47
- Pact::Consumer::AppManager.instance.should_receive(:register_mock_service_for).with(producer_name, url)
48
- subject.configure_consumer_contract_builder({:producer_name => producer_name })
46
+ Pact::Consumer::AppManager.instance.should_receive(:register_mock_service_for).with(provider_name, url)
47
+ subject.configure_consumer_contract_builder({:provider_name => provider_name })
49
48
  end
50
49
  end
51
50
  end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+ require 'pact/consumer/interaction_builder'
3
+
4
+ module Pact
5
+ module Consumer
6
+ describe InteractionBuilder do
7
+
8
+ subject { InteractionBuilder.new }
9
+ let(:interaction) { double('Interaction').as_null_object}
10
+
11
+ before do
12
+ Interaction.should_receive(:new).and_return(interaction)
13
+ end
14
+
15
+ describe "given" do
16
+ context "with a string provider state" do
17
+ it "sets the provider_state on the interaction" do
18
+ interaction.should_receive(:provider_state=).with('blah')
19
+ subject.given('blah')
20
+ end
21
+ end
22
+
23
+ context "with a symbol provider state" do
24
+ it "sets the provider_state on the interaction as a string" do
25
+ interaction.should_receive(:provider_state=).with('some_symbol')
26
+ subject.given(:some_symbol)
27
+ end
28
+ end
29
+
30
+ it "returns itself" do
31
+ expect(subject.given(nil)).to be(subject)
32
+ end
33
+ end
34
+
35
+ describe "upon_receiving" do
36
+ it "sets the description on the interaction" do
37
+ interaction.should_receive(:description=).with('blah')
38
+ subject.upon_receiving('blah')
39
+ end
40
+
41
+ it "returns itself" do
42
+ expect(subject.given(nil)).to be(subject)
43
+ end
44
+ end
45
+
46
+ describe "with" do
47
+
48
+ let(:request) { {a: 'request'} }
49
+ let(:expected_request) { {an: 'expected_request'} }
50
+
51
+ it "sets the request on the interaction as a instance of Request::Expected" do
52
+ Request::Expected.should_receive(:from_hash).with(request).and_return(expected_request)
53
+ interaction.should_receive(:request=).with(expected_request)
54
+ subject.with(request)
55
+ end
56
+
57
+ it "returns itself" do
58
+ expect(subject.given(nil)).to be(subject)
59
+ end
60
+ end
61
+
62
+ describe "will_respond_with" do
63
+ let(:response) { {a: 'response'} }
64
+
65
+ let(:provider) do
66
+ double(callback: nil)
67
+ end
68
+
69
+ before do
70
+ subject.on_interaction_fully_defined do | interaction |
71
+ provider.callback interaction
72
+ end
73
+ end
74
+
75
+ it "sets the response on the interaction" do
76
+ interaction.should_receive(:response=).with(response)
77
+ subject.will_respond_with(response)
78
+ end
79
+
80
+ it "returns itself" do
81
+ expect(subject.given(nil)).to be(subject)
82
+ end
83
+
84
+ it "invokes the 'on_interaction_fully_defined' callback" do
85
+ provider.should_receive(:callback).with(interaction)
86
+ subject.will_respond_with response
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+ require 'pact/consumer/interactions_filter'
3
+
4
+ module Pact::Consumer
5
+
6
+ describe 'Interactions' do
7
+ let(:interaction) { InteractionFactory.create }
8
+ let(:indentical_interaction) { InteractionFactory.create }
9
+ let(:interaction_with_diff_request) { InteractionFactory.create :request => {:path => '/different'} }
10
+ let(:interaction_with_diff_description) { InteractionFactory.create :description => 'blah' }
11
+ let(:interaction_with_diff_provider_state) { InteractionFactory.create :provider_state => 'blah' }
12
+ let(:interactions) { [interaction] }
13
+
14
+ shared_examples_for 'interactions' do
15
+
16
+ subject { described_class.new(interactions) }
17
+
18
+ describe "<<" do
19
+ context "when an interaction with the same provider state and description is not already included" do
20
+ it "adds the interaction" do
21
+ subject << interaction_with_diff_description
22
+ expect(interactions).to eq [interaction, interaction_with_diff_description]
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ describe UpdatableInteractionsFilter do
29
+ context "which, by default, is used when running rspec" do
30
+ include_examples 'interactions'
31
+ describe "<<" do
32
+ context "when an interaction with the same provider state and description is already included" do
33
+ it "overwrites the existing interaction, as the user has most likely just updated a test, and is rerunning the one spec" do
34
+ subject << interaction_with_diff_request
35
+ expect(interactions).to eq [interaction_with_diff_request]
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ describe DistinctInteractionsFilter do
43
+ context "which, by default, this is used when running rake" do
44
+ include_examples 'interactions'
45
+ describe "<<" do
46
+ context "when an interaction with the same provider state and description is already included" do
47
+ context "when the interactions are not equal" do
48
+ it "raises an error as the user has most likely copy/pasted an existing interaction and forgotten to update the description or provider state" do
49
+ expect{ subject << interaction_with_diff_request }.to raise_error 'Interaction with same description (a description) and provider state (a thing exists) already exists'
50
+ end
51
+ end
52
+ context "when the interactions are equal" do
53
+ it "does not add the interaction as it already exists" do
54
+ subject << indentical_interaction
55
+ expect(interactions).to eq [interaction]
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ end
@@ -4,15 +4,11 @@ require 'pact/consumer/mock_service'
4
4
  module Pact::Consumer
5
5
 
6
6
  describe InteractionList do
7
- before do
8
- InteractionList.instance.clear
9
- end
10
-
11
7
  shared_context "unexpected requests and missed interactions" do
12
8
  let(:expected_call) { {request: 'blah'} }
13
9
  let(:unexpected_call) { Pact::Request::Actual.from_hash(path: '/path', method: 'get') }
14
10
  subject {
15
- interactionList = InteractionList.instance
11
+ interactionList = InteractionList.new
16
12
  interactionList.add expected_call
17
13
  interactionList.register_unexpected unexpected_call
18
14
  interactionList
@@ -23,7 +19,7 @@ module Pact::Consumer
23
19
  let(:expected_call) { {request: 'blah'} }
24
20
  let(:unexpected_call) { Pact::Request::Actual.from_hash(path: '/path', method: 'get') }
25
21
  subject {
26
- interactionList = InteractionList.instance
22
+ interactionList = InteractionList.new
27
23
  interactionList.add expected_call
28
24
  interactionList.register_matched expected_call
29
25
  interactionList
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Pact::Consumer
3
+ module Pact
4
4
  describe ServiceConsumer do
5
5
  describe "as_json" do
6
6
  it "returns a hash representation of the object" do
@@ -27,9 +27,9 @@ module Pact
27
27
  end
28
28
 
29
29
  let(:service_consumer) { double('ServiceConsumer', :as_json => {:a => 'consumer'}) }
30
- let(:service_producer) { double('ServiceProducer', :as_json => {:a => 'producer'}) }
31
- let(:pact) { ConsumerContract.new({:interactions => [MockInteraction.new], :consumer => service_consumer, :producer => service_producer }) }
32
- let(:expected_as_json) { {:producer=>{:a=>"producer"}, :consumer=>{:a=>"consumer"}, :interactions=>[{:mock=>"interaction"}], :metadata=>{:pact_gem=>{:version=>"1.0"}}} }
30
+ let(:service_provider) { double('ServiceProvider', :as_json => {:a => 'provider'}) }
31
+ let(:pact) { ConsumerContract.new({:interactions => [MockInteraction.new], :consumer => service_consumer, :provider => service_provider }) }
32
+ let(:expected_as_json) { {:provider=>{:a=>"provider"}, :consumer=>{:a=>"consumer"}, :interactions=>[{:mock=>"interaction"}], :metadata=>{:pact_gem=>{:version=>"1.0"}}} }
33
33
 
34
34
  it "should return a hash representation of the Pact" do
35
35
  pact.as_json.should eq expected_as_json
@@ -56,67 +56,111 @@ module Pact
56
56
  end
57
57
 
58
58
  it "should have a consumer" do
59
- loaded_pact.consumer.should be_instance_of Pact::Consumer::ServiceConsumer
59
+ loaded_pact.consumer.should be_instance_of Pact::ServiceConsumer
60
60
  end
61
61
 
62
- it "should have a producer" do
63
- loaded_pact.producer.should be_instance_of Pact::Consumer::ServiceProducer
62
+ it "should have a provider" do
63
+ loaded_pact.provider.should be_instance_of Pact::ServiceProvider
64
+ end
65
+ end
66
+
67
+ context "with old 'producer' key" do
68
+ let(:string) { File.read('./spec/support/a_consumer-a_producer.json')}
69
+ it "should create a Pact" do
70
+ loaded_pact.should be_instance_of ConsumerContract
71
+ end
72
+
73
+ it "should have interactions" do
74
+ loaded_pact.interactions.should be_instance_of Array
75
+ end
76
+
77
+ it "should have a consumer" do
78
+ loaded_pact.consumer.should be_instance_of Pact::ServiceConsumer
79
+ end
80
+
81
+ it "should have a provider" do
82
+ loaded_pact.provider.should be_instance_of Pact::ServiceProvider
83
+ loaded_pact.provider.name.should eq "an old producer"
84
+ end
85
+
86
+ it "should have a provider_state" do
87
+ loaded_pact.interactions.first.provider_state.should eq 'state one'
64
88
  end
65
89
  end
66
90
  end
67
91
 
68
92
  describe "find_interactions" do
69
- let(:consumer) { double('ServiceConsumer', :name => 'Consumer')}
70
- let(:producer) { double('ServiceProducer', :name => 'Producer')}
71
- let(:interaction1) { Pact::Consumer::Interaction.new(:description => 'a request for food') }
72
- let(:interaction2) { Pact::Consumer::Interaction.new(:description => 'a request for drink') }
73
- subject { ConsumerContract.new(:interactions => [interaction1, interaction2], :consumer => consumer, :producer => producer) }
93
+ let(:consumer) { double('Pact::ServiceConsumer', :name => 'Consumer')}
94
+ let(:provider) { double('Pact::ServiceProvider', :name => 'Provider')}
95
+ let(:interaction) { double('Pact::Interaction') }
96
+ subject { ConsumerContract.new(:interactions => [interaction], :consumer => consumer, :provider => provider) }
97
+ let(:criteria) { {:description => /blah/} }
98
+ before do
99
+ interaction.should_receive(:matches_criteria?).with(criteria).and_return(matches)
100
+ end
74
101
  context "by description" do
75
102
  context "when no interactions are found" do
103
+ let(:matches) { false }
76
104
  it "returns an empty array" do
77
- expect(subject.find_interactions(:description => /blah/)).to eql []
105
+ expect(subject.find_interactions(criteria)).to eql []
78
106
  end
79
107
  end
80
108
  context "when interactions are found" do
109
+ let(:matches) { true }
81
110
  it "returns an array of the matching interactions" do
82
- expect(subject.find_interactions(:description => /request/)).to eql [interaction1, interaction2]
111
+ expect(subject.find_interactions(criteria)).to eql [interaction]
83
112
  end
84
113
  end
85
114
  end
86
115
  end
116
+
87
117
  describe "find_interaction" do
88
- let(:consumer) { double('ServiceConsumer', :name => 'Consumer')}
89
- let(:producer) { double('ServiceProducer', :name => 'Producer')}
90
- # Should be stubbing these
91
- let(:interaction1) { Pact::Consumer::Interaction.new(:description => 'a request for food') }
92
- let(:interaction2) { Pact::Consumer::Interaction.new(:description => 'a request for drink') }
93
- subject { ConsumerContract.new(:interactions => [interaction1, interaction2], :consumer => consumer, :producer => producer) }
118
+ let(:consumer) { double('Pact::ServiceConsumer', :name => 'Consumer')}
119
+ let(:provider) { double('Pact::ServiceProvider', :name => 'Provider')}
120
+ let(:interaction1) { double('Pact::Interaction') }
121
+ let(:interaction2) { double('Pact::Interaction') }
122
+ let(:criteria) { {:description => /blah/} }
123
+
124
+ before do
125
+ interaction1.should_receive(:matches_criteria?).with(criteria).and_return(matches1)
126
+ interaction2.should_receive(:matches_criteria?).with(criteria).and_return(matches2)
127
+ end
128
+
129
+ subject { ConsumerContract.new(:interactions => [interaction1, interaction2], :consumer => consumer, :provider => provider) }
94
130
  context "by description" do
95
131
  context "when a match is found" do
132
+ let(:matches1) { true }
133
+ let(:matches2) { false }
134
+
96
135
  it "returns the interaction" do
97
- expect(subject.find_interaction :description => /request.*food/).to eql interaction1
136
+ expect(subject.find_interaction criteria).to eql interaction1
98
137
  end
99
138
  end
100
139
  context "when more than one match is found" do
140
+ let(:matches1) { true }
141
+ let(:matches2) { true }
101
142
  it "raises an error" do
102
- expect{ subject.find_interaction(:description => /request/) }.to raise_error "Found more than 1 interaction matching {:description=>/request/} in pact file between Consumer and Producer."
143
+ expect{ subject.find_interaction(criteria) }.to raise_error "Found more than 1 interaction matching {:description=>/blah/} in pact file between Consumer and Provider."
103
144
  end
104
145
  end
105
146
  context "when a match is not found" do
147
+ let(:matches1) { false }
148
+ let(:matches2) { false }
106
149
  it "raises an error" do
107
- expect{ subject.find_interaction(:description => /blah/) }.to raise_error "Could not find interaction matching {:description=>/blah/} in pact file between Consumer and Producer."
150
+ expect{ subject.find_interaction(criteria) }.to raise_error "Could not find interaction matching {:description=>/blah/} in pact file between Consumer and Provider."
108
151
  end
109
152
  end
110
153
  end
111
154
  end
155
+
112
156
  describe "update_pactfile" do
113
157
  let(:pacts_dir) { Pathname.new("./tmp/pactfiles") }
114
158
  let(:expected_pact_path) { pacts_dir + "test_consumer-test_service.json" }
115
159
  let(:expected_pact_string) { 'the_json' }
116
- let(:consumer) { Pact::Consumer::ServiceConsumer.new(:name => 'test_consumer')}
117
- let(:producer) { Pact::Consumer::ServiceProducer.new(:name => 'test_service')}
160
+ let(:consumer) { Pact::ServiceConsumer.new(:name => 'test_consumer')}
161
+ let(:provider) { Pact::ServiceProvider.new(:name => 'test_service')}
118
162
  let(:interactions) { [double("interaction", as_json: "something")]}
119
- subject { ConsumerContract.new(:consumer => consumer, :producer => producer, :interactions => interactions) }
163
+ subject { ConsumerContract.new(:consumer => consumer, :provider => provider, :interactions => interactions) }
120
164
  before do
121
165
  Pact.configuration.stub(:pact_dir).and_return(Pathname.new("./tmp/pactfiles"))
122
166
  FileUtils.rm_rf pacts_dir
@@ -125,13 +169,13 @@ module Pact
125
169
  subject.update_pactfile
126
170
  end
127
171
 
128
- it "should write to a file specified by the consumer and producer name" do
172
+ it "should write to a file specified by the consumer and provider name" do
129
173
  File.exist?(expected_pact_path).should be_true
130
174
  end
131
175
 
132
176
  it "should write the interactions to the file" do
133
177
  File.read(expected_pact_path).should eql expected_pact_string
134
178
  end
135
- end
136
- end
179
+ end
180
+ end
137
181
  end
@@ -1,44 +1,42 @@
1
1
  require 'spec_helper'
2
+ require 'pact/reification'
3
+ require 'pact/consumer_contract/interaction'
2
4
 
3
5
  module Pact
4
6
  module Consumer
5
- describe InteractionBuilder do
6
7
 
7
- subject {
8
- interaction_builder = InteractionBuilder.new('Test request', nil).with(request)
9
- interaction_builder.on_interaction_fully_defined do | interaction |
10
- producer.callback interaction
11
- end
12
- interaction_builder
13
- }
14
-
15
- let(:pact_path) { File.expand_path('../../../../pacts/mock', __FILE__) }
16
-
17
- let(:request) do
18
- {
19
- method: 'post',
20
- path: '/foo',
21
- body: Term.new(generate: 'waffle', matcher: /ffl/),
22
- headers: { 'Content-Type' => 'application/json' },
23
- query: '',
24
- }
25
- end
26
-
27
- let(:response) do
28
- { baz: /qux/, wiffle: Term.new(generate: 'wiffle', matcher: /iff/) }
29
- end
8
+ describe Interaction do
30
9
 
31
- let(:producer) do
32
- double(callback: nil)
10
+ describe "==" do
11
+ subject { InteractionFactory.create }
12
+ context "when other is the same" do
13
+ let(:other) { InteractionFactory.create }
14
+ it "returns true" do
15
+ expect(subject == other).to be_true
16
+ end
17
+ end
18
+ context "when other is not the same" do
19
+ let(:other) { InteractionFactory.create(:request => {:path => '/a_different_path'}) }
20
+ it "returns false" do
21
+ expect(subject == other).to be_false
22
+ end
23
+ end
33
24
  end
34
25
 
35
- describe "setting up responses" do
36
-
37
- it "invokes the callback" do
38
- producer.should_receive(:callback).with(subject.interaction)
39
- subject.will_respond_with response
26
+ describe "matches_criteria?" do
27
+ subject { InteractionFactory.create(:description => 'a request for food') }
28
+ context "by description" do
29
+ context "when the interaction matches" do
30
+ it "returns true" do
31
+ expect(subject.matches_criteria?(:description => /request.*food/)).to be_true
32
+ end
33
+ end
34
+ context "when the interaction does not match" do
35
+ it "returns false" do
36
+ expect(subject.matches_criteria?(:description => /blah/)).to be_false
37
+ end
38
+ end
40
39
  end
41
-
42
40
  end
43
41
 
44
42
  describe "as_json_for_mock_service" do
@@ -46,7 +44,7 @@ module Pact
46
44
  let(:request) { double(Pact::Request::Expected, :as_json_with_options => {:opts => 'blah'})}
47
45
  let(:response) { double('response') }
48
46
  let(:generated_response ) { double('generated_response', :to_json => 'generated_response') }
49
- subject { Interaction.new(:description => 'description', :request => request, :response => response, :producer_state => 'some state')}
47
+ subject { Interaction.new(:description => 'description', :request => request, :response => response, :provider_state => 'some state')}
50
48
  let(:expected_hash) { {:response => generated_response, :request => as_json_with_options, :description => '' } }
51
49
 
52
50
  before do
@@ -62,8 +60,8 @@ module Pact
62
60
  expect(subject.as_json_for_mock_service[:request]).to eq as_json_with_options
63
61
  end
64
62
 
65
- it "includes the producer state" do
66
- expect(subject.as_json_for_mock_service[:producer_state]).to eq 'some state'
63
+ it "includes the provider state" do
64
+ expect(subject.as_json_for_mock_service[:provider_state]).to eq 'some state'
67
65
  end
68
66
 
69
67
  it "includes the description" do
@@ -71,19 +69,30 @@ module Pact
71
69
  end
72
70
 
73
71
  it "doesn't have any other keys" do
74
- expect(subject.as_json_for_mock_service.keys).to eq [:response, :request, :description, :producer_state]
72
+ expect(subject.as_json_for_mock_service.keys).to eq [:response, :request, :description, :provider_state]
75
73
  end
76
74
  end
77
75
 
78
76
  describe "to JSON" do
77
+ let(:request) do
78
+ {
79
+ method: 'post',
80
+ path: '/foo',
81
+ body: Term.new(generate: 'waffle', matcher: /ffl/),
82
+ headers: { 'Content-Type' => 'application/json' },
83
+ query: '',
84
+ }
85
+ end
86
+
87
+ let(:response) do
88
+ { baz: /qux/, wiffle: Term.new(generate: 'wiffle', matcher: /iff/) }
89
+ end
79
90
 
80
91
  let(:parsed_result) do
81
- JSON.load(JSON.dump(subject.interaction))
92
+ JSON.load(JSON.dump(subject))
82
93
  end
83
94
 
84
- before do
85
- subject.will_respond_with response
86
- end
95
+ subject { Interaction.from_hash('response' => response, 'request' => request) }
87
96
 
88
97
  it "contains the request" do
89
98
  expect(parsed_result['request']).to eq({
@@ -112,30 +121,6 @@ module Pact
112
121
 
113
122
  end
114
123
 
115
- context "with a producer_state" do
116
- context "described with a string" do
117
- subject {
118
- interaction_builder = InteractionBuilder.new('Test request', "there are no alligators").with(request)
119
- interaction_builder.on_interaction_fully_defined {}
120
- interaction_builder
121
- }
122
-
123
- it "includes the state name as a string" do
124
- expect(parsed_result['producer_state']).to eql("there are no alligators")
125
- end
126
- end
127
- context "described with a symbol" do
128
- subject {
129
- interaction_builder = InteractionBuilder.new('Test request', :there_are_no_alligators).with(request)
130
- interaction_builder.on_interaction_fully_defined {}
131
- interaction_builder
132
- }
133
-
134
- it "includes the state name as a symbol" do
135
- expect(parsed_result['producer_state']).to eql("there_are_no_alligators")
136
- end
137
- end
138
- end
139
124
  end
140
125
  end
141
126
  end