pact-mock_service 0.2.2 → 0.2.3.pre.rc1

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 (80) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/lib/pact/consumer/app_manager.rb +5 -1
  4. data/lib/pact/consumer/interactions_filter.rb +1 -17
  5. data/lib/pact/consumer/mock_service/actual_interactions.rb +34 -0
  6. data/lib/pact/consumer/mock_service/app.rb +21 -18
  7. data/lib/pact/consumer/mock_service/candidate_interactions.rb +13 -0
  8. data/lib/pact/consumer/mock_service/expected_interactions.rb +17 -0
  9. data/lib/pact/consumer/mock_service/interaction_delete.rb +11 -5
  10. data/lib/pact/consumer/mock_service/interaction_post.rb +69 -6
  11. data/lib/pact/consumer/mock_service/interaction_replay.rb +77 -57
  12. data/lib/pact/consumer/mock_service/log_get.rb +1 -1
  13. data/lib/pact/consumer/mock_service/missing_interactions_get.rb +7 -4
  14. data/lib/pact/consumer/mock_service/pact_post.rb +6 -4
  15. data/lib/pact/consumer/mock_service/rack_request_helper.rb +1 -1
  16. data/lib/pact/consumer/mock_service/verification.rb +46 -0
  17. data/lib/pact/consumer/mock_service/verification_get.rb +17 -12
  18. data/lib/pact/consumer/mock_service/verified_interactions.rb +18 -0
  19. data/lib/pact/consumer/mock_service_client.rb +4 -4
  20. data/lib/pact/consumer/server.rb +2 -0
  21. data/lib/pact/consumer_contract/consumer_contract_writer.rb +2 -0
  22. data/lib/pact/mock_service/cli.rb +21 -14
  23. data/lib/pact/mock_service/version.rb +1 -1
  24. metadata +10 -124
  25. data/.gitignore +0 -30
  26. data/.rspec +0 -3
  27. data/.travis.yml +0 -8
  28. data/Rakefile +0 -6
  29. data/lib/pact/consumer/mock_service/interaction_list.rb +0 -76
  30. data/pact-mock-service.gemspec +0 -39
  31. data/spec/features/mock_multiple_responses_spec.rb +0 -120
  32. data/spec/features/mock_response_spec.rb +0 -71
  33. data/spec/lib/pact/consumer/app_manager_spec.rb +0 -42
  34. data/spec/lib/pact/consumer/mock_service/app_spec.rb +0 -52
  35. data/spec/lib/pact/consumer/mock_service/interaction_list_spec.rb +0 -78
  36. data/spec/lib/pact/consumer/mock_service/interaction_mismatch_spec.rb +0 -70
  37. data/spec/lib/pact/consumer/mock_service/interaction_replay_spec.rb +0 -12
  38. data/spec/lib/pact/consumer/mock_service/rack_request_helper_spec.rb +0 -88
  39. data/spec/lib/pact/consumer/mock_service/verification_get_spec.rb +0 -142
  40. data/spec/lib/pact/consumer/mock_service_client_spec.rb +0 -88
  41. data/spec/lib/pact/consumer/service_consumer_spec.rb +0 -11
  42. data/spec/lib/pact/consumer_contract/consumer_contract_writer_spec.rb +0 -128
  43. data/spec/lib/pact/consumer_contract/request_decorator_body_spec.rb +0 -77
  44. data/spec/lib/pact/consumer_contract/request_decorator_headers_spec.rb +0 -69
  45. data/spec/lib/pact/consumer_contract/request_decorator_path_spec.rb +0 -42
  46. data/spec/lib/pact/consumer_contract/request_decorator_query_spec.rb +0 -74
  47. data/spec/lib/pact/consumer_contract/request_decorator_spec.rb +0 -41
  48. data/spec/lib/pact/consumer_contract/response_decorator_spec.rb +0 -10
  49. data/spec/lib/pact/mock_service/interaction_decorator_spec.rb +0 -74
  50. data/spec/lib/pact/mock_service/request_decorator_spec.rb +0 -76
  51. data/spec/lib/pact/mock_service/response_decorator_spec.rb +0 -12
  52. data/spec/spec_helper.rb +0 -16
  53. data/spec/support/a_consumer-a_producer.json +0 -32
  54. data/spec/support/a_consumer-a_provider.json +0 -32
  55. data/spec/support/active_support_if_configured.rb +0 -6
  56. data/spec/support/app_for_config_ru.rb +0 -4
  57. data/spec/support/case-insensitive-response-header-matching.json +0 -21
  58. data/spec/support/case-insensitive-response-header-matching.rb +0 -15
  59. data/spec/support/consumer_contract_template.json +0 -24
  60. data/spec/support/dsl_spec_support.rb +0 -7
  61. data/spec/support/factories.rb +0 -82
  62. data/spec/support/generated_index.md +0 -4
  63. data/spec/support/generated_markdown.md +0 -55
  64. data/spec/support/interaction_view_model.json +0 -63
  65. data/spec/support/interaction_view_model_with_terms.json +0 -50
  66. data/spec/support/markdown_pact.json +0 -48
  67. data/spec/support/missing_provider_states_output.txt +0 -25
  68. data/spec/support/options.json +0 -21
  69. data/spec/support/options_app.rb +0 -15
  70. data/spec/support/pact_helper.rb +0 -57
  71. data/spec/support/shared_examples_for_request.rb +0 -94
  72. data/spec/support/shared_examples_for_response_decorator.rb +0 -25
  73. data/spec/support/spec_support.rb +0 -20
  74. data/spec/support/stubbing.json +0 -22
  75. data/spec/support/stubbing_using_allow.rb +0 -29
  76. data/spec/support/term.json +0 -48
  77. data/spec/support/test_app_fail.json +0 -61
  78. data/spec/support/test_app_pass.json +0 -38
  79. data/spec/support/test_app_with_right_content_type_differ.json +0 -23
  80. data/tasks/spec.rake +0 -6
