pact 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/CHANGELOG.md +31 -20
  2. data/Gemfile.lock +12 -12
  3. data/README.md +32 -16
  4. data/Rakefile +3 -3
  5. data/documentation/README.md +1 -0
  6. data/documentation/development-workflow.md +22 -0
  7. data/documentation/faq.md +8 -0
  8. data/documentation/provider-states.md +2 -0
  9. data/documentation/troubleshooting.md +4 -0
  10. data/documentation/verifying-pacts.md +97 -0
  11. data/lib/pact/app.rb +98 -4
  12. data/lib/pact/consumer/rspec.rb +3 -2
  13. data/lib/pact/doc/doc_file.rb +4 -4
  14. data/lib/pact/doc/generator.rb +3 -3
  15. data/lib/pact/doc/interaction_view_model.rb +1 -0
  16. data/lib/pact/doc/markdown/{interactions_renderer.rb → consumer_contract_renderer.rb} +1 -1
  17. data/lib/pact/doc/markdown/generator.rb +2 -2
  18. data/lib/pact/matchers/unix_diff_formatter.rb +1 -1
  19. data/lib/pact/project_root.rb +7 -0
  20. data/lib/pact/provider.rb +0 -1
  21. data/lib/pact/provider/context.rb +0 -0
  22. data/lib/pact/provider/matchers/messages.rb +15 -13
  23. data/lib/pact/provider/pact_spec_runner.rb +21 -22
  24. data/lib/pact/provider/rspec.rb +22 -15
  25. data/lib/pact/provider/rspec/custom_options_file +0 -0
  26. data/lib/pact/provider/{matchers.rb → rspec/matchers.rb} +2 -1
  27. data/lib/pact/rspec.rb +20 -0
  28. data/lib/pact/shared/request.rb +1 -1
  29. data/lib/pact/tasks/task_helper.rb +18 -15
  30. data/lib/pact/tasks/verification_task.rb +26 -32
  31. data/lib/pact/version.rb +1 -1
  32. data/lib/tasks/pact.rake +5 -11
  33. data/spec/integration/pact/consumer_configuration_spec.rb +3 -3
  34. data/spec/lib/pact/app_spec.rb +47 -0
  35. data/spec/lib/pact/consumer/app_manager_spec.rb +1 -1
  36. data/spec/lib/pact/consumer/mock_service/interaction_list_spec.rb +3 -3
  37. data/spec/lib/pact/consumer/mock_service/verification_get_spec.rb +10 -2
  38. data/spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb +2 -2
  39. data/spec/lib/pact/consumer_contract/consumer_contract_spec.rb +1 -1
  40. data/spec/lib/pact/consumer_contract/interaction_spec.rb +4 -4
  41. data/spec/lib/pact/consumer_contract/request_spec.rb +23 -23
  42. data/spec/lib/pact/doc/generator_spec.rb +4 -4
  43. data/spec/lib/pact/doc/markdown/{interactions_renderer_spec.rb → consumer_contract_renderer_spec.rb} +4 -4
  44. data/spec/lib/pact/matchers/unix_diff_formatter_spec.rb +8 -8
  45. data/spec/lib/pact/provider/configuration/configuration_extension_spec.rb +2 -2
  46. data/spec/lib/pact/provider/matchers/messages_spec.rb +17 -6
  47. data/spec/lib/pact/provider/rspec/formatter_spec.rb +3 -1
  48. data/spec/lib/pact/shared/dsl_spec.rb +1 -1
  49. data/spec/lib/pact/shared/request_spec.rb +8 -0
  50. data/spec/lib/pact/tasks/task_helper_spec.rb +39 -54
  51. data/spec/lib/pact/tasks/verification_task_spec.rb +75 -0
  52. data/spec/pact_specification/compliance-1.0.0.rb +47 -0
  53. data/spec/spec_helper.rb +2 -6
  54. data/spec/standalone/consumer_fail_test.rb +1 -0
  55. data/spec/standalone/consumer_pass_test.rb +1 -0
  56. data/spec/support/active_support_if_configured.rb +6 -0
  57. data/spec/support/pact_helper.rb +2 -1
  58. data/spec/support/shared_examples_for_request.rb +15 -4
  59. data/spec/support/spec_support.rb +3 -0
  60. data/spec/support/stubbing_using_allow.rb +1 -0
  61. data/spec/support/term.json +13 -1
  62. data/tasks/pact-test.rake +45 -26
  63. metadata +23 -13
  64. data/lib/pact/provider/client_project_pact_helper.rb +0 -4
  65. data/spec/lib/pact/provider/pact_spec_runner_spec.rb +0 -7
  66. data/spec/lib/pact/verification_task_spec.rb +0 -99
