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,57 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/consumer/configuration'
3
-
4
- module Pact::Consumer::Configuration
5
-
6
- describe MockService do
7
-
8
- let(:world) { Pact::Consumer::World.new }
9
- before do
10
- Pact.clear_configuration
11
- allow(Pact::Consumer::AppManager.instance).to receive(:register_mock_service_for)
12
- allow(Pact).to receive(:consumer_world).and_return(world)
13
- end
14
-
15
- describe "configure_consumer_contract_builder" do
16
- let(:consumer_name) {'consumer'}
17
- subject {
18
- MockService.build :mock_service, consumer_name, provider_name do
19
- port 1234
20
- standalone true
21
- verify true
22
- end
23
- }
24
-
25
- let(:provider_name) { 'Mock Provider' }
26
- let(:consumer_contract_builder) { instance_double('Pact::Consumer::ConsumerContractBuilder') }
27
- let(:url) { "http://localhost:1234" }
28
-
29
- it "adds a verification to the Pact configuration" do
30
- allow(Pact::Consumer::ConsumerContractBuilder).to receive(:new).and_return(consumer_contract_builder)
31
- subject.finalize
32
- expect(consumer_contract_builder).to receive(:verify)
33
- Pact.configuration.provider_verifications.first.call
34
- end
35
-
36
- context "when standalone" do
37
- it "does not register the app with the AppManager" do
38
- expect(Pact::Consumer::AppManager.instance).to_not receive(:register_mock_service_for)
39
- subject.finalize
40
- end
41
- end
42
- context "when not standalone" do
43
- subject {
44
- MockService.build :mock_service, consumer_name, provider_name do
45
- port 1234
46
- standalone false
47
- verify true
48
- end
49
- }
50
- it "registers the app with the AppManager" do
51
- expect(Pact::Consumer::AppManager.instance).to receive(:register_mock_service_for).with(provider_name, url)
52
- subject.finalize
53
- end
54
- end
55
- end
56
- end
57
- end
@@ -1,69 +0,0 @@
1
- require 'spec_helper'
2
- require 'fileutils'
3
- require 'pathname'
4
-
5
- module Pact
6
- module Consumer
7
- describe ConsumerContractBuilder do
8
-
9
- let(:consumer_name) { 'a consumer' }
10
- let(:provider_name) { 'a provider' }
11
-
12
- describe "handle_interaction_fully_defined" do
13
-
14
- subject {
15
- Pact::Consumer::ConsumerContractBuilder.new(:consumer_name => 'blah', :provider_name => 'blah', :port => 2222)
16
- }
17
-
18
- let(:interaction_hash) {
19
- {
20
- description: 'Test request',
21
- request: {
22
- method: 'post',
23
- path: '/foo',
24
- body: Term.new(generate: 'waffle', matcher: /ffl/),
25
- headers: { 'Content-Type' => 'application/json' },
26
- query: "",
27
- },
28
- response: {
29
- baz: 'qux',
30
- wiffle: 'wiffle'
31
- }
32
- }
33
- }
34
-
35
- let(:interaction_json) { {} }
36
-
37
- let(:interaction) { Pact::Interaction.from_hash(JSON.load(interaction_hash.to_json)) }
38
-
39
- before do
40
- stub_request(:post, 'localhost:2222/interactions')
41
- end
42
-
43
- it "posts the interaction with generated response to the mock service" do
44
- subject.handle_interaction_fully_defined interaction
45
- expect(WebMock).to have_requested(:post, 'localhost:2222/interactions').with(body: interaction_json)
46
- end
47
-
48
- it "resets the interaction_builder to nil" do
49
- expect(subject).to receive(:interaction_builder=).with(nil)
50
- subject.handle_interaction_fully_defined interaction
51
- end
52
- end
53
-
54
- describe "#mock_service_base_url" do
55
-
56
- subject {
57
- ConsumerContractBuilder.new(
58
- :pactfile_write_mode => :overwrite,
59
- :consumer_name => consumer_name,
60
- :provider_name => provider_name,
61
- :port => 1234) }
62
-
63
- it "returns the mock service base URL" do
64
- expect(subject.mock_service_base_url).to eq("http://localhost:1234")
65
- end
66
- end
67
- end
68
- end
69
- end
@@ -1,91 +0,0 @@
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
- expect(Interaction).to 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
- expect(interaction).to 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
- expect(interaction).to 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
- expect(interaction).to 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
- expect(Pact::Request::Expected).to receive(:from_hash).with(request).and_return(expected_request)
53
- expect(interaction).to 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
- expect(interaction).to 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
- expect(provider).to receive(:callback).with(interaction)
86
- subject.will_respond_with response
87
- end
88
- end
89
- end
90
- end
91
- end
@@ -1,64 +0,0 @@
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
@@ -1,52 +0,0 @@
1
- require 'spec_helper'
2
- require 'rack/test'
3
- require 'tempfile'
4
-
5
- module Pact
6
- module Consumer
7
-
8
- describe MockService do
9
-
10
- include Rack::Test::Methods
11
-
12
- def app
13
- MockService.new(log_file: temp_file)
14
- end
15
-
16
- let(:temp_file) { Tempfile.new('log') }
17
-
18
- after do
19
- temp_file.close
20
- temp_file.unlink
21
- end
22
-
23
- context "when a StandardError is encountered" do
24
- let(:response) { JSON.parse(last_response.body)}
25
- let(:interaction_replay) { double(InteractionReplay, :match? => true)}
26
-
27
- before do
28
- expect(InteractionReplay).to receive(:new).and_return(interaction_replay)
29
- expect(interaction_replay).to receive(:respond).and_raise("an error")
30
- end
31
-
32
- subject { get "/" }
33
-
34
- it "returns a json error" do
35
- subject
36
- expect(last_response.content_type).to eq 'application/json'
37
- end
38
-
39
- it "includes the error message" do
40
- subject
41
- expect(response['message']).to eq "an error"
42
- end
43
-
44
- it "includes the backtrace" do
45
- subject
46
- expect(response['backtrace']).to be_instance_of Array
47
- end
48
- end
49
-
50
- end
51
- end
52
- end
@@ -1,78 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/consumer/mock_service/interaction_list'
3
-
4
- module Pact::Consumer
5
-
6
- describe InteractionList do
7
- shared_context "unexpected requests and missed interactions" do
8
- let(:expected_interaction) { InteractionFactory.create }
9
- let(:unexpected_request) { RequestFactory.create_actual method: 'put' }
10
- let(:candidate_interaction) { double("Pact::Interaction") }
11
- let(:candidate_interactions) { [candidate_interaction] }
12
- let(:interaction_mismatch) { instance_double("Pact::Consumer::InteractionMismatch", :short_summary => 'blah', :candidate_interactions => candidate_interactions)}
13
- subject {
14
- interactionList = InteractionList.new
15
- interactionList.add expected_interaction
16
- interactionList.register_unexpected_request unexpected_request
17
- interactionList.register_interaction_mismatch interaction_mismatch
18
- interactionList
19
- }
20
- end
21
-
22
- shared_context "no unexpected requests or missed interactions exist" do
23
- let(:expected_interaction) { InteractionFactory.create }
24
- subject {
25
- interactionList = InteractionList.new
26
- interactionList.add expected_interaction
27
- interactionList.register_matched expected_interaction
28
- interactionList
29
- }
30
- end
31
-
32
- describe "interaction_diffs" do
33
- context "when unexpected requests and missed interactions exist" do
34
- include_context "unexpected requests and missed interactions"
35
- let(:expected_diff) {
36
- {:missing_interactions=>["GET /path"],
37
- :unexpected_requests=>["PUT /path?query"],
38
- :interaction_mismatches => ['blah']}
39
- }
40
- it "returns the unexpected requests and missed interactions" do
41
- expect(subject.interaction_diffs).to eq expected_diff
42
- end
43
- end
44
-
45
- context "when no unexpected requests or missed interactions exist" do
46
- include_context "no unexpected requests or missed interactions exist"
47
- let(:expected_diff) {
48
- {}
49
- }
50
- it "returns an empty hash" do
51
- expect(subject.interaction_diffs).to eq expected_diff
52
- end
53
- end
54
- end
55
-
56
- describe "all_matched?" do
57
- context "when unexpected requests or missed interactions exist" do
58
- include_context "unexpected requests and missed interactions"
59
- it "returns false" do
60
- expect(subject.all_matched?).to be false
61
- end
62
- end
63
- context "when unexpected requests or missed interactions do not exist" do
64
- include_context "no unexpected requests or missed interactions exist"
65
- it "returns false" do
66
- expect(subject.all_matched?).to be true
67
- end
68
- end
69
- end
70
-
71
- describe "missing_interactions_summaries" do
72
- include_context "unexpected requests and missed interactions"
73
- it "returns a list of the method and paths for each missing interaction" do
74
- expect(subject.missing_interactions_summaries).to eq ["GET /path"]
75
- end
76
- end
77
- end
78
- end
@@ -1,70 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/consumer/mock_service/interaction_mismatch'
3
-
4
- module Pact
5
- module Consumer
6
- describe InteractionMismatch do
7
- let(:content_type) { 'some/content' }
8
- let(:actual_request) { instance_double('Pact::Consumer::Request::Actual', :method_and_path => 'GET /path') }
9
- let(:expected_request_1) { instance_double('Pact::Request::Expected', :content_type => content_type) }
10
- let(:expected_request_2) { instance_double('Pact::Request::Expected', :content_type => content_type) }
11
- let(:candidate_1) { instance_double('Pact::Interaction', request: expected_request_1, description_with_provider_state_quoted: "desc 1") }
12
- let(:candidate_2) { instance_double('Pact::Interaction', request: expected_request_2, description_with_provider_state_quoted: "desc 2") }
13
- let(:candidate_interactions) { [candidate_1, candidate_2] }
14
- subject { InteractionMismatch.new(candidate_interactions, actual_request) }
15
- let(:diff_1) { {body: 'diff'} }
16
- let(:diff_2) { {} }
17
-
18
- before do
19
- allow(expected_request_1).to receive(:difference).with(actual_request).and_return(diff_1)
20
- allow(expected_request_2).to receive(:difference).with(actual_request).and_return(diff_2)
21
- end
22
-
23
- describe "short_summary" do
24
- it "includes the method and path" do
25
- expect(subject.short_summary).to match /GET \/path \(.*\)/
26
- end
27
- context "when the body does not match" do
28
- let(:diff_1) { {body: nil} }
29
-
30
- it "returns a message indicating that the body does not match" do
31
- expect(subject.short_summary).to include "(request body did not match)"
32
- end
33
- end
34
- context "when the headers do not match" do
35
- let(:diff_1) { {headers: nil} }
36
- it "returns a message indicating that the body does not match" do
37
- expect(subject.short_summary).to include "(request headers did not match)"
38
- end
39
- end
40
- context "when the headers and body do not match" do
41
- let(:diff_1) { {body: nil, headers: nil} }
42
- let(:diff_2) { {body: nil, headers: nil} }
43
- it "returns a message indicating that the headers and body do not match" do
44
- expect(subject.short_summary).to include "(request body and headers did not match)"
45
- end
46
- end
47
- end
48
-
49
- describe "to_s" do
50
- let(:expected_message) { "Diff with interaction: desc 1\ndiff 1\nDiff with interaction: desc 2\ndiff 2" }
51
-
52
- let(:diff_formatter) { double("diff_formatter")}
53
- before do
54
- allow(Pact.configuration).to receive(:diff_formatter_for_content_type).with(content_type).and_return(diff_formatter)
55
- allow(diff_formatter).to receive(:call).and_return("diff 1", "diff 2")
56
- end
57
-
58
- it "creates diff output using the configured diff_formatter" do
59
- expect(diff_formatter).to receive(:call).with(diff_1, colour: false)
60
- expect(diff_formatter).to receive(:call).with(diff_2, colour: false)
61
- subject.to_s
62
- end
63
-
64
- it "includes a diff output in the string output" do
65
- expect(subject.to_s).to eq expected_message
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/consumer/mock_service/interaction_replay'
3
-
4
- module Pact
5
- module Consumer
6
-
7
- describe InteractionReplay do
8
-
9
-
10
- end
11
- end
12
- end
@@ -1,88 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/consumer/mock_service/rack_request_helper'
3
-
4
- module Pact::Consumer
5
-
6
- describe RackRequestHelper do
7
- class TestSubject
8
- include RackRequestHelper
9
- end
10
-
11
- let(:rack_env) {
12
- {
13
- "CONTENT_LENGTH" => "16",
14
- "CONTENT_TYPE" => content_type,
15
- "GATEWAY_INTERFACE" => "CGI/1.1",
16
- "PATH_INFO" => "/donuts",
17
- "QUERY_STRING" => "",
18
- "REMOTE_ADDR" => "127.0.0.1",
19
- "REMOTE_HOST" => "localhost",
20
- "REQUEST_METHOD" => "POST",
21
- "REQUEST_URI" => "http://localhost:4321/donuts",
22
- "SCRIPT_NAME" => "",
23
- "SERVER_NAME" => "localhost",
24
- "SERVER_PORT" => "4321",
25
- "SERVER_PROTOCOL" => "HTTP/1.1",
26
- "SERVER_SOFTWARE" => "WEBrick/1.3.1 (Ruby/1.9.3/2013-02-22)",
27
- "HTTP_ACCEPT" => "text/plain",
28
- "HTTP_USER_AGENT" => "Ruby",
29
- "HTTP_HOST" => "localhost:4321",
30
- "HTTP_X_SOMETHING" => "1, 2",
31
- "rack.version" => [1, 2 ],
32
- "rack.input" => StringIO.new(body),
33
- "rack.errors" => nil,
34
- "rack.multithread" => true,
35
- "rack.multiprocess" => false,
36
- "rack.run_once" => false,
37
- "rack.url_scheme" => "http",
38
- "HTTP_VERSION" => "HTTP/1.1",
39
- "REQUEST_PATH" => "/donuts"
40
- }
41
- }
42
-
43
- let(:content_type) { "" }
44
- let(:body) { '' }
45
-
46
- subject { TestSubject.new }
47
-
48
- let(:expected_request) {
49
- {
50
- :query => "",
51
- :method => "post",
52
- :body => expected_body,
53
- :path => "/donuts",
54
- :headers => {
55
- "Content-Type" => content_type,
56
- "Content-Length" => "16",
57
- "Accept" => "text/plain",
58
- "User-Agent" => "Ruby",
59
- "Host" => "localhost:4321",
60
- "Version" => "HTTP/1.1",
61
- "X-Something" => "1, 2"
62
- }
63
- }
64
- }
65
-
66
- context "with a text body" do
67
- let(:content_type) { "application/x-www-form-urlencoded" }
68
- let(:body) { 'this is the body' }
69
- let(:expected_body) { body }
70
-
71
- it "extracts the body" do
72
- expect(subject.request_as_hash_from(rack_env)).to eq expected_request
73
- end
74
- end
75
-
76
- context "with a json body" do
77
- let(:content_type) { "application/json" }
78
- let(:body) { '{"a" : "body" }' }
79
- let(:expected_body) { {"a" => "body"} }
80
-
81
- it "extracts the body" do
82
- expect(subject.request_as_hash_from(rack_env)).to eq expected_request
83
- end
84
- end
85
-
86
-
87
- end
88
- end