@@ -1,88 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/consumer/mock_service_client'
3
-
4
- module Pact
5
- module Consumer
6
- describe MockServiceClient do
7
-
8
- subject { MockServiceClient.new(4444) }
9
-
10
- let(:administration_headers) { {'X-Pact-Mock-Service' => 'true'} }
11
-
12
- describe "#add_expected_interaction" do
13
- let(:interaction) { InteractionFactory.create }
14
- let(:request_body) { Pact::MockService::InteractionDecorator.new(interaction).to_json }
15
-
16
- context "when successful" do
17
- let!(:post_interaction) do
18
- stub_request(:post, "localhost:4444/interactions").
19
- with(body: request_body, headers: administration_headers.merge('Content-Type' => "application/json")).
20
- to_return(status: 200)
21
- end
22
-
23
- it "sets up the expected interaction on the mock server" do
24
- subject.add_expected_interaction interaction
25
- expect(post_interaction).to have_been_made
26
- end
27
- end
28
-
29
- end
30
-
31
- describe "#verify" do
32
-
33
- context "when all interactions are successfully verified" do
34
-
35
- let!(:get_verification) do
36
- stub_request(:get, "localhost:4444/interactions/verification?example_description=some%20example").
37
- with(headers: administration_headers).
38
- to_return(status: 200)
39
- end
40
-
41
- it "does not throw an error" do
42
- subject.verify "some example"
43
- expect(get_verification).to have_been_made
44
- end
45
- end
46
- end
47
-
48
- describe ".clear_interactions" do
49
- let!(:delete_verifications) do
50
- stub_request(:delete, "localhost:4444/interactions?example_description=some%20example").
51
- with(headers: administration_headers).
52
- to_return(status: 200)
53
- end
54
-
55
- it "deletes the interactions" do
56
- MockServiceClient.clear_interactions 4444, "some example"
57
- expect(delete_verifications).to have_been_made
58
- end
59
- end
60
-
61
- describe "#write_pact" do
62
- let(:consumer_contract_details) { {consumer: {name: 'Consumer'}, provider: {name: 'Provider'}, pactfile_write_mode: 'update'} }
63
- let(:pact) { {a: 'pact'}.to_json }
64
-
65
- let!(:post_pact) do
66
- stub_request(:post, "localhost:4444/pact").
67
- with(headers: administration_headers.merge('Content-Type' => "application/json"), body: consumer_contract_details).
68
- to_return(status: 200, body: pact)
69
- end
70
-
71
- it "deletes the interactions" do
72
- expect(subject.write_pact(consumer_contract_details)).to eq pact
73
- expect(post_pact).to have_been_made
74
- end
75
-
76
- end
77
-
78
- describe "#log" do
79
- it "sends a log request to the mock server"
80
- end
81
-
82
- describe "#wait_for_interactions" do
83
- it "waits until there are no missing interactions"
84
- end
85
- end
86
- end
87
- end
88
-
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Pact
4
- describe ServiceConsumer do
5
- describe "as_json" do
6
- it "returns a hash representation of the object" do
7
- expect(ServiceConsumer.new(:name => "Bob").as_json).to eq :name => "Bob"
8
- end
9
- end
10
- end
11
- end
@@ -1,128 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/consumer_contract/consumer_contract_writer'
3
-
4
- module Pact
5
-
6
- describe ConsumerContractWriter do
7
-
8
- let(:support_pact_file) { './spec/support/a_consumer-a_provider.json' }
9
- let(:consumer_name) { 'a consumer' }
10
- let(:provider_name) { 'a provider' }
11
- let(:target_pact_file_location) { "#{tmp_pact_dir}/a_consumer-a_provider.json" }
12
-
13
- before do
14
- Pact.clear_configuration
15
- FileUtils.rm_rf tmp_pact_dir
16
- FileUtils.mkdir_p tmp_pact_dir
17
- FileUtils.cp support_pact_file, target_pact_file_location
18
- end
19
-
20
- let(:existing_interactions) { ConsumerContract.from_json(File.read(support_pact_file)).interactions }
21
- let(:new_interactions) { [InteractionFactory.create] }
22
- let(:tmp_pact_dir) { "./tmp/pacts" }
23
- let(:logger) { double("logger").as_null_object }
24
- let(:pactfile_write_mode) { :overwrite }
25
- let(:consumer_contract_details) {
26
- {
27
- consumer: { name: consumer_name },
28
- provider: { name: provider_name },
29
- pactfile_write_mode: pactfile_write_mode,
30
- interactions: new_interactions,
31
- pact_dir: tmp_pact_dir
32
- }
33
- }
34
-
35
- let(:consumer_contract_writer) { ConsumerContractWriter.new(consumer_contract_details, logger) }
36
-
37
- describe "consumer_contract" do
38
-
39
- let(:subject) { consumer_contract_writer.consumer_contract }
40
-
41
- context "when overwriting pact" do
42
-
43
- it "it uses only the interactions from the current test run" do
44
- expect(consumer_contract_writer.consumer_contract.interactions).to eq new_interactions
45
- end
46
-
47
- end
48
-
49
- context "when updating pact" do
50
-
51
- let(:pactfile_write_mode) {:update}
52
-
53
- it "merges the interactions from the current test run with the interactions from the existing file" do
54
- allow_any_instance_of(ConsumerContractWriter).to receive(:info_and_puts)
55
- expect(consumer_contract_writer.consumer_contract.interactions).to eq existing_interactions + new_interactions
56
- end
57
-
58
- let(:line0) { /\*/ }
59
- let(:line1) { /Updating existing file/ }
60
- let(:line2) { /Only interactions defined in this test run will be updated/ }
61
- let(:line3) { /As interactions are identified by description and provider state/ }
62
-
63
- it "logs a description message" do
64
- expect($stdout).to receive(:puts).with(line0).twice
65
- expect($stdout).to receive(:puts).with(line1)
66
- expect($stdout).to receive(:puts).with(line2)
67
- expect($stdout).to receive(:puts).with(line3)
68
- expect(logger).to receive(:info).with(line0).twice
69
- expect(logger).to receive(:info).with(line1)
70
- expect(logger).to receive(:info).with(line2)
71
- expect(logger).to receive(:info).with(line3)
72
- consumer_contract_writer.consumer_contract
73
- end
74
- end
75
-
76
- context "when an error occurs deserializing the existing pactfile" do
77
-
78
- let(:pactfile_write_mode) {:update}
79
- let(:error) { RuntimeError.new('some error')}
80
- let(:line1) { /Could not load existing consumer contract from .* due to some error/ }
81
- let(:line2) {'Creating a new file.'}
82
-
83
- before do
84
- allow(ConsumerContract).to receive(:from_json).and_raise(error)
85
- allow($stderr).to receive(:puts)
86
- allow(logger).to receive(:puts)
87
- end
88
-
89
- it "logs the error" do
90
- expect($stderr).to receive(:puts).with(line1)
91
- expect($stderr).to receive(:puts).with(line2)
92
- expect(logger).to receive(:warn).with(line1)
93
- expect(logger).to receive(:warn).with(line2)
94
- consumer_contract_writer.consumer_contract
95
- end
96
-
97
- it "uses the new interactions" do
98
- expect(consumer_contract_writer.consumer_contract.interactions).to eq new_interactions
99
- end
100
- end
101
- end
102
-
103
- describe "#write" do
104
- it "writes the pact file to the pact_dir" do
105
- FileUtils.rm_rf target_pact_file_location
106
- consumer_contract_writer.write
107
- expect(File.exist?(target_pact_file_location)).to be true
108
- end
109
-
110
- context "when the pact_dir is not specified" do
111
- let(:consumer_contract_details) {
112
- {
113
- consumer: { name: consumer_name },
114
- provider: { name: provider_name },
115
- pactfile_write_mode: pactfile_write_mode,
116
- interactions: new_interactions
117
- }
118
- }
119
-
120
- it "raises an error" do
121
- expect{ consumer_contract_writer.write }.to raise_error ConsumerContractWriterError, /Please indicate the directory/
122
- end
123
- end
124
- end
125
-
126
- end
127
-
128
- end
@@ -1,77 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/consumer_contract/request_decorator'
3
- require 'pact/consumer/request'
4
-
5
- module Pact
6
- describe RequestDecorator do
7
-
8
- let(:body) { {some: "bod"} }
9
- let(:headers) { {some: "header"} }
10
- let(:request_params) do
11
- {
12
- method: :get,
13
- headers: headers,
14
- path: "/",
15
- body: body
16
- }
17
- end
18
-
19
- let(:request) { Pact::Request::Expected.from_hash(request_params) }
20
-
21
- subject { RequestDecorator.new(request) }
22
-
23
- describe "#to_json" do
24
-
25
- let(:parsed_json) { JSON.parse subject.to_json, symbolize_names: true }
26
-
27
- context "body" do
28
-
29
- context "with a Content-Type of form and body specified as a hash with a Pact::Term" do
30
- let(:headers) { { 'Content-Type' => 'application/x-www-form-urlencoded' } }
31
- let(:body) { {"param" => Pact::Term.new(generate: 'apple', matcher: /a/ )} }
32
-
33
- it "reifies the body for compatibility with pact-specification 1.0.0" do
34
- expect(parsed_json[:body]).to eq "param=apple"
35
- end
36
- end
37
-
38
- context "with a Content-Type of form and body specified as a hash with an array value" do
39
- let(:headers) { { 'Content-Type' => 'application/x-www-form-urlencoded' } }
40
- let(:body) { {"param" => ['pear', Pact::Term.new(generate: 'apple', matcher: /a/ )] } }
41
-
42
- it "reifies the body for compatibility with pact-specification 1.0.0" do
43
- expect(parsed_json[:body]).to eq "param=pear&param=apple"
44
- end
45
- end
46
-
47
- context "with no Content-Type and a body specified as a Hash" do
48
- it "renders the body as JSON" do
49
- expect(parsed_json[:body]).to eq body
50
- end
51
- end
52
-
53
- context "with a Pact::Term in the JSON body" do
54
- let(:body) { {"param" => Pact::Term.new(generate: 'apple', matcher: /a/ )} }
55
- it "reifes the body for compatibility with pact-specification 1.0.0" do
56
- expect(parsed_json[:body]).to eq param: 'apple'
57
- end
58
- end
59
-
60
- context "with a Pact::Term as the body" do
61
- let(:body) { Pact::Term.new(generate: 'apple', matcher: /a/ ) }
62
- it "reifes the body for compatibility with pact-specification 1.0.0" do
63
- expect(parsed_json[:body]).to eq 'apple'
64
- end
65
- end
66
-
67
- context "with a String body" do
68
- let(:body) { "a body" }
69
- it "renders the String body" do
70
- expect(parsed_json[:body]).to eq body
71
- end
72
- end
73
-
74
- end
75
- end
76
- end
77
- end
@@ -1,69 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/consumer_contract/request_decorator'
3
- require 'pact/consumer/request'
4
-
5
- module Pact
6
- describe RequestDecorator do
7
-
8
- let(:headers) { { some: "header" } }
9
- let(:request_params) do
10
- {
11
- method: :get,
12
- headers: headers,
13
- path: "/"
14
- }
15
- end
16
-
17
- let(:request) { Pact::Request::Expected.from_hash(request_params) }
18
-
19
- subject { RequestDecorator.new(request) }
20
-
21
- describe "#to_json" do
22
-
23
- let(:parsed_json) { JSON.parse subject.to_json, symbolize_names: true }
24
-
25
- context "headers" do
26
-
27
- it "renders the headers" do
28
- expect(parsed_json[:headers][:some]).to eq "header"
29
- end
30
-
31
- context "with a Pact::Term in the headers" do
32
- let(:headers) { { 'X-Zebra' => Pact::Term.new(generate: 'zebra', matcher: /z/) } }
33
-
34
- it "reifies the headers" do
35
- expect(parsed_json[:headers][:'X-Zebra']).to eq 'zebra'
36
- end
37
- end
38
-
39
- context "with no headers specified" do
40
- let(:request_params) do
41
- {
42
- method: :get,
43
- path: "/"
44
- }
45
- end
46
-
47
- it "does not include the key" do
48
- expect(parsed_json).to_not have_key(:headers)
49
- end
50
- end
51
-
52
- context "with nil headers specified" do
53
- let(:request_params) do
54
- {
55
- method: :get,
56
- path: "/",
57
- headers: nil
58
- }
59
- end
60
-
61
- it "renders the headers as nil, but this would really be silly and will probably cause problems down the line" do
62
- expect(parsed_json.fetch(:headers)).to be nil
63
- end
64
- end
65
-
66
- end
67
- end
68
- end
69
- end
@@ -1,42 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/consumer_contract/request_decorator'
3
- require 'pact/consumer/request'
4
-
5
- module Pact
6
- describe RequestDecorator do
7
-
8
- let(:path) { "/zebras/1" }
9
- let(:request_params) do
10
- {
11
- method: :get,
12
- path: path
13
- }
14
- end
15
-
16
- let(:request) { Pact::Request::Expected.from_hash(request_params) }
17
-
18
- subject { RequestDecorator.new(request) }
19
-
20
- describe "#to_json" do
21
-
22
- let(:parsed_json) { JSON.parse subject.to_json, symbolize_names: true }
23
-
24
- context "path" do
25
-
26
- context "with a String path" do
27
- it "renders the path" do
28
- expect(parsed_json[:path]).to eq path
29
- end
30
- end
31
-
32
- context "with a Pact::Term path", pending: "Pact::Terms for paths are not implemented yet" do
33
- let(:path) { Pact::Term.new(generate: "/zebras/1", matcher: %r{/zebras/\d}) }
34
-
35
- it "reifies the path for compatibility with pact-specification 1.0.0" do
36
- expect(parsed_json[:path]).to eq path
37
- end
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/consumer_contract/request_decorator'
3
- require 'pact/consumer/request'
4
-
5
- module Pact
6
- describe RequestDecorator do
7
-
8
- let(:headers) { {some: "header"} }
9
- let(:query) { "param=foo" }
10
- let(:request_params) do
11
- {
12
- method: :get,
13
- query: query,
14
- headers: headers,
15
- path: "/"
16
- }
17
- end
18
-
19
- let(:request) { Pact::Request::Expected.from_hash(request_params) }
20
-
21
- subject { RequestDecorator.new(request) }
22
-
23
- describe "#to_json" do
24
-
25
- let(:parsed_json) { JSON.parse subject.to_json, symbolize_names: true }
26
-
27
- context "query" do
28
- context "with a query hash containing a Pact::Term" do
29
- let(:query) { { param: Pact::Term.new(generate: 'apple', matcher: /a/) } }
30
-
31
- it "reifies the query for compatibility with pact-specification 1.0.0" do
32
- expect(parsed_json[:query]).to eq "param=apple"
33
- end
34
- end
35
-
36
- context "with a Pact::Term query" do
37
- let(:query) { Pact::Term.new(generate: 'param=apple', matcher: /param=a/) }
38
-
39
- it "reifies the query for compatibility with the pact-specification 1.0.0" do
40
- expect(parsed_json[:query]).to eq 'param=apple'
41
- end
42
- end
43
-
44
- context "when the query is not specified" do
45
- let(:request_params) do
46
- {
47
- method: :get,
48
- path: "/"
49
- }
50
- end
51
-
52
- it "does not include the key" do
53
- expect(parsed_json).to_not have_key(:query)
54
- end
55
- end
56
-
57
- context "when the query is nil" do
58
- let(:request_params) do
59
- {
60
- method: :get,
61
- path: "/",
62
- query: nil
63
- }
64
- end
65
-
66
- it "includes the query as nil" do
67
- expect(parsed_json.fetch(:query)).to be nil
68
- end
69
- end
70
- end
71
-
72
- end
73
- end
74
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/consumer_contract/request_decorator'
3
- require 'pact/consumer/request'
4
-
5
- module Pact
6
- describe RequestDecorator do
7
-
8
- let(:options) { { some: 'opts' } }
9
- let(:body) { { some: "bod" } }
10
- let(:headers) { { some: "header" } }
11
- let(:query) { "param=foo" }
12
- let(:request_params) do
13
- {
14
- method: :get,
15
- query: query,
16
- headers: headers,
17
- path: "/",
18
- body: body,
19
- options: options
20
- }
21
- end
22
-
23
- let(:request) { Pact::Request::Expected.from_hash(request_params) }
24
-
25
- subject { RequestDecorator.new(request) }
26
-
27
- describe "#to_json" do
28
-
29
- let(:parsed_json) { JSON.parse subject.to_json, symbolize_names: true }
30
-
31
- it "renders the keys in a meaningful order" do
32
- expect(subject.to_json).to match(/method.*path.*query.*headers.*body/)
33
- end
34
-
35
- it "does not render the options" do
36
- expect(subject.to_json).to_not include('options')
37
- end
38
-
39
- end
40
- end
41
- end
@@ -1,10 +0,0 @@
1
- require 'pact/consumer_contract/response_decorator'
2
- require 'support/shared_examples_for_response_decorator'
3
-
4
- module Pact
5
- describe ResponseDecorator do
6
-
7
- include_examples "request decorator to_json"
8
-
9
- end
10
- end
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/mock_service/interaction_decorator'
3
-
4
- module Pact
5
- module MockService
6
- describe InteractionDecorator do
7
-
8
- describe "#to_json" do
9
-
10
- let(:request) do
11
- {
12
- method: 'post',
13
- path: '/foo',
14
- body: Term.new(generate: 'waffle', matcher: /ffl/),
15
- headers: { 'Content-Type' => 'application/json' },
16
- query: '',
17
- }
18
- end
19
-
20
- let(:response) do
21
- { body: { baz: /qux/, wiffle: Term.new(generate: 'wiffle', matcher: /iff/) } }
22
- end
23
-
24
- let(:interaction) do
25
- Interaction.from_hash(
26
- 'description' => 'description',
27
- 'provider_state' => 'provider_state',
28
- 'response' => response,
29
- 'request' => request)
30
- end
31
-
32
- subject { InteractionDecorator.new(interaction) }
33
-
34
- let(:parsed_result) do
35
- JSON.load(subject.to_json)
36
- end
37
-
38
- it "contains the request" do
39
- expect(parsed_result).to have_key('request')
40
- end
41
-
42
- it "contains the response" do
43
- expect(parsed_result).to have_key('request')
44
- end
45
-
46
- it "contains the description" do
47
- expect(parsed_result['description']).to eq 'description'
48
- end
49
-
50
- context "with a provider state" do
51
- it "contains the provider_state" do
52
- expect(parsed_result['provider_state']).to eq 'provider_state'
53
- end
54
- end
55
-
56
- context "without a provider state" do
57
-
58
- let(:interaction) do
59
- Interaction.from_hash(
60
- 'description' => 'description',
61
- 'response' => response,
62
- 'request' => request)
63
- end
64
-
65
- it "does not contain the provider_state" do
66
- expect(parsed_result).to_not have_key 'provider_state'
67
- end
68
- end
69
-
70
- end
71
-
72
- end
73
- end
74
- end
@@ -1,76 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/mock_service/request_decorator'
3
- require 'pact/consumer_contract/request'
4
-
5
-
6
- module Pact
7
- module MockService
8
- describe RequestDecorator do
9
-
10
- let(:options) { {} }
11
- let(:body) { {some: "bod"} }
12
- let(:headers) { {some: "header"} }
13
- let(:request_params) do
14
- {
15
- method: :get,
16
- query: "param=foo",
17
- headers: headers,
18
- path: "/",
19
- body: body
20
- }
21
- end
22
-
23
- let(:request) { Pact::Request::Expected.from_hash(request_params) }
24
-
25
- subject { RequestDecorator.new(request) }
26
-
27
- describe "#to_json" do
28
-
29
- let(:parsed_json) { JSON.parse subject.to_json, symbolize_names: true}
30
-
31
- it "renders the keys in a meaningful order" do
32
- expect(subject.to_json).to match(/method.*path.*query.*headers.*body/)
33
- end
34
-
35
- context "with a body specified as a Hash" do
36
- it "serialises the body as a Hash" do
37
- expect(parsed_json[:body]).to eq body
38
- end
39
- end
40
-
41
- context "with a body specified as a Hash containing a Pact::Term" do
42
- let(:body) { { some: Pact::Term.new(generate: 'apple', matcher: /a/) } }
43
-
44
- it "serialises the Pact::Term to Ruby specific JSON that is not compatible with pact-specification 1.0.0" do
45
- expect(subject.to_json).to include "Pact::Term"
46
- end
47
- end
48
- end
49
-
50
- describe "#as_json" do
51
- context "without options" do
52
- it "does not include the options key" do
53
- expect(subject.as_json.key?(:options)).to be false
54
- end
55
- end
56
-
57
- context "with options" do
58
- let(:request_params) do
59
- {
60
- method: :get,
61
- path: "/",
62
- options: options
63
- }
64
- end
65
-
66
- let(:options) { {:opts => 'blah'} }
67
-
68
- it "includes the options in the request hash" do
69
- expect(subject.as_json[:options]).to eq options
70
- end
71
- end
72
- end
73
-
74
- end
75
- end
76
- end