@@ -1,3 +1,3 @@
1
1
  module Pact
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -3,32 +3,26 @@ namespace :pact do
3
3
 
4
4
  desc "Verifies the pact files configured in the pact_helper.rb against this service provider."
5
5
  task :verify do
6
- require 'pact/provider'
6
+
7
7
  require 'pact/tasks/task_helper'
8
- require 'pact/provider/client_project_pact_helper'
9
8
 
10
9
  include Pact::TaskHelper
11
10
 
12
11
  handle_verification_failure do
13
- options = {criteria: spec_criteria}
14
- pact_verifications = Pact.configuration.pact_verifications
15
- verification_configs = pact_verifications.collect { | pact_verification | { :uri => pact_verification.uri }}
16
- raise "Please configure a pact to verify" if verification_configs.empty?
17
- Pact::Provider::PactSpecRunner.new(verification_configs, options).run
12
+ execute_pact_verify
18
13
  end
19
14
  end
20
15
 
21
16
  desc "Verifies the pact at the given URI against this service provider."
22
17
  task 'verify:at', :pact_uri do | t, args |
23
- require 'pact/provider'
18
+ require 'term/ansicolor'
24
19
  require 'pact/tasks/task_helper'
25
20
 
26
21
  include Pact::TaskHelper
27
22
 
23
+ abort(::Term::ANSIColor.red("Please provide a pact URI. eg. rake pact:verify:at[../my-consumer/spec/pacts/my_consumer-my_provider.json]")) unless args[:pact_uri]
28
24
  handle_verification_failure do
29
- puts "Verifying pact at uri #{args[:pact_uri]}"
30
- options = {criteria: spec_criteria}
31
- Pact::Provider::PactSpecRunner.new([{uri: args[:pact_uri]}], options).run
25
+ execute_pact_verify args[:pact_uri]
32
26
  end
33
27
  end
34
28
 
@@ -53,7 +53,7 @@ describe "consumer side" do
53
53
  end
54
54
 
55
55
  it "should have registered the app" do
56
- Pact::Consumer::AppManager.instance.app_registered_on?(1111).should be_true
56
+ Pact::Consumer::AppManager.instance.app_registered_on?(1111).should be true
57
57
  end
58
58
  end
59
59
 
@@ -67,13 +67,13 @@ describe "consumer side" do
67
67
 
68
68
  context "when standalone is true" do
69
69
  it "is not registerd with the AppManager" do
70
- Pact::Consumer::AppManager.instance.app_registered_on?(1234).should be_false
70
+ Pact::Consumer::AppManager.instance.app_registered_on?(1234).should be false
71
71
  end
72
72
  end
73
73
 
74
74
  context "when standalone is false" do
75
75
  it "should register the MockServices on their given ports if they are not" do
76
- Pact::Consumer::AppManager.instance.app_registered_on?(1235).should be_true
76
+ Pact::Consumer::AppManager.instance.app_registered_on?(1235).should be true
77
77
  end
78
78
  end
79
79
  end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ require 'pact/app'
