pact 1.3.3 → 1.4.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 (212) hide show
  1. data/CHANGELOG.md +37 -1
  2. data/lib/pact/cli.rb +0 -26
  3. data/lib/pact/consumer/configuration/configuration_extensions.rb +51 -0
  4. data/lib/pact/consumer/configuration/mock_service.rb +2 -1
  5. data/lib/pact/consumer/configuration.rb +0 -1
  6. data/lib/pact/consumer/consumer_contract_builder.rb +3 -3
  7. data/lib/pact/consumer/interaction_builder.rb +3 -5
  8. data/lib/pact/doc/interaction_view_model.rb +9 -6
  9. data/lib/pact/doc/sort_interactions.rb +1 -1
  10. data/lib/pact/provider/configuration/configuration_extension.rb +0 -9
  11. data/lib/pact/provider/rspec.rb +11 -9
  12. data/lib/pact/version.rb +1 -1
  13. data/lib/pact.rb +6 -5
  14. data/pact.gemspec +6 -2
  15. metadata +57 -304
  16. data/.gitignore +0 -29
  17. data/.rspec +0 -2
  18. data/.ruby-version +0 -1
  19. data/.travis.yml +0 -8
  20. data/Gemfile +0 -4
  21. data/Gemfile.lock +0 -86
  22. data/README.md +0 -313
  23. data/Rakefile +0 -9
  24. data/config.ru +0 -3
  25. data/documentation/README.md +0 -13
  26. data/documentation/configuration.md +0 -166
  27. data/documentation/diff_formatter_embedded.png +0 -0
  28. data/documentation/diff_formatter_list.png +0 -0
  29. data/documentation/diff_formatter_unix.png +0 -0
  30. data/example/animal-service/Gemfile +0 -14
  31. data/example/animal-service/Gemfile.lock +0 -69
  32. data/example/animal-service/Rakefile +0 -5
  33. data/example/animal-service/config.ru +0 -3
  34. data/example/animal-service/db/animal_db.sqlite3 +0 -0
  35. data/example/animal-service/lib/animal_service/animal_repository.rb +0 -12
  36. data/example/animal-service/lib/animal_service/api.rb +0 -28
  37. data/example/animal-service/lib/animal_service/db.rb +0 -5
  38. data/example/animal-service/spec/service_consumers/pact_helper.rb +0 -11
  39. data/example/animal-service/spec/service_consumers/provider_states_for_zoo_app.rb +0 -26
  40. data/example/zoo-app/Gemfile +0 -12
  41. data/example/zoo-app/Gemfile.lock +0 -63
  42. data/example/zoo-app/Rakefile +0 -5
  43. data/example/zoo-app/doc/pacts/markdown/README.md +0 -3
  44. data/example/zoo-app/doc/pacts/markdown/Zoo App - Animal Service.md +0 -75
  45. data/example/zoo-app/lib/zoo_app/animal_service_client.rb +0 -40
  46. data/example/zoo-app/lib/zoo_app/models/alligator.rb +0 -15
  47. data/example/zoo-app/spec/pacts/zoo_app-animal_service.json +0 -67
  48. data/example/zoo-app/spec/service_providers/animal_service_client_spec.rb +0 -71
  49. data/example/zoo-app/spec/service_providers/pact_helper.rb +0 -15
  50. data/example/zoo-app/spec/spec_helper.rb +0 -6
  51. data/lib/pact/configuration.rb +0 -195
  52. data/lib/pact/consumer/app_manager.rb +0 -158
  53. data/lib/pact/consumer/interactions_filter.rb +0 -48
  54. data/lib/pact/consumer/mock_service/app.rb +0 -82
  55. data/lib/pact/consumer/mock_service/interaction_delete.rb +0 -33
  56. data/lib/pact/consumer/mock_service/interaction_list.rb +0 -76
  57. data/lib/pact/consumer/mock_service/interaction_mismatch.rb +0 -73
  58. data/lib/pact/consumer/mock_service/interaction_post.rb +0 -31
  59. data/lib/pact/consumer/mock_service/interaction_replay.rb +0 -139
  60. data/lib/pact/consumer/mock_service/log_get.rb +0 -28
  61. data/lib/pact/consumer/mock_service/missing_interactions_get.rb +0 -30
  62. data/lib/pact/consumer/mock_service/mock_service_administration_endpoint.rb +0 -31
  63. data/lib/pact/consumer/mock_service/pact_post.rb +0 -33
  64. data/lib/pact/consumer/mock_service/rack_request_helper.rb +0 -51
  65. data/lib/pact/consumer/mock_service/verification_get.rb +0 -68
  66. data/lib/pact/consumer/mock_service.rb +0 -2
  67. data/lib/pact/consumer/mock_service_client.rb +0 -65
  68. data/lib/pact/consumer/mock_service_interaction_expectation.rb +0 -37
  69. data/lib/pact/consumer/request.rb +0 -27
  70. data/lib/pact/consumer/server.rb +0 -90
  71. data/lib/pact/consumer_contract/consumer_contract.rb +0 -115
  72. data/lib/pact/consumer_contract/consumer_contract_writer.rb +0 -84
  73. data/lib/pact/consumer_contract/file_name.rb +0 -19
  74. data/lib/pact/consumer_contract/headers.rb +0 -51
  75. data/lib/pact/consumer_contract/interaction.rb +0 -67
  76. data/lib/pact/consumer_contract/pact_file.rb +0 -24
  77. data/lib/pact/consumer_contract/request.rb +0 -73
  78. data/lib/pact/consumer_contract/service_consumer.rb +0 -28
  79. data/lib/pact/consumer_contract/service_provider.rb +0 -28
  80. data/lib/pact/consumer_contract.rb +0 -1
  81. data/lib/pact/logging.rb +0 -14
  82. data/lib/pact/matchers/actual_type.rb +0 -16
  83. data/lib/pact/matchers/base_difference.rb +0 -37
  84. data/lib/pact/matchers/differ.rb +0 -153
  85. data/lib/pact/matchers/difference.rb +0 -13
  86. data/lib/pact/matchers/difference_indicator.rb +0 -26
  87. data/lib/pact/matchers/embedded_diff_formatter.rb +0 -62
  88. data/lib/pact/matchers/expected_type.rb +0 -35
  89. data/lib/pact/matchers/index_not_found.rb +0 -15
  90. data/lib/pact/matchers/list_diff_formatter.rb +0 -101
  91. data/lib/pact/matchers/matchers.rb +0 -139
  92. data/lib/pact/matchers/no_diff_indicator.rb +0 -18
  93. data/lib/pact/matchers/regexp_difference.rb +0 -13
  94. data/lib/pact/matchers/type_difference.rb +0 -16
  95. data/lib/pact/matchers/unexpected_index.rb +0 -11
  96. data/lib/pact/matchers/unexpected_key.rb +0 -11
  97. data/lib/pact/matchers/unix_diff_formatter.rb +0 -114
  98. data/lib/pact/matchers.rb +0 -1
  99. data/lib/pact/reification.rb +0 -28
  100. data/lib/pact/rspec.rb +0 -53
  101. data/lib/pact/shared/active_support_support.rb +0 -51
  102. data/lib/pact/shared/dsl.rb +0 -76
  103. data/lib/pact/shared/jruby_support.rb +0 -18
  104. data/lib/pact/shared/json_differ.rb +0 -15
  105. data/lib/pact/shared/key_not_found.rb +0 -15
  106. data/lib/pact/shared/null_expectation.rb +0 -31
  107. data/lib/pact/shared/request.rb +0 -80
  108. data/lib/pact/shared/text_differ.rb +0 -14
  109. data/lib/pact/something_like.rb +0 -49
  110. data/lib/pact/symbolize_keys.rb +0 -12
  111. data/lib/pact/term.rb +0 -85
  112. data/scratchpad.rb +0 -52
  113. data/spec/features/consumption_spec.rb +0 -114
  114. data/spec/features/production_spec.rb +0 -155
  115. data/spec/features/provider_states/zebras.rb +0 -28
  116. data/spec/integration/consumer_spec.rb +0 -212
  117. data/spec/integration/pact/consumer_configuration_spec.rb +0 -66
  118. data/spec/integration/pact/provider_configuration_spec.rb +0 -25
  119. data/spec/lib/pact/cli_spec.rb +0 -47
  120. data/spec/lib/pact/configuration_spec.rb +0 -297
  121. data/spec/lib/pact/consumer/app_manager_spec.rb +0 -41
  122. data/spec/lib/pact/consumer/configuration_spec.rb +0 -57
  123. data/spec/lib/pact/consumer/consumer_contract_builder_spec.rb +0 -69
  124. data/spec/lib/pact/consumer/interaction_builder_spec.rb +0 -91
  125. data/spec/lib/pact/consumer/interactions_spec.rb +0 -64
  126. data/spec/lib/pact/consumer/mock_service/app_spec.rb +0 -52
  127. data/spec/lib/pact/consumer/mock_service/interaction_list_spec.rb +0 -78
  128. data/spec/lib/pact/consumer/mock_service/interaction_mismatch_spec.rb +0 -70
  129. data/spec/lib/pact/consumer/mock_service/interaction_replay_spec.rb +0 -12
  130. data/spec/lib/pact/consumer/mock_service/rack_request_helper_spec.rb +0 -88
  131. data/spec/lib/pact/consumer/mock_service/verification_get_spec.rb +0 -142
  132. data/spec/lib/pact/consumer/mock_service_client_spec.rb +0 -88
  133. data/spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb +0 -54
  134. data/spec/lib/pact/consumer/request_spec.rb +0 -24
  135. data/spec/lib/pact/consumer/service_consumer_spec.rb +0 -11
  136. data/spec/lib/pact/consumer_contract/active_support_support_spec.rb +0 -58
  137. data/spec/lib/pact/consumer_contract/consumer_contract_spec.rb +0 -180
  138. data/spec/lib/pact/consumer_contract/consumer_contract_writer_spec.rb +0 -111
  139. data/spec/lib/pact/consumer_contract/headers_spec.rb +0 -107
  140. data/spec/lib/pact/consumer_contract/interaction_spec.rb +0 -107
  141. data/spec/lib/pact/consumer_contract/request_spec.rb +0 -329
  142. data/spec/lib/pact/doc/generator_spec.rb +0 -84
  143. data/spec/lib/pact/doc/interaction_view_model_spec.rb +0 -132
  144. data/spec/lib/pact/doc/markdown/consumer_contract_renderer_spec.rb +0 -29
  145. data/spec/lib/pact/doc/markdown/index_renderer_spec.rb +0 -29
  146. data/spec/lib/pact/matchers/differ_spec.rb +0 -214
  147. data/spec/lib/pact/matchers/difference_spec.rb +0 -22
  148. data/spec/lib/pact/matchers/embedded_diff_formatter_spec.rb +0 -90
  149. data/spec/lib/pact/matchers/index_not_found_spec.rb +0 -21
  150. data/spec/lib/pact/matchers/list_diff_formatter_spec.rb +0 -114
  151. data/spec/lib/pact/matchers/matchers_spec.rb +0 -500
  152. data/spec/lib/pact/matchers/regexp_difference_spec.rb +0 -20
  153. data/spec/lib/pact/matchers/type_difference_spec.rb +0 -34
  154. data/spec/lib/pact/matchers/unexpected_index_spec.rb +0 -20
  155. data/spec/lib/pact/matchers/unexpected_key_spec.rb +0 -20
  156. data/spec/lib/pact/matchers/unix_diff_formatter_spec.rb +0 -216
  157. data/spec/lib/pact/provider/configuration/configuration_extension_spec.rb +0 -30
  158. data/spec/lib/pact/provider/configuration/pact_verification_spec.rb +0 -43
  159. data/spec/lib/pact/provider/configuration/service_provider_config_spec.rb +0 -21
  160. data/spec/lib/pact/provider/configuration/service_provider_dsl_spec.rb +0 -108
  161. data/spec/lib/pact/provider/configuration_spec.rb +0 -50
  162. data/spec/lib/pact/provider/matchers/messages_spec.rb +0 -116
  163. data/spec/lib/pact/provider/pact_helper_locator_spec.rb +0 -54
  164. data/spec/lib/pact/provider/print_missing_provider_states_spec.rb +0 -19
  165. data/spec/lib/pact/provider/request_spec.rb +0 -78
  166. data/spec/lib/pact/provider/rspec/formatter_rspec_2_spec.rb +0 -68
  167. data/spec/lib/pact/provider/rspec/formatter_rspec_3_spec.rb +0 -72
  168. data/spec/lib/pact/provider/rspec_spec.rb +0 -55
  169. data/spec/lib/pact/provider/state/provider_state_manager_spec.rb +0 -89
  170. data/spec/lib/pact/provider/state/provider_state_proxy_spec.rb +0 -80
  171. data/spec/lib/pact/provider/state/provider_state_spec.rb +0 -213
  172. data/spec/lib/pact/provider/world_spec.rb +0 -41
  173. data/spec/lib/pact/reification_spec.rb +0 -67
  174. data/spec/lib/pact/shared/dsl_spec.rb +0 -86
  175. data/spec/lib/pact/shared/json_differ_spec.rb +0 -36
  176. data/spec/lib/pact/shared/key_not_found_spec.rb +0 -20
  177. data/spec/lib/pact/shared/request_spec.rb +0 -111
  178. data/spec/lib/pact/shared/text_differ_spec.rb +0 -54
  179. data/spec/lib/pact/something_like_spec.rb +0 -21
  180. data/spec/lib/pact/tasks/task_helper_spec.rb +0 -74
  181. data/spec/lib/pact/tasks/verification_task_spec.rb +0 -75
  182. data/spec/lib/pact/term_spec.rb +0 -89
  183. data/spec/pact_specification/compliance-1.0.0.rb +0 -47
  184. data/spec/spec_helper.rb +0 -22
  185. data/spec/standalone/consumer_fail_test.rb +0 -55
  186. data/spec/standalone/consumer_pass_test.rb +0 -51
  187. data/spec/support/a_consumer-a_producer.json +0 -32
  188. data/spec/support/a_consumer-a_provider.json +0 -32
  189. data/spec/support/active_support_if_configured.rb +0 -6
  190. data/spec/support/app_for_config_ru.rb +0 -4
  191. data/spec/support/consumer_contract_template.json +0 -24
  192. data/spec/support/dsl_spec_support.rb +0 -7
  193. data/spec/support/factories.rb +0 -82
  194. data/spec/support/generated_index.md +0 -4
  195. data/spec/support/generated_markdown.md +0 -55
  196. data/spec/support/interaction_view_model.json +0 -63
  197. data/spec/support/interaction_view_model_with_terms.json +0 -50
  198. data/spec/support/markdown_pact.json +0 -48
  199. data/spec/support/missing_provider_states_output.txt +0 -25
  200. data/spec/support/options.json +0 -21
  201. data/spec/support/options_app.rb +0 -15
  202. data/spec/support/pact_helper.rb +0 -57
  203. data/spec/support/shared_examples_for_request.rb +0 -94
  204. data/spec/support/spec_support.rb +0 -20
  205. data/spec/support/stubbing.json +0 -22
  206. data/spec/support/stubbing_using_allow.rb +0 -29
  207. data/spec/support/term.json +0 -48
  208. data/spec/support/test_app_fail.json +0 -61
  209. data/spec/support/test_app_pass.json +0 -38
  210. data/spec/support/test_app_with_right_content_type_differ.json +0 -23
  211. data/tasks/pact-test.rake +0 -109
  212. data/tasks/spec.rake +0 -8
