pact 1.4.0.rc4 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/CHANGELOG.md +13 -0
  2. data/lib/pact/consumer/configuration/mock_service.rb +2 -1
  3. data/lib/pact/consumer/consumer_contract_builder.rb +2 -1
  4. data/lib/pact/version.rb +1 -1
  5. data/pact.gemspec +4 -3
  6. metadata +32 -205
  7. data/.gitignore +0 -29
  8. data/.rspec +0 -2
  9. data/.travis.yml +0 -8
  10. data/Gemfile +0 -9
  11. data/Gemfile.lock +0 -108
  12. data/README.md +0 -314
  13. data/Rakefile +0 -9
  14. data/config.ru +0 -3
  15. data/documentation/README.md +0 -13
  16. data/documentation/configuration.md +0 -166
  17. data/documentation/diff_formatter_embedded.png +0 -0
  18. data/documentation/diff_formatter_list.png +0 -0
  19. data/documentation/diff_formatter_unix.png +0 -0
  20. data/example/animal-service/Gemfile +0 -14
  21. data/example/animal-service/Gemfile.lock +0 -69
  22. data/example/animal-service/Rakefile +0 -5
  23. data/example/animal-service/config.ru +0 -3
  24. data/example/animal-service/db/animal_db.sqlite3 +0 -0
  25. data/example/animal-service/lib/animal_service/animal_repository.rb +0 -12
  26. data/example/animal-service/lib/animal_service/api.rb +0 -29
  27. data/example/animal-service/lib/animal_service/db.rb +0 -5
  28. data/example/animal-service/spec/service_consumers/pact_helper.rb +0 -11
  29. data/example/animal-service/spec/service_consumers/provider_states_for_zoo_app.rb +0 -26
  30. data/example/zoo-app/Gemfile +0 -12
  31. data/example/zoo-app/Gemfile.lock +0 -63
  32. data/example/zoo-app/Rakefile +0 -5
  33. data/example/zoo-app/doc/pacts/markdown/README.md +0 -3
  34. data/example/zoo-app/doc/pacts/markdown/Zoo App - Animal Service.md +0 -75
  35. data/example/zoo-app/lib/zoo_app/animal_service_client.rb +0 -31
  36. data/example/zoo-app/lib/zoo_app/models/alligator.rb +0 -17
  37. data/example/zoo-app/spec/pacts/zoo_app-animal_service.json +0 -67
  38. data/example/zoo-app/spec/service_providers/animal_service_client_spec.rb +0 -71
  39. data/example/zoo-app/spec/service_providers/pact_helper.rb +0 -15
  40. data/example/zoo-app/spec/spec_helper.rb +0 -6
  41. data/scratchpad.rb +0 -52
  42. data/spec/features/consumption_spec.rb +0 -114
  43. data/spec/features/production_spec.rb +0 -155
  44. data/spec/features/provider_states/zebras.rb +0 -28
  45. data/spec/integration/consumer_async_request_spec.rb +0 -46
  46. data/spec/integration/consumer_more_than_one_matching_interaction_spec.rb +0 -49
  47. data/spec/integration/consumer_no_matching_interaction_spec.rb +0 -53
  48. data/spec/integration/consumer_with_a_provider_state_spec.rb +0 -44
  49. data/spec/integration/consumer_with_form_hash_spec.rb +0 -62
  50. data/spec/integration/consumer_with_form_spec.rb +0 -50
  51. data/spec/integration/consumer_with_params_hash_spec.rb +0 -122
  52. data/spec/integration/pact/consumer_configuration_spec.rb +0 -66
  53. data/spec/integration/pact/provider_configuration_spec.rb +0 -25
  54. data/spec/lib/pact/cli_spec.rb +0 -47
  55. data/spec/lib/pact/configuration_spec.rb +0 -297
  56. data/spec/lib/pact/consumer/app_manager_spec.rb +0 -41
  57. data/spec/lib/pact/consumer/configuration_spec.rb +0 -57
  58. data/spec/lib/pact/consumer/consumer_contract_builder_spec.rb +0 -69
  59. data/spec/lib/pact/consumer/interaction_builder_spec.rb +0 -87
  60. data/spec/lib/pact/consumer/interactions_spec.rb +0 -64
  61. data/spec/lib/pact/consumer/mock_service/app_spec.rb +0 -52
  62. data/spec/lib/pact/consumer/mock_service/interaction_list_spec.rb +0 -78
  63. data/spec/lib/pact/consumer/mock_service/interaction_mismatch_spec.rb +0 -70
  64. data/spec/lib/pact/consumer/mock_service/interaction_replay_spec.rb +0 -12
  65. data/spec/lib/pact/consumer/mock_service/rack_request_helper_spec.rb +0 -88
  66. data/spec/lib/pact/consumer/mock_service/verification_get_spec.rb +0 -142
  67. data/spec/lib/pact/consumer/service_consumer_spec.rb +0 -11
  68. data/spec/lib/pact/doc/generator_spec.rb +0 -84
  69. data/spec/lib/pact/doc/interaction_view_model_spec.rb +0 -132
  70. data/spec/lib/pact/doc/markdown/consumer_contract_renderer_spec.rb +0 -29
  71. data/spec/lib/pact/doc/markdown/index_renderer_spec.rb +0 -29
  72. data/spec/lib/pact/provider/configuration/configuration_extension_spec.rb +0 -17
  73. data/spec/lib/pact/provider/configuration/pact_verification_spec.rb +0 -43
  74. data/spec/lib/pact/provider/configuration/service_provider_config_spec.rb +0 -21
  75. data/spec/lib/pact/provider/configuration/service_provider_dsl_spec.rb +0 -108
  76. data/spec/lib/pact/provider/configuration_spec.rb +0 -50
  77. data/spec/lib/pact/provider/matchers/messages_spec.rb +0 -116
  78. data/spec/lib/pact/provider/pact_helper_locator_spec.rb +0 -54
  79. data/spec/lib/pact/provider/print_missing_provider_states_spec.rb +0 -19
  80. data/spec/lib/pact/provider/request_spec.rb +0 -78
  81. data/spec/lib/pact/provider/rspec/formatter_rspec_2_spec.rb +0 -68
  82. data/spec/lib/pact/provider/rspec/formatter_rspec_3_spec.rb +0 -72
  83. data/spec/lib/pact/provider/rspec_spec.rb +0 -55
  84. data/spec/lib/pact/provider/state/provider_state_manager_spec.rb +0 -89
  85. data/spec/lib/pact/provider/state/provider_state_proxy_spec.rb +0 -80
  86. data/spec/lib/pact/provider/state/provider_state_spec.rb +0 -213
  87. data/spec/lib/pact/provider/world_spec.rb +0 -41
  88. data/spec/lib/pact/tasks/task_helper_spec.rb +0 -74
  89. data/spec/lib/pact/tasks/verification_task_spec.rb +0 -75
  90. data/spec/pact_specification/compliance-1.0.0.rb +0 -47
  91. data/spec/spec_helper.rb +0 -22
  92. data/spec/standalone/consumer_fail_test.rb +0 -55
  93. data/spec/standalone/consumer_pass_test.rb +0 -51
  94. data/spec/support/a_consumer-a_producer.json +0 -32
  95. data/spec/support/a_consumer-a_provider.json +0 -32
  96. data/spec/support/active_support_if_configured.rb +0 -6
  97. data/spec/support/app_for_config_ru.rb +0 -4
  98. data/spec/support/case-insensitive-response-header-matching.json +0 -21
  99. data/spec/support/case-insensitive-response-header-matching.rb +0 -15
  100. data/spec/support/consumer_contract_template.json +0 -24
  101. data/spec/support/factories.rb +0 -82
  102. data/spec/support/generated_index.md +0 -4
  103. data/spec/support/generated_markdown.md +0 -55
  104. data/spec/support/interaction_view_model.json +0 -63
  105. data/spec/support/interaction_view_model_with_terms.json +0 -50
  106. data/spec/support/markdown_pact.json +0 -48
  107. data/spec/support/missing_provider_states_output.txt +0 -25
  108. data/spec/support/options.json +0 -21
  109. data/spec/support/options_app.rb +0 -15
  110. data/spec/support/pact_helper.rb +0 -57
  111. data/spec/support/shared_examples_for_request.rb +0 -94
  112. data/spec/support/spec_support.rb +0 -20
  113. data/spec/support/stubbing.json +0 -22
  114. data/spec/support/stubbing_using_allow.rb +0 -29
  115. data/spec/support/term.json +0 -48
  116. data/spec/support/test_app_fail.json +0 -61
  117. data/spec/support/test_app_pass.json +0 -38
  118. data/spec/support/test_app_with_right_content_type_differ.json +0 -23
  119. data/tasks/pact-test.rake +0 -114
  120. data/tasks/spec.rake +0 -8
@@ -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,87 +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 {|interaction|} }
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
- subject { InteractionBuilder.new {|interaction| provider.callback interaction } }
70
-
71
- it "sets the response on the interaction" do
72
- expect(interaction).to receive(:response=).with(response)
73
- subject.will_respond_with(response)
74
- end
75
-
76
- it "returns itself" do
77
- expect(subject.given(nil)).to be(subject)
78
- end
79
-
80
- it "invokes the 'on_interaction_fully_defined' callback" do
81
- expect(provider).to receive(:callback).with(interaction)
82
- subject.will_respond_with response
83
- end
84
- end
85
- end
86
- end
87
- 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