3
+
4
+ module Pact
5
+ describe SpecCriteria do
6
+
7
+ describe "#spec_criteria" do
8
+
9
+ let(:env_description) { "pact description set in ENV"}
10
+ let(:env_provider_state) { "provider state set in ENV"}
11
+ let(:env_criteria){ {:description=>/#{env_description}/, :provider_state=>/#{env_provider_state}/} }
12
+
13
+ let(:defaults) { {:description => default_description, :provider_state => default_provider_state} }
14
+
15
+ let(:subject) { Pact::App.new }
16
+
17
+ context "when ENV variables are defined" do
18
+ before do
19
+ ENV.stub(:[])
20
+ ENV.stub(:[]).with("PACT_DESCRIPTION").and_return(env_description)
21
+ ENV.stub(:[]).with("PACT_PROVIDER_STATE").and_return(env_provider_state)
22
+ end
23
+
24
+ it "returns the env vars as regexes" do
25
+ expect(SpecCriteria.call).to eq(env_criteria)
26
+ end
27
+ end
28
+
29
+ context "when ENV variables are not defined" do
30
+ it "returns an empty hash" do
31
+ expect(SpecCriteria.call).to eq({})
32
+ end
33
+ end
34
+
35
+ context "when provider state is an empty string" do
36
+ before do
37
+ ENV.stub(:[]).with(anything).and_return(nil)
38
+ ENV.stub(:[]).with("PACT_PROVIDER_STATE").and_return('')
39
+ end
40
+
41
+ it "returns a nil provider state so that it matches a nil provider state on the interaction" do
42
+ expect(SpecCriteria.call[:provider_state]).to be_nil
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -21,7 +21,7 @@ module Pact::Consumer
21
21
 
22
22
  it "registers the mock service as running on the given port" do
23
23
  AppManager.instance.register_mock_service_for name, url
24
- AppManager.instance.app_registered_on?(1234).should be_true
24
+ AppManager.instance.app_registered_on?(1234).should be true
25
25
  end
26
26
  end
27
27
  context "for https://" do
@@ -34,7 +34,7 @@ module Pact::Consumer
34
34
  include_context "unexpected requests and missed interactions"
35
35
  let(:expected_diff) {
36
36
  {:missing_interactions=>["GET /path"],
37
- :unexpected_requests=>["PUT /path"],
37
+ :unexpected_requests=>["PUT /path?query"],
38
38
  :interaction_mismatches => ['blah']}
39
39
  }
40
40
  it "returns the unexpected requests and missed interactions" do
@@ -57,13 +57,13 @@ module Pact::Consumer
57
57
  context "when unexpected requests or missed interactions exist" do
58
58
  include_context "unexpected requests and missed interactions"
59
59
  it "returns false" do
60
- expect(subject.all_matched?).to be_false
60
+ expect(subject.all_matched?).to be false
61
61
  end
62
62
  end
63
63
  context "when unexpected requests or missed interactions do not exist" do
64
64
  include_context "no unexpected requests or missed interactions exist"
65
65
  it "returns false" do
66
- expect(subject.all_matched?).to be_true
66
+ expect(subject.all_matched?).to be true
67
67
  end
68
68
  end
69
69
  end
@@ -11,9 +11,17 @@ module Pact
11
11
 
12
12
  subject { VerificationGet.new('VerificationGet', logger, interaction_list, log_description) }
13
13
 
14
- its(:request_path) { should eq '/verify'}
15
- its(:request_method) { should eq 'GET'}
14
+ describe "request_path" do
15
+ it "is /verify" do
16
+ expect(subject.request_path).to eq '/verify'
17
+ end
18
+ end
16
19
 
20
+ describe "request_method" do
21
+ it "is GET" do
22
+ expect(subject.request_method).to eq 'GET'
23
+ end
24
+ end
17
25
 
18
26
  describe "#respond" do
19
27
  let(:env) { {
@@ -39,7 +39,7 @@ describe Pact::Consumer::MockServiceInteractionExpectation do
39
39
 
40
40
  context "without options" do
41
41
  it "does not include the options key" do
42
- expect(subject.as_json.key?(:options)).to be_false
42
+ expect(subject.as_json.key?(:options)).to be false
43
43
  end
44
44
  end
45
45
 
@@ -50,5 +50,5 @@ describe Pact::Consumer::MockServiceInteractionExpectation do
50
50
  end
51
51
  end
52
52
  end
53
-
53
+
54
54
  end
@@ -169,7 +169,7 @@ eos
169
169
  end
170
170
 
171
171
  it "should write to a file specified by the consumer and provider name" do
172
- File.exist?(expected_pact_path).should be_true
172
+ File.exist?(expected_pact_path).should be true
173
173
  end
174
174
 
175
175
  it "should write the interactions to the file" do
@@ -12,13 +12,13 @@ module Pact
12
12
  context "when other is the same" do
13
13
  let(:other) { InteractionFactory.create }
14
14
  it "returns true" do
15
- expect(subject == other).to be_true
15
+ expect(subject == other).to be true
16
16
  end
17
17
  end
18
18
  context "when other is not the same" do
19
19
  let(:other) { InteractionFactory.create(:request => {:path => '/a_different_path'}) }
20
20
  it "returns false" do
21
- expect(subject == other).to be_false
21
+ expect(subject == other).to be false
22
22
  end
23
23
  end
24
24
  end
@@ -28,12 +28,12 @@ module Pact
28
28
  context "by description" do
29
29
  context "when the interaction matches" do
30
30
  it "returns true" do
31
- expect(subject.matches_criteria?(:description => /request.*food/)).to be_true
31
+ expect(subject.matches_criteria?(:description => /request.*food/)).to be true
32
32
  end
33
33
  end
34
34
  context "when the interaction does not match" do
35
35
  it "returns false" do
36
- expect(subject.matches_criteria?(:description => /blah/)).to be_false
36
+ expect(subject.matches_criteria?(:description => /blah/)).to be false
37
37
  end
38
38
  end
39
39
  end
@@ -24,13 +24,13 @@ module Pact
24
24
  expect(subject.headers).to be_instance_of(Pact::NullExpectation)
25
25
  end
26
26
  end
27
- end
27
+ end
28
28
 
29
29
  describe "as_json" do
30
30
  subject { Request::Expected.new(:get, '/path', {:header => 'value'}, {:body => 'yeah'}, "query", {some: 'options'}) }
31
31
  context "with options" do
32
32
  it "does not include the options because they are a temporary hack and should leave no trace of themselves in the pact file" do
33
- expect(subject.as_json.key?(:options)).to be_false
33
+ expect(subject.as_json.key?(:options)).to be false
34
34
  end
35
35
  end
36
36
  end
@@ -55,7 +55,7 @@ module Pact
55
55
  let(:actual_query) { '' }
56
56
 
57
57
  it "matches identical requests" do
58
- expect(subject.matches? actual_request).to be_true
58
+ expect(subject.matches? actual_request).to be true
59
59
  end
60
60
 
61
61
  context "when the methods are the same but one is symbolized" do
@@ -63,7 +63,7 @@ module Pact
63
63
  let(:actual_method) { 'get' }
64
64
 
65
65
  it "matches" do
66
- expect(subject.matches? actual_request).to be_true
66
+ expect(subject.matches? actual_request).to be true
67
67
  end
68
68
  end
69
69
 
@@ -72,7 +72,7 @@ module Pact
72
72
  let(:actual_method) { 'post' }
73
73
 
74
74
  it "does not match" do
75
- expect(subject.matches? actual_request).to be_false
75
+ expect(subject.matches? actual_request).to be false
76
76
  end
77
77
  end
78
78
 
@@ -81,7 +81,7 @@ module Pact
81
81
  let(:actual_path) { '/bar' }
82
82
 
83
83
  it "does not match" do
84
- expect(subject.matches? actual_request).to be_false
84
+ expect(subject.matches? actual_request).to be false
85
85
  end
86
86
  end
87
87
 
@@ -90,7 +90,7 @@ module Pact
90
90
  let(:actual_path) { '/foo/' }
91
91
 
92
92
  it "matches" do
93
- expect(subject.matches? actual_request).to be_true
93
+ expect(subject.matches? actual_request).to be true
94
94
  end
95
95
  end
96
96
 
@@ -99,7 +99,7 @@ module Pact
99
99
  let(:actual_body) { '' }
100
100
 
101
101
  it "does not match" do
102
- expect(subject.matches? actual_request).to be_false
102
+ expect(subject.matches? actual_request).to be false
103
103
  end
104
104
  end
105
105
 
@@ -108,7 +108,7 @@ module Pact
108
108
  let(:actual_body) { '' }
109
109
 
110
110
  it "matches" do
111
- expect(subject.matches? actual_request).to be_true
111
+ expect(subject.matches? actual_request).to be true
112
112
  end
113
113
  end
114
114
 
@@ -122,7 +122,7 @@ module Pact
122
122
  let(:actual_body) { nil }
123
123
 
124
124
  it "does not match" do
125
- expect(subject.matches? actual_request).to be_false
125
+ expect(subject.matches? actual_request).to be false
126
126
  end
127
127
  end
128
128
 
@@ -131,7 +131,7 @@ module Pact
131
131
  let(:actual_body) { 'bar' }
132
132
 
133
133
  it "does not match" do
134
- expect(subject.matches? actual_request).to be_false
134
+ expect(subject.matches? actual_request).to be false
135
135
  end
136
136
  end
137
137
 
@@ -151,7 +151,7 @@ module Pact
151
151
  end
152
152
 
153
153
  it "matches" do
154
- expect(subject.matches? actual_request).to be_true
154
+ expect(subject.matches? actual_request).to be true
155
155
  end
156
156
  end
157
157
 
@@ -171,7 +171,7 @@ module Pact
171
171
  end
172
172
 
173
173
  it "does not match" do
174
- expect(subject.matches? actual_request).to be_false
174
+ expect(subject.matches? actual_request).to be false
175
175
  end
176
176
  end
177
177
 
@@ -191,7 +191,7 @@ module Pact
191
191
  end
192
192
 
193
193
  it "matches" do
194
- expect(subject.matches? actual_request).to be_true
194
+ expect(subject.matches? actual_request).to be true
195
195
  end
196
196
  end
197
197
 
@@ -211,7 +211,7 @@ module Pact
211
211
  end
212
212
 
213
213
  it "does not match" do
214
- expect(subject.matches? actual_request).to be_false
214
+ expect(subject.matches? actual_request).to be false
215
215
  end
216
216
  end
217
217
 
@@ -231,7 +231,7 @@ module Pact
231
231
  end
232
232
 
233
233
  it "does not match" do
234
- expect(subject.matches? actual_request).to be_false
234
+ expect(subject.matches? actual_request).to be false
235
235
  end
236
236
  end
237
237
  context "when the expected body contains non-matching hash where one field contains a substring of the other" do
@@ -248,7 +248,7 @@ module Pact
248
248
  end
249
249
 
250
250
  it "does not match" do
251
- expect(subject.matches? actual_request).to be_false
251
+ expect(subject.matches? actual_request).to be false
252
252
  end
253
253
  end
254
254
 
@@ -268,7 +268,7 @@ module Pact
268
268
  end
269
269
 
270
270
  it "does not match" do
271
- expect(subject.matches? actual_request).to be_true
271
+ expect(subject.matches? actual_request).to be true
272
272
  end
273
273
  end
274
274
 
@@ -277,7 +277,7 @@ module Pact
277
277
  let(:actual_query) { 'bar' }
278
278
 
279
279
  it "does not match" do
280
- expect(subject.matches? actual_request).to be_false
280
+ expect(subject.matches? actual_request).to be false
281
281
  end
282
282
  end
283
283
 
@@ -286,7 +286,7 @@ module Pact
286
286
  let(:actual_query) { 'bar' }
287
287
 
288
288
  it 'matches' do
289
- expect(subject.matches? actual_request).to be_true
289
+ expect(subject.matches? actual_request).to be true
290
290
  end
291
291
  end
292
292
 
@@ -295,7 +295,7 @@ module Pact
295
295
  let(:expected_body) { { thing: "123" } }
296
296
 
297
297
  it 'does not match' do
298
- expect(subject.matches? actual_request).to be_false
298
+ expect(subject.matches? actual_request).to be false
299
299
  end
300
300
  end
301
301
 
@@ -305,13 +305,13 @@ module Pact
305
305
  context "when allowing unexpected keys" do
306
306
  let(:options) { {'allow_unexpected_keys_in_body' => true} } #From json, these will be strings
307
307
  it "matches" do
308
- expect(subject.matches? actual_request).to be_true
308
+ expect(subject.matches? actual_request).to be true
309
309
  end
310
310
  end
311
311
  context "when not allowing unexpected keys" do
312
312
  let(:options) { {'allow_unexpected_keys_in_body' => false} }
313
313
  it "does not match" do
314
- expect(subject.matches? actual_request).to be_false
314
+ expect(subject.matches? actual_request).to be false
315
315
  end
316
316
  end
317
317
  end
@@ -9,7 +9,7 @@ module Pact
9
9
  let(:doc_dir) { './tmp/doc' }
10
10
  let(:pact_dir) { './tmp/pacts' }
11
11
  let(:file_name) { "Some Consumer - Some Provider#{file_extension}" }
12
- let(:interactions_renderer) { double("InteractionsRenderer", :call => doc_content) }
12
+ let(:consumer_contract_renderer) { double("ConsumerContractRenderer", :call => doc_content) }
13
13
  let(:doc_content) { "doc_content" }
14
14
  let(:index_content) { "index_content" }
15
15
  let(:expected_doc_path) { "#{doc_dir}/#{doc_type}/#{file_name}" }
@@ -30,7 +30,7 @@ module Pact
30
30
  FileUtils.cp './spec/support/markdown_pact.json', pact_dir
31
31
  end
32
32
 
33
- let(:options) { { interactions_renderer: interactions_renderer, doc_type: doc_type, file_extension: file_extension, index_renderer: index_renderer, index_name: index_name } }
33
+ let(:options) { { consumer_contract_renderer: consumer_contract_renderer, doc_type: doc_type, file_extension: file_extension, index_renderer: index_renderer, index_name: index_name } }
34
34
 
35
35
  subject { Generator.new(pact_dir, doc_dir, options) }
36
36
 
@@ -43,9 +43,9 @@ module Pact
43
43
  end
44
44
 
45
45
  it "clears the existing files" do
46
- expect(File.exist?(existing_doc_file_path)).to be_true
46
+ expect(File.exist?(existing_doc_file_path)).to be true
47
47
  subject.call
48
- expect(File.exist?(existing_doc_file_path)).to be_false
48
+ expect(File.exist?(existing_doc_file_path)).to be false
49
49
  end
50
50
  end
51
51