@@ -1,107 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/consumer_contract/headers'
3
-
4
- module Pact
5
- describe Headers do
6
-
7
- describe "initialize" do
8
-
9
- context "with duplicate headers" do
10
-
11
- subject { Headers.new('Content-Type' => 'application/hippo', 'CONTENT-TYPE' => 'application/giraffe') }
12
-
13
- it "raises an error" do
14
- expect { subject }.to raise_error DuplicateHeaderError, /Content\-Type.*CONTENT\-TYPE/
15
- end
16
-
17
- end
18
-
19
- context "with a symbol as a header name" do
20
-
21
- subject { Headers.new(:'content-type' => 'application/hippo') }
22
-
23
- it "converts the header name to a String" do
24
- expect( subject.to_hash ).to eq 'content-type' => 'application/hippo'
25
- end
26
-
27
- end
28
-
29
- context "with a nil header name" do
30
-
31
- subject { Headers.new(nil => 'application/hippo') }
32
-
33
- it "raises an error" do
34
- expect{ subject }.to raise_error InvalidHeaderNameTypeError
35
- end
36
-
37
- end
38
-
39
- context "with a boolean header name" do
40
-
41
- subject { Headers.new(false => 'application/hippo') }
42
-
43
- it "raises an error" do
44
- expect{ subject }.to raise_error InvalidHeaderNameTypeError
45
- end
46
-
47
- end
48
-
49
- end
50
-
51
- describe "[]" do
52
-
53
- subject { Headers.new 'Content-Type' => 'application/hippo' }
54
-
55
- it "is case insensitive as HTTP headers are case insensitive" do
56
- expect(subject['Content-Type']).to eq('application/hippo')
57
- expect(subject['CONTENT-TYPE']).to eq('application/hippo')
58
- expect(subject['content-type']).to eq('application/hippo')
59
- end
60
-
61
- end
62
-
63
- describe "fetch" do
64
-
65
- subject { Headers.new 'Content-Type' => 'application/hippo' }
66
-
67
- it "is case insensitive as HTTP headers are case insensitive" do
68
- expect(subject.fetch('Content-Type')).to eq('application/hippo')
69
- expect(subject.fetch('CONTENT-TYPE')).to eq('application/hippo')
70
- expect(subject.fetch('content-type')).to eq('application/hippo')
71
- expect(subject.fetch('Content-Length','1')).to eq('1')
72
- expect { subject.fetch('Content-Length')}.to raise_error KeyError
73
- end
74
-
75
- end
76
-
77
- describe "key?" do
78
-
79
- subject { Headers.new 'Content-Type' => 'application/hippo' }
80
-
81
- it "is case insensitive as HTTP headers are case insensitive" do
82
- expect(subject.key?('CONTENT-TYPE')).to be true
83
- expect(subject.key?('CONTENT-LENGTH')).to be false
84
- end
85
- end
86
-
87
- describe "has_key?" do
88
-
89
- subject { Headers.new 'Content-Type' => 'application/hippo' }
90
-
91
- it "is case insensitive as HTTP headers are case insensitive" do
92
- expect(subject.has_key?('CONTENT-TYPE')).to be true
93
- expect(subject.has_key?('CONTENT-LENGTH')).to be false
94
- end
95
- end
96
-
97
- describe "[]=" do
98
-
99
- subject { Headers.new }
100
-
101
- it "does not allow modification" do
102
- expect{ subject['Content-Type'] = 'application/hippo' }.to raise_error /frozen/
103
- end
104
-
105
- end
106
- end
107
- end
@@ -1,107 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/reification'
3
- require 'pact/consumer_contract/interaction'
4
-
5
- module Pact
6
- module Consumer
7
-
8
- describe Interaction do
9
-
10
- let(:request) { {method: 'get', path: 'path'} }
11
- let(:response) { {} }
12
-
13
- describe "==" do
14
- subject { InteractionFactory.create }
15
- context "when other is the same" do
16
- let(:other) { InteractionFactory.create }
17
- it "returns true" do
18
- expect(subject == other).to be true
19
- end
20
- end
21
- context "when other is not the same" do
22
- let(:other) { InteractionFactory.create(:request => {:path => '/a_different_path'}) }
23
- it "returns false" do
24
- expect(subject == other).to be false
25
- end
26
- end
27
- end
28
-
29
- describe "matches_criteria?" do
30
- subject { InteractionFactory.create(:description => 'a request for food') }
31
- context "by description" do
32
- context "when the interaction matches" do
33
- it "returns true" do
34
- expect(subject.matches_criteria?(:description => /request.*food/)).to be true
35
- end
36
- end
37
- context "when the interaction does not match" do
38
- it "returns false" do
39
- expect(subject.matches_criteria?(:description => /blah/)).to be false
40
- end
41
- end
42
- end
43
- end
44
-
45
- describe "from_hash" do
46
- context "when providerState has been used instead of provider_state" do
47
-
48
- subject { Interaction.from_hash('response' => response, 'request' => request, 'providerState' => 'some state') }
49
-
50
- it "recognises the provider state" do
51
- expect(subject.provider_state).to eq 'some state'
52
- end
53
- end
54
- end
55
-
56
- describe "to JSON" do
57
- let(:request) do
58
- {
59
- method: 'post',
60
- path: '/foo',
61
- body: Term.new(generate: 'waffle', matcher: /ffl/),
62
- headers: { 'Content-Type' => 'application/json' },
63
- query: '',
64
- }
65
- end
66
-
67
- let(:response) do
68
- { baz: /qux/, wiffle: Term.new(generate: 'wiffle', matcher: /iff/) }
69
- end
70
-
71
- let(:parsed_result) do
72
- JSON.load(subject.to_json)
73
- end
74
-
75
- subject { Interaction.from_hash('response' => response, 'request' => request) }
76
-
77
- it "contains the request" do
78
- expect(parsed_result['request']).to eq({
79
- 'method' => 'post',
80
- 'path' => '/foo',
81
- 'headers' => {
82
- 'Content-Type' => 'application/json'
83
- },
84
- 'body' => Term.new(generate: 'waffle', matcher: /ffl/),
85
- 'query' => ''
86
- })
87
- end
88
-
89
- describe "response" do
90
-
91
- it "serialises regexes" do
92
- expect(parsed_result['response']['baz']).to eql /qux/
93
- end
94
-
95
- it "serialises terms" do
96
- term = Term.new(generate:'wiffle', matcher: /iff/)
97
- parsed_term = parsed_result['response']['wiffle']
98
- expect(term.matcher).to eql parsed_term.matcher
99
- expect(term.generate).to eql parsed_term.generate
100
- end
101
-
102
- end
103
-
104
- end
105
- end
106
- end
107
- end
@@ -1,329 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/consumer_contract/request'
3
- require 'pact/consumer/request'
4
- require 'support/shared_examples_for_request'
5
-
6
- module Pact
7
-
8
- describe Request::Expected do
9
- it_behaves_like "a request"
10
-
11
- let(:raw_request) do
12
- {
13
- 'method' => 'get',
14
- 'path' => '/mallory'
15
- }
16
- end
17
-
18
- describe "from_hash" do
19
- context "when optional field are not defined" do
20
- subject { described_class.from_hash(raw_request) }
21
- it "sets their values to NullExpectation" do
22
- expect(subject.body).to be_instance_of(Pact::NullExpectation)
23
- expect(subject.query).to be_instance_of(Pact::NullExpectation)
24
- expect(subject.headers).to be_instance_of(Pact::NullExpectation)
25
- end
26
- end
27
- end
28
-
29
- describe "as_json" do
30
- subject { Request::Expected.new(:get, '/path', {:header => 'value'}, {:body => 'yeah'}, "query", {some: 'options'}) }
31
- context "with options" do
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
34
- end
35
- end
36
- end
37
-
38
- describe "matching to actual requests" do
39
-
40
- subject { Request::Expected.new(expected_method, expected_path, expected_headers, expected_body, expected_query, options) }
41
- let(:options) { {} }
42
-
43
- let(:expected_method) { 'get' }
44
- let(:expected_path) { '/foo' }
45
- let(:expected_headers) { Pact::NullExpectation.new }
46
- let(:expected_body) { Pact::NullExpectation.new }
47
- let(:expected_query) { '' }
48
-
49
- let(:actual_request) { Consumer::Request::Actual.new(actual_method, actual_path, actual_headers, actual_body, actual_query) }
50
-
51
- let(:actual_method) { 'get' }
52
- let(:actual_path) { '/foo' }
53
- let(:actual_headers) { {} }
54
- let(:actual_body) { '' }
55
- let(:actual_query) { '' }
56
-
57
- it "matches identical requests" do
58
- expect(subject.matches? actual_request).to be true
59
- end
60
-
61
- context "when the methods are the same but one is symbolized" do
62
- let(:expected_method) { :get }
63
- let(:actual_method) { 'get' }
64
-
65
- it "matches" do
66
- expect(subject.matches? actual_request).to be true
67
- end
68
- end
69
-
70
- context "when the methods are different" do
71
- let(:expected_method) { 'get' }
72
- let(:actual_method) { 'post' }
73
-
74
- it "does not match" do
75
- expect(subject.matches? actual_request).to be false
76
- end
77
- end
78
-
79
- context "when the methods are the same but different case" do
80
- let(:expected_method) { 'get' }
81
- let(:actual_method) { 'GET' }
82
-
83
- it "matches" do
84
- expect(subject.matches? actual_request).to be true
85
- end
86
- end
87
-
88
- context "when the paths are different" do
89
- let(:expected_path) { '/foo' }
90
- let(:actual_path) { '/bar' }
91
-
92
- it "does not match" do
93
- expect(subject.matches? actual_request).to be false
94
- end
95
- end
96
-
97
- context "when the paths vary only by a trailing slash" do
98
- let(:expected_path) { '/foo' }
99
- let(:actual_path) { '/foo/' }
100
-
101
- it "matches" do
102
- expect(subject.matches? actual_request).to be true
103
- end
104
- end
105
-
106
- context "when the expected body is nil and the actual body is empty" do
107
- let(:expected_body) { nil }
108
- let(:actual_body) { '' }
109
-
110
- it "does not match" do
111
- expect(subject.matches? actual_request).to be false
112
- end
113
- end
114
-
115
- context "when the expected body has no expectation and the actual body is empty" do
116
- let(:expected_body) { Pact::NullExpectation.new }
117
- let(:actual_body) { '' }
118
-
119
- it "matches" do
120
- expect(subject.matches? actual_request).to be true
121
- end
122
- end
123
-
124
- context "when the expected body is nested and the actual body is nil" do
125
- let(:expected_body) do
126
- {
127
- a: 'a'
128
- }
129
- end
130
-
131
- let(:actual_body) { nil }
132
-
133
- it "does not match" do
134
- expect(subject.matches? actual_request).to be false
135
- end
136
- end
137
-
138
- context "when the bodies are different" do
139
- let(:expected_body) { 'foo' }
140
- let(:actual_body) { 'bar' }
141
-
142
- it "does not match" do
143
- expect(subject.matches? actual_request).to be false
144
- end
145
- end
146
-
147
- context "when the expected body contains matching regexes" do
148
- let(:expected_body) do
149
- {
150
- name: 'Bob',
151
- customer_id: /CN.*/
152
- }
153
- end
154
-
155
- let(:actual_body) do
156
- {
157
- name: 'Bob',
158
- customer_id: 'CN1234'
159
- }
160
- end
161
-
162
- it "matches" do
163
- expect(subject.matches? actual_request).to be true
164
- end
165
- end
166
-
167
- context "when the expected body contains non-matching regexes" do
168
- let(:expected_body) do
169
- {
170
- name: 'Bob',
171
- customer_id: /foo/
172
- }
173
- end
174
-
175
- let(:actual_body) do
176
- {
177
- name: 'Bob',
178
- customer_id: 'CN1234'
179
- }
180
- end
181
-
182
- it "does not match" do
183
- expect(subject.matches? actual_request).to be false
184
- end
185
- end
186
-
187
- context "when the expected body contains matching terms" do
188
- let(:expected_body) do
189
- {
190
- name: 'Bob',
191
- customer_id: Term.new(matcher: /CN.*/, generate: 'CN789')
192
- }
193
- end
194
-
195
- let(:actual_body) do
196
- {
197
- name: 'Bob',
198
- customer_id: 'CN1234'
199
- }
200
- end
201
-
202
- it "matches" do
203
- expect(subject.matches? actual_request).to be true
204
- end
205
- end
206
-
207
- context "when the expected body contains non-matching terms" do
208
- let(:expected_body) do
209
- {
210
- name: 'Bob',
211
- customer_id: Term.new(matcher: /foo/, generate: 'fooool')
212
- }
213
- end
214
-
215
- let(:actual_body) do
216
- {
217
- name: 'Bob',
218
- customer_id: 'CN1234'
219
- }
220
- end
221
-
222
- it "does not match" do
223
- expect(subject.matches? actual_request).to be false
224
- end
225
- end
226
-
227
- context "when the expected body contains non-matching arrays" do
228
- let(:expected_body) do
229
- {
230
- name: 'Robert',
231
- nicknames: ['Bob', 'Bobert']
232
- }
233
- end
234
-
235
- let(:actual_body) do
236
- {
237
- name: 'Bob',
238
- nicknames: ['Bob']
239
- }
240
- end
241
-
242
- it "does not match" do
243
- expect(subject.matches? actual_request).to be false
244
- end
245
- end
246
- context "when the expected body contains non-matching hash where one field contains a substring of the other" do
247
- let(:expected_body) do
248
- {
249
- name: 'Robert',
250
- }
251
- end
252
-
253
- let(:actual_body) do
254
- {
255
- name: 'Rob'
256
- }
257
- end
258
-
259
- it "does not match" do
260
- expect(subject.matches? actual_request).to be false
261
- end
262
- end
263
-
264
- context "when the expected body contains matching arrays" do
265
- let(:expected_body) do
266
- {
267
- name: 'Robert',
268
- nicknames: ['Bob', 'Bobert']
269
- }
270
- end
271
-
272
- let(:actual_body) do
273
- {
274
- name: 'Robert',
275
- nicknames: ['Bob', 'Bobert']
276
- }
277
- end
278
-
279
- it "does not match" do
280
- expect(subject.matches? actual_request).to be true
281
- end
282
- end
283
-
284
- context "when the queries are different" do
285
- let(:expected_query) { 'foo' }
286
- let(:actual_query) { 'bar' }
287
-
288
- it "does not match" do
289
- expect(subject.matches? actual_request).to be false
290
- end
291
- end
292
-
293
- context 'when there is no query expectation' do
294
- let(:expected_query) { Pact::NullExpectation.new }
295
- let(:actual_query) { 'bar' }
296
-
297
- it 'matches' do
298
- expect(subject.matches? actual_request).to be true
299
- end
300
- end
301
-
302
- context "when a string is expected, but a number is found" do
303
- let(:actual_body) { { thing: 123} }
304
- let(:expected_body) { { thing: "123" } }
305
-
306
- it 'does not match' do
307
- expect(subject.matches? actual_request).to be false
308
- end
309
- end
310
-
311
- context "when unexpected keys are found in the body" do
312
- let(:expected_body) { {a: 1} }
313
- let(:actual_body) { {a: 1, b: 2} }
314
- context "when allowing unexpected keys" do
315
- let(:options) { {'allow_unexpected_keys_in_body' => true} } #From json, these will be strings
316
- it "matches" do
317
- expect(subject.matches? actual_request).to be true
318
- end
319
- end
320
- context "when not allowing unexpected keys" do
321
- let(:options) { {'allow_unexpected_keys_in_body' => false} }
322
- it "does not match" do
323
- expect(subject.matches? actual_request).to be false
324
- end
325
- end
326
- end
327
- end
328
- end
329
- end
@@ -1,84 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/doc/generator'
3
- require 'fileutils'
4
-
5
- module Pact
6
- module Doc
7
- describe Generator do
8
-
9
- let(:doc_dir) { './tmp/doc' }
10
- let(:pact_dir) { './tmp/pacts' }
11
- let(:file_name) { "Some Consumer - Some Provider#{file_extension}" }
12
- let(:consumer_contract_renderer) { double("ConsumerContractRenderer", :call => doc_content) }
13
- let(:doc_content) { "doc_content" }
14
- let(:index_content) { "index_content" }
15
- let(:expected_doc_path) { "#{doc_dir}/#{doc_type}/#{file_name}" }
16
- let(:expected_index_path) { "#{doc_dir}/#{doc_type}/#{index_name}#{file_extension}" }
17
- let(:doc_type) { 'markdown' }
18
- let(:file_extension) { ".md" }
19
- let(:actual_file_contents) { File.read(expected_doc_path) }
20
- let(:actual_index_contents) { File.read(expected_index_path)}
21
- let(:index_renderer) { double("IndexRenderer", :call => index_content)}
22
- let(:index_name) { 'README' }
23
- let(:after_hook) { double("hook", :call => nil)}
24
-
25
- before do
26
- FileUtils.rm_rf doc_dir
27
- FileUtils.rm_rf pact_dir
28
- FileUtils.mkdir_p doc_dir
29
- FileUtils.mkdir_p pact_dir
30
- FileUtils.cp './spec/support/markdown_pact.json', pact_dir
31
- end
32
-
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
-
35
- subject { Generator.new(pact_dir, doc_dir, options) }
36
-
37
- context "when there are existing files" do
38
- let(:existing_doc_file_path) { File.join(doc_dir, doc_type, "leftover") }
39
-
40
- before do
41
- FileUtils.mkdir_p File.dirname(existing_doc_file_path)
42
- FileUtils.touch existing_doc_file_path
43
- end
44
-
45
- it "clears the existing files" do
46
- expect(File.exist?(existing_doc_file_path)).to be true
47
- subject.call
48
- expect(File.exist?(existing_doc_file_path)).to be false
49
- end
50
- end
51
-
52
-
53
- it "creates an index" do
54
- expect(index_renderer).to receive(:call).with("Some Consumer", {"Some Provider"=>"Some Consumer - Some Provider.md"})
55
- subject.call
56
- expect(actual_index_contents).to eq(index_content)
57
- end
58
-
59
- it "creates documentation" do
60
- subject.call
61
- expect(actual_file_contents).to eq(doc_content)
62
- end
63
-
64
- context "with an after hook specified" do
65
-
66
- subject { Generator.new(pact_dir, doc_dir, options.merge(:after => after_hook)) }
67
-
68
- it "executes the hook" do
69
- expect(after_hook).to receive(:call).with(pact_dir, "#{doc_dir}/#{doc_type}", instance_of(Array))
70
- subject.call
71
- end
72
-
73
- it "passes in the consumer_contracts" do
74
- expect(after_hook).to receive(:call) do | _, _, consumer_contracts |
75
- expect(consumer_contracts.first).to be_instance_of(Pact::ConsumerContract)
76
- end
77
- subject.call
78
- end
79
-
80
- end
81
-
82
- end
83
- end
84
- end