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,120 +0,0 @@
1
- require 'pact/consumer/mock_service/app'
2
- require 'rack/test'
3
-
4
- describe Pact::Consumer::MockService do
5
-
6
- include Rack::Test::Methods
7
-
8
- let(:app) { Pact::Consumer::MockService.new(log_file: StringIO.new) }
9
-
10
- # NOTE: the admin_headers are Rack headers, they will be converted
11
- # to X-Pact-Mock-Service and Content-Type by the framework
12
- let(:admin_headers) { {'HTTP_X_PACT_MOCK_SERVICE' => 'true', 'CONTENT_TYPE' => 'application/json'} }
13
-
14
- let(:expected_interaction) do
15
- {
16
- description: "a request for alligators",
17
- provider_state: "alligators exist",
18
- request: {
19
- method: :get,
20
- path: '/alligators',
21
- headers: { 'Accept' => 'application/json' },
22
- },
23
- response: {
24
- status: 200,
25
- headers: { 'Content-Type' => 'application/json' },
26
- body: [{ name: 'Mary' }]
27
- }
28
- }.to_json
29
- end
30
-
31
- context "when more than one response has been mocked" do
32
- context "when the actual request matches one expected request" do
33
-
34
- let(:another_expected_interaction) do
35
- {
36
- description: "a request for zebras",
37
- provider_state: "there are zebras",
38
- request: {
39
- method: :get,
40
- path: '/zebras',
41
- headers: { 'Accept' => 'application/json' },
42
- },
43
- response: {
44
- status: 200,
45
- headers: { 'Content-Type' => 'application/json' },
46
- body: [{ name: 'Xena Zebra' }]
47
- }
48
- }.to_json
49
- end
50
-
51
- it "returns the expected response" do
52
- # Set up expected interaction
53
- post "/interactions", expected_interaction, admin_headers
54
-
55
- # Set up another expected interaction
56
- post "/interactions", another_expected_interaction, admin_headers
57
-
58
- # Invoke the actual request
59
- get "/alligators", nil, { 'HTTP_ACCEPT' => 'application/json' }
60
-
61
- # Ensure that the response we get back was the one we expected
62
- expect(last_response.status).to eq 200
63
- expect(last_response.headers['Content-Type']).to eq 'application/json'
64
- expect(JSON.parse(last_response.body)).to eq([{ 'name' => 'Mary' }])
65
-
66
- # Invoke the /zebras request
67
- get "/zebras", nil, { 'HTTP_ACCEPT' => 'application/json' }
68
-
69
- # Ensure we got the zebra response back
70
- expect(JSON.parse(last_response.body)).to eq([{ 'name' => 'Xena Zebra' }])
71
-
72
- # Verify
73
- get "/interactions/verification", nil, admin_headers
74
- expect(last_response.status).to eq 200
75
-
76
- end
77
- end
78
-
79
- context "when the actual request matches more than one expected request" do
80
-
81
- let(:another_expected_interaction) do
82
- {
83
- description: "a request for alligators",
84
- provider_state: "there are no alligators",
85
- request: {
86
- method: :get,
87
- path: '/alligators',
88
- headers: { 'Accept' => 'application/json' },
89
- },
90
- response: {
91
- status: 200,
92
- headers: { 'Content-Type' => 'application/json' },
93
- body: []
94
- }
95
- }.to_json
96
- end
97
-
98
- it "returns an error response" do
99
- # Set up expected interaction
100
- post "/interactions", expected_interaction, admin_headers
101
-
102
- # Set up another expected interaction
103
- post "/interactions", another_expected_interaction, admin_headers
104
-
105
- # Invoke the actual request
106
- get "/alligators", nil, { 'HTTP_ACCEPT' => 'application/json' }
107
-
108
- # A 500 is returned as both interactions match the actual request
109
- expect(last_response.status).to eq 500
110
- expect(last_response.body).to include 'Multiple interaction found'
111
-
112
- # Verification will be false
113
- get "/interactions/verification", nil, admin_headers
114
- expect(last_response.status).to eq 500
115
- expect(last_response.body).to include 'Actual interactions do not match expected interactions'
116
- end
117
- end
118
- end
119
-
120
- end
@@ -1,71 +0,0 @@
1
- require 'pact/consumer/mock_service/app'
2
- require 'rack/test'
3
-
4
- describe Pact::Consumer::MockService do
5
-
6
- include Rack::Test::Methods
7
-
8
- let(:app) { Pact::Consumer::MockService.new(log_file: StringIO.new) }
9
-
10
- # NOTE: the admin_headers are Rack headers, they will be converted
11
- # to X-Pact-Mock-Service and Content-Type by the framework
12
- let(:admin_headers) { {'HTTP_X_PACT_MOCK_SERVICE' => 'true', 'CONTENT_TYPE' => 'application/json'} }
13
-
14
- let(:expected_interaction) do
15
- {
16
- description: "a request for alligators",
17
- provider_state: "alligators exist",
18
- request: {
19
- method: :get,
20
- path: '/alligators',
21
- headers: { 'Accept' => 'application/json' },
22
- },
23
- response: {
24
- status: 200,
25
- headers: { 'Content-Type' => 'application/json' },
26
- body: [{ name: 'Mary' }]
27
- }
28
- }.to_json
29
- end
30
-
31
- context "when a response has been mocked" do
32
- context "when the actual request matches the expected request" do
33
- it "returns the expected response" do
34
- # Set up expected interaction
35
- post "/interactions", expected_interaction, admin_headers
36
-
37
- # Invoke the actual request
38
- get "/alligators", nil, { 'HTTP_ACCEPT' => 'application/json' }
39
-
40
- # Ensure that the response we get back was the one we expected
41
- expect(last_response.status).to eq 200
42
- expect(last_response.headers['Content-Type']).to eq 'application/json'
43
- expect(JSON.parse(last_response.body)).to eq([{ 'name' => 'Mary' }])
44
-
45
- # Verify that all the expected interactions were executed, and no extras were made
46
- get "/interactions/verification", nil, admin_headers
47
- expect(last_response.status).to eq 200
48
- end
49
- end
50
-
51
- context "when the actual request does not match the expected request" do
52
- it "returns an error response" do
53
- # Set up expected interaction
54
- post "/interactions", expected_interaction, admin_headers
55
-
56
- # Invoke the actual request
57
- get "/alligators", nil, { 'HTTP_ACCEPT' => 'application/xml' }
58
-
59
- # A 500 is returned as the headers don't match
60
- expect(last_response.status).to eq 500
61
- expect(last_response.body).to include 'No interaction found'
62
-
63
- # Verification will be false
64
- get "/interactions/verification", nil, admin_headers
65
- expect(last_response.status).to eq 500
66
- expect(last_response.body).to include 'Actual interactions do not match expected interactions'
67
- end
68
- end
69
- end
70
-
71
- end
@@ -1,42 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/consumer/app_manager'
3
-
4
- module Pact::Consumer
5
- describe AppManager do
6
- before do
7
- AppManager.instance.clear_all
8
- end
9
-
10
- describe "start_service_for" do
11
- before do
12
- allow_any_instance_of(AppRegistration).to receive(:spawn) # Don't want process actually spawning during the tests
13
- end
14
- let(:name) { 'some_service'}
15
- context "for http://localhost" do
16
- let(:url) { 'http://localhost:1234'}
17
- it "starts a mock service at the given port on localhost" do
18
- expect_any_instance_of(AppRegistration).to receive(:spawn)
19
- AppManager.instance.register_mock_service_for name, url
20
- AppManager.instance.spawn_all
21
- end
22
-
23
- it "registers the mock service as running on the given port" do
24
- AppManager.instance.register_mock_service_for name, url
25
- expect(AppManager.instance.app_registered_on?(1234)).to eq true
26
- end
27
- end
28
- context "for https://" do
29
- let(:url) { 'https://localhost:1234'}
30
- it "should throw an unsupported error" do
31
- expect { AppManager.instance.register_mock_service_for name, url }.to raise_error "Currently only http is supported"
32
- end
33
- end
34
- context "for a host other than localhost" do
35
- let(:url) { 'http://aserver:1234'}
36
- it "should throw an unsupported error" do
37
- expect { AppManager.instance.register_mock_service_for name, url }.to raise_error "Currently only services on localhost are supported"
38
- end
39
- end
40
- end
41
- end
42
- 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
@@ -1,142 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact/consumer/mock_service/verification_get'
3
-
4
- module Pact
5
- module Consumer
6
- describe VerificationGet do
7
-
8
- let(:interaction_list) { instance_double("Pact::Consumer::InteractionList")}
9
- let(:logger) { double("Logger").as_null_object }
10
- let(:log_description) { "/log/pact.log" }
11
-
12
- subject { VerificationGet.new('VerificationGet', logger, interaction_list, log_description) }
13
-
14
- describe "request_path" do
15
- it "is /interactions/verification" do
16
- expect(subject.request_path).to eq '/interactions/verification'
17
- end
18
- end
19
-
20
- describe "request_method" do
21
- it "is GET" do
22
- expect(subject.request_method).to eq 'GET'
23
- end
24
- end
25
-
26
- describe "#respond" do
27
- let(:env) { {
28
- "QUERY_STRING" => "example_description=a description"
29
- } }
30
-
31
- before do
32
- allow(interaction_list).to receive(:all_matched?).and_return(all_matched)
33
- end
34
-
35
- let(:response) { subject.respond env }
36
-
37
- context "when all interactions have been matched" do
38
- let(:all_matched) { true }
39
-
40
- it "returns a 200 status" do
41
- expect(response.first).to eq 200
42
- end
43
-
44
- it "returns a Content-Type of text/plain" do
45
- expect(response[1]).to eq 'Content-Type' => 'text/plain'
46
- end
47
-
48
- it "returns a nice message" do
49
- expect(response.last).to eq ['Interactions matched']
50
- end
51
-
52
- it "logs the success" do
53
- expect(logger).to receive(:info).with(/Verifying - interactions matched.*a description/)
54
- response
55
- end
56
- end
57
-
58
- context "when all interactions not been matched" do
59
- let(:all_matched) { false }
60
- let(:failure_message) { "this is a failure message"}
61
-
62
- before do
63
- allow_any_instance_of(VerificationGet::FailureMessage).to receive(:to_s).and_return(failure_message)
64
- end
65
-
66
- it "returns a 500 status" do
67
- expect(response.first).to eq 500
68
- end
69
-
70
- it "returns a Content-Type of text/plain" do
71
- expect(response[1]).to eq 'Content-Type' => 'text/plain'
72
- end
73
-
74
- it "returns a message" do
75
- expect(response.last.first).to include "Actual interactions do not match"
76
- expect(response.last.first).to include failure_message
77
- expect(response.last.first).to include log_description
78
- end
79
-
80
- it "logs the failure message" do
81
- expect(logger).to receive(:warn).with(/Verifying - actual interactions do not match/)
82
- expect(logger).to receive(:warn).with(failure_message)
83
- response
84
- end
85
-
86
- end
87
-
88
- end
89
-
90
- describe "FailureMessage" do
91
- let(:missing_interactions_summaries) { ["Blah", "Thing"]}
92
- let(:interaction_mismatches_summaries) { []}
93
- let(:unexpected_requests_summaries) { []}
94
- let(:interaction_list) { instance_double("Pact::Consumer::InteractionList") }
95
- subject { VerificationGet::FailureMessage.new(interaction_list).to_s }
96
-
97
- before do
98
- allow(interaction_list).to receive(:missing_interactions_summaries).and_return(missing_interactions_summaries)
99
- allow(interaction_list).to receive(:interaction_mismatches_summaries).and_return(interaction_mismatches_summaries)
100
- allow(interaction_list).to receive(:unexpected_requests_summaries).and_return(unexpected_requests_summaries)
101
- end
102
-
103
- context "with only a missing interactions" do
104
-
105
- let(:expected_string) { <<-EOS
106
- Missing requests:
107
- \tBlah
108
- \tThing
109
-
110
- EOS
111
- }
112
- it "only includes missing interactions" do
113
- expect(subject).to eq expected_string
114
- end
115
- end
116
-
117
- context "with missing, mismatches and unexpected interactions" do
118
-
119
- let(:interaction_mismatches_summaries) { ["wiffle"]}
120
- let(:unexpected_requests_summaries) { ["moose"]}
121
-
122
- let(:expected_string) { <<-EOS
123
- Incorrect requests:
124
- \twiffle
125
-
126
- Missing requests:
127
- \tBlah
128
- \tThing
129
-
130
- Unexpected requests:
131
- \tmoose
132
-
133
- EOS
134
- }
135
- it "includes all the things" do
136
- expect(subject).to eq expected_string
137
- end
138
- end
139
- end
140
- end
141
- end
142
- end