http_stub 0.25.1 → 0.26.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.
- checksums.yaml +4 -4
- data/lib/http_stub.rb +32 -9
- data/lib/http_stub/configurer.rb +2 -10
- data/lib/http_stub/configurer/dsl/scenario_builder.rb +13 -11
- data/lib/http_stub/configurer/dsl/server.rb +32 -43
- data/lib/http_stub/configurer/dsl/server_endpoint_template.rb +23 -0
- data/lib/http_stub/configurer/dsl/session.rb +55 -0
- data/lib/http_stub/configurer/dsl/session_endpoint_template.rb +22 -0
- data/lib/http_stub/configurer/dsl/session_factory.rb +34 -0
- data/lib/http_stub/configurer/dsl/stub_builder.rb +18 -8
- data/lib/http_stub/configurer/dsl/stub_builder_template.rb +26 -0
- data/lib/http_stub/configurer/request/http/basic.rb +9 -3
- data/lib/http_stub/configurer/request/http/factory.rb +7 -16
- data/lib/http_stub/configurer/request/http/multipart.rb +5 -7
- data/lib/http_stub/configurer/request/stub.rb +3 -3
- data/lib/http_stub/configurer/request/triggers.rb +25 -0
- data/lib/http_stub/configurer/server/command_processor.rb +8 -10
- data/lib/http_stub/configurer/server/configuration.rb +33 -0
- data/lib/http_stub/configurer/server/facade.rb +21 -43
- data/lib/http_stub/configurer/server/request_processor.rb +2 -2
- data/lib/http_stub/configurer/server/session_facade.rb +64 -0
- data/lib/http_stub/extensions/core/uri.rb +28 -0
- data/lib/http_stub/extensions/rack/handler.rb +1 -0
- data/lib/http_stub/extensions/sinatra/namespace.rb +9 -0
- data/lib/http_stub/rake/server_tasks.rb +1 -4
- data/lib/http_stub/server/application/application.rb +17 -98
- data/lib/http_stub/server/application/configuration.rb +38 -0
- data/lib/http_stub/server/application/cross_origin_support.rb +7 -5
- data/lib/http_stub/server/application/request_support.rb +38 -0
- data/lib/http_stub/server/application/response_support.rb +19 -0
- data/lib/http_stub/server/application/routes/memory.rb +37 -0
- data/lib/http_stub/server/application/routes/resource.rb +23 -0
- data/lib/http_stub/server/application/routes/scenario.rb +52 -0
- data/lib/http_stub/server/application/routes/session.rb +65 -0
- data/lib/http_stub/server/application/routes/stub.rb +75 -0
- data/lib/http_stub/server/application/session_uri_support.rb +15 -0
- data/lib/http_stub/server/memory/controller.rb +25 -0
- data/lib/http_stub/server/memory/memory.rb +32 -0
- data/lib/http_stub/server/registry.rb +25 -8
- data/lib/http_stub/server/request/factory.rb +23 -0
- data/lib/http_stub/server/request/parameters.rb +2 -2
- data/lib/http_stub/server/request/request.rb +6 -11
- data/lib/http_stub/server/request/sinatra_request.rb +26 -0
- data/lib/http_stub/server/scenario/controller.rb +16 -11
- data/lib/http_stub/server/scenario/not_found_error.rb +15 -0
- data/lib/http_stub/server/session.rb +14 -0
- data/lib/http_stub/server/session/configuration.rb +32 -0
- data/lib/http_stub/server/session/controller.rb +40 -0
- data/lib/http_stub/server/session/empty.rb +15 -0
- data/lib/http_stub/server/session/identifier_strategy.rb +24 -0
- data/lib/http_stub/server/session/registry.rb +38 -0
- data/lib/http_stub/server/session/session.rb +80 -0
- data/lib/http_stub/server/stub/controller.rb +18 -12
- data/lib/http_stub/server/stub/empty.rb +1 -1
- data/lib/http_stub/server/stub/match/controller.rb +9 -5
- data/lib/http_stub/server/stub/payload/response_body_modifier.rb +3 -1
- data/lib/http_stub/server/stub/registry.rb +6 -13
- data/lib/http_stub/server/stub/triggers.rb +11 -9
- data/lib/http_stub/server/views/_home.haml +2 -0
- data/lib/http_stub/server/views/_post_link_function.haml +26 -0
- data/lib/http_stub/server/views/_session.haml +16 -0
- data/lib/http_stub/server/views/_stub.haml +8 -2
- data/lib/http_stub/server/views/_stubs.haml +4 -0
- data/lib/http_stub/server/views/application.sass +4 -1
- data/lib/http_stub/server/views/layout.haml +1 -0
- data/lib/http_stub/server/views/scenario.haml +4 -3
- data/lib/http_stub/server/views/scenarios.haml +7 -6
- data/lib/http_stub/server/views/session.haml +3 -0
- data/lib/http_stub/server/views/sessions.haml +6 -0
- data/lib/http_stub/server/views/stubs.haml +1 -4
- data/lib/http_stub/server/views/transactional_session.haml +2 -0
- data/lib/http_stub/version.rb +1 -1
- data/spec/acceptance/configurer_initialization_spec.rb +40 -51
- data/spec/acceptance/configurer_part_spec.rb +5 -7
- data/spec/acceptance/cross_origin_support_spec.rb +7 -13
- data/spec/acceptance/endpoint_template_spec.rb +2 -4
- data/spec/acceptance/request_reference_spec.rb +1 -3
- data/spec/acceptance/scenario_spec.rb +7 -9
- data/spec/acceptance/server_defaults_spec.rb +2 -4
- data/spec/acceptance/server_memory_spec.rb +20 -0
- data/spec/acceptance/session_spec.rb +125 -0
- data/spec/acceptance/stub_body_request_matching_spec.rb +2 -4
- data/spec/acceptance/stub_control_values_spec.rb +19 -18
- data/spec/acceptance/stub_match_last_spec.rb +0 -4
- data/spec/acceptance/stub_match_list_spec.rb +0 -4
- data/spec/acceptance/stub_miss_list_spec.rb +0 -4
- data/spec/acceptance/stub_spec.rb +11 -11
- data/spec/acceptance/stub_trigger_spec.rb +60 -13
- data/spec/lib/http_stub/configurer/dsl/scenario_builder_spec.rb +83 -30
- data/spec/lib/http_stub/configurer/dsl/server_endpoint_template_spec.rb +167 -0
- data/spec/lib/http_stub/configurer/dsl/server_spec.rb +306 -176
- data/spec/lib/http_stub/configurer/dsl/session_endpoint_template_spec.rb +150 -0
- data/spec/lib/http_stub/configurer/dsl/session_factory_spec.rb +97 -0
- data/spec/lib/http_stub/configurer/dsl/session_spec.rb +222 -0
- data/spec/lib/http_stub/configurer/dsl/stub_builder_spec.rb +209 -48
- data/spec/lib/http_stub/configurer/dsl/stub_builder_template_spec.rb +203 -0
- data/spec/lib/http_stub/configurer/request/http/basic_spec.rb +80 -4
- data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +115 -56
- data/spec/lib/http_stub/configurer/request/http/multipart_spec.rb +39 -6
- data/spec/lib/http_stub/configurer/request/stub_spec.rb +50 -108
- data/spec/lib/http_stub/configurer/request/triggers_spec.rb +101 -0
- data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +11 -10
- data/spec/lib/http_stub/configurer/server/configuration_spec.rb +139 -0
- data/spec/lib/http_stub/configurer/server/facade_spec.rb +65 -142
- data/spec/lib/http_stub/configurer/server/request_processor_spec.rb +7 -6
- data/spec/lib/http_stub/configurer/server/session_facade_spec.rb +336 -0
- data/spec/lib/http_stub/configurer_spec.rb +105 -0
- data/spec/lib/http_stub/extensions/core/uri_spec.rb +75 -0
- data/spec/lib/http_stub/extensions/rack/handler_spec.rb +1 -1
- data/spec/lib/http_stub/extensions/sinatra/namespace_spec.rb +36 -0
- data/spec/lib/http_stub/rake/server_tasks_smoke_spec.rb +4 -3
- data/spec/lib/http_stub/rake/server_tasks_spec.rb +47 -10
- data/spec/lib/http_stub/server/application/application_spec.rb +44 -301
- data/spec/lib/http_stub/server/application/configuration_spec.rb +59 -0
- data/spec/lib/http_stub/server/application/cross_origin_support_spec.rb +23 -20
- data/spec/lib/http_stub/server/application/request_support_integration_spec.rb +93 -0
- data/spec/lib/http_stub/server/application/request_support_spec.rb +61 -0
- data/spec/lib/http_stub/server/application/response_support_spec.rb +30 -0
- data/spec/lib/http_stub/server/application/routes/memory_spec.rb +41 -0
- data/spec/lib/http_stub/server/application/routes/resource_spec.rb +16 -0
- data/spec/lib/http_stub/server/application/routes/scenario_spec.rb +117 -0
- data/spec/lib/http_stub/server/application/routes/session_integration_spec.rb +46 -0
- data/spec/lib/http_stub/server/application/routes/session_spec.rb +186 -0
- data/spec/lib/http_stub/server/application/{application_integration_spec.rb → routes/stub_integration_spec.rb} +16 -38
- data/spec/lib/http_stub/server/application/routes/stub_spec.rb +202 -0
- data/spec/lib/http_stub/server/application/session_uri_support_spec.rb +48 -0
- data/spec/lib/http_stub/server/application/text_formatting_support_spec.rb +3 -3
- data/spec/lib/http_stub/server/memory/controller_spec.rb +47 -0
- data/spec/lib/http_stub/server/memory/memory_spec.rb +122 -0
- data/spec/lib/http_stub/server/registry_spec.rb +153 -34
- data/spec/lib/http_stub/server/request/factory_spec.rb +74 -0
- data/spec/lib/http_stub/server/request/parameters_spec.rb +5 -8
- data/spec/lib/http_stub/server/request/request_spec.rb +52 -52
- data/spec/lib/http_stub/server/request/sinatra_request_spec.rb +132 -0
- data/spec/lib/http_stub/server/scenario/controller_spec.rb +121 -35
- data/spec/lib/http_stub/server/scenario/not_found_error_spec.rb +25 -0
- data/spec/lib/http_stub/server/session/configuration_spec.rb +94 -0
- data/spec/lib/http_stub/server/session/controller_spec.rb +106 -0
- data/spec/lib/http_stub/server/session/empty_spec.rb +13 -0
- data/spec/lib/http_stub/server/session/identifier_strategy_spec.rb +126 -0
- data/spec/lib/http_stub/server/session/registry_spec.rb +214 -0
- data/spec/lib/http_stub/server/session/session_spec.rb +444 -0
- data/spec/lib/http_stub/server/stub/controller_spec.rb +89 -37
- data/spec/lib/http_stub/server/stub/empty_spec.rb +2 -2
- data/spec/lib/http_stub/server/stub/match/controller_spec.rb +59 -16
- data/spec/lib/http_stub/server/stub/payload/response_body_modifier_spec.rb +7 -8
- data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +42 -15
- data/spec/lib/http_stub/server/stub/registry_spec.rb +38 -59
- data/spec/lib/http_stub/server/stub/triggers_spec.rb +93 -34
- data/spec/spec_helper.rb +13 -1
- data/spec/support/contain_file.rb +23 -0
- data/spec/support/cross_origin_server/application.rb +1 -1
- data/spec/support/cross_origin_server/index_page.rb +2 -2
- data/spec/support/cross_origin_server/integration.rb +3 -2
- data/spec/support/cross_origin_server/public/index.html +2 -1
- data/spec/support/http_stub/configurer_integration.rb +12 -14
- data/spec/support/http_stub/server/application/http_stub_rack_application_test.rb +47 -0
- data/spec/support/http_stub/server/driver.rb +56 -0
- data/spec/support/http_stub/server/memory_fixture.rb +17 -0
- data/spec/support/http_stub/server/request_fixture.rb +7 -6
- data/spec/support/http_stub/server/scenario_fixture.rb +13 -0
- data/spec/support/http_stub/server/session_fixture.rb +27 -0
- data/spec/support/http_stub/server_integration.rb +12 -17
- data/spec/support/http_stub/stub_fixture.rb +19 -6
- data/spec/support/include_in_json.rb +4 -4
- data/spec/support/rack/rack_application_test.rb +9 -0
- data/spec/support/rack/request_fixture.rb +13 -0
- data/spec/support/surpressed_output.rb +10 -0
- metadata +149 -36
- data/lib/http_stub/configurer/dsl/deprecated.rb +0 -60
- data/lib/http_stub/configurer/dsl/endpoint_template.rb +0 -38
- data/lib/http_stub/configurer/dsl/scenario_activator.rb +0 -15
- data/lib/http_stub/configurer/dsl/stub_activator_builder.rb +0 -24
- data/lib/http_stub/configurer/dsl/stub_builder_producer.rb +0 -21
- data/lib/http_stub/server/request.rb +0 -12
- data/lib/http_stub/server/scenario/activator.rb +0 -25
- data/lib/http_stub/server/views/_activate_scenario.haml +0 -23
- data/lib/http_stub/server/views/index.haml +0 -8
- data/spec/acceptance/activator_spec.rb +0 -81
- data/spec/lib/http_stub/configurer/dsl/deprecated_spec.rb +0 -240
- data/spec/lib/http_stub/configurer/dsl/endpoint_template_spec.rb +0 -255
- data/spec/lib/http_stub/configurer/dsl/scenario_activator_spec.rb +0 -62
- data/spec/lib/http_stub/configurer/dsl/stub_activator_builder_spec.rb +0 -120
- data/spec/lib/http_stub/configurer/dsl/stub_builder_producer_spec.rb +0 -85
- data/spec/lib/http_stub/server/request_spec.rb +0 -24
- data/spec/lib/http_stub/server/scenario/activator_spec.rb +0 -111
- data/spec/support/http_stub/server/scenario/scenario_fixture.rb +0 -15
@@ -1,15 +1,91 @@
|
|
1
1
|
describe HttpStub::Configurer::Request::Http::Basic do
|
2
2
|
|
3
|
-
let(:
|
3
|
+
let(:request_method) { :get }
|
4
|
+
let(:path) { "some/path" }
|
5
|
+
let(:args) { { method: request_method, path: path } }
|
4
6
|
|
5
|
-
let(:basic_request) {
|
7
|
+
let(:basic_request) { described_class.new(args) }
|
6
8
|
|
7
9
|
describe "#to_http_request" do
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
subject { basic_request.to_http_request }
|
12
|
+
|
13
|
+
it "returns a HTTP request of the provided type" do
|
14
|
+
expect(subject).to be_a(Net::HTTP::Get)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns a request with the provided path prefixed with http_stub scoping" do
|
18
|
+
expect(subject.path).to eql("/http_stub/#{path}")
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when headers are provided" do
|
22
|
+
|
23
|
+
let(:args) { { method: request_method, path: path, headers: headers } }
|
24
|
+
|
25
|
+
context "whose names are symbols" do
|
26
|
+
|
27
|
+
let(:headers) { (1..3).each_with_object({}) { |i, result| result["header#{i}".to_sym] = "value#{i}" } }
|
28
|
+
|
29
|
+
it "returns a request with the provided headers with names converted to strings" do
|
30
|
+
expect(request_headers).to include(headers.stringify_keys)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
context "whose names are strings" do
|
36
|
+
|
37
|
+
let(:headers) { (1..3).each_with_object({}) { |i, result| result["header#{i}"] = "value#{i}" } }
|
38
|
+
|
39
|
+
it "returns a request with the provided headers" do
|
40
|
+
expect(request_headers).to include(headers)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when headers are not provided" do
|
48
|
+
|
49
|
+
it "returns a request with default headers" do
|
50
|
+
expect(request_headers).to_not be_empty
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when parameters are provided" do
|
56
|
+
|
57
|
+
let(:parameters) { (1..3).each_with_object({}) { |i, result| result["parameter#{i}"] = "value#{i}" } }
|
58
|
+
|
59
|
+
let(:args) { { method: request_method, path: path, parameters: parameters } }
|
60
|
+
|
61
|
+
it "returns a request with the provided parameters" do
|
62
|
+
expect(request_parameters).to eql(parameters)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when parameters are not provided" do
|
68
|
+
|
69
|
+
let(:args) { { method: request_method, path: path } }
|
70
|
+
|
71
|
+
it "returns a request without parameters" do
|
72
|
+
expect(subject.body).to eql(nil)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
it "returns a request with the provided path prefixed with http_stub scoping" do
|
78
|
+
expect(subject.path).to eql("/http_stub/#{path}")
|
11
79
|
end
|
12
80
|
|
13
81
|
end
|
14
82
|
|
83
|
+
def request_headers
|
84
|
+
subject.to_hash.each_with_object({}) { |(key, value), result| result[key] = value.first }
|
85
|
+
end
|
86
|
+
|
87
|
+
def request_parameters
|
88
|
+
URI.decode_www_form(subject.body).to_h
|
89
|
+
end
|
90
|
+
|
15
91
|
end
|
@@ -2,21 +2,55 @@ describe HttpStub::Configurer::Request::Http::Factory do
|
|
2
2
|
|
3
3
|
describe "::multipart" do
|
4
4
|
|
5
|
-
let(:model)
|
5
|
+
let(:model) { double("HttpStub::Configurer::Request::SomeModel") }
|
6
|
+
let(:path) { "some/model/path" }
|
7
|
+
|
6
8
|
let(:multipart_request) { instance_double(HttpStub::Configurer::Request::Http::Multipart) }
|
7
9
|
|
8
|
-
subject {
|
10
|
+
subject { described_class.multipart(path, model) }
|
9
11
|
|
10
12
|
before(:example) do
|
11
13
|
allow(HttpStub::Configurer::Request::Http::Multipart).to receive(:new).and_return(multipart_request)
|
12
14
|
end
|
13
15
|
|
16
|
+
it "creates a multipart request with the provided path" do
|
17
|
+
expect(HttpStub::Configurer::Request::Http::Multipart).to receive(:new).with(hash_including(path: path))
|
18
|
+
|
19
|
+
subject
|
20
|
+
end
|
21
|
+
|
14
22
|
it "creates a multipart request with the provided model" do
|
15
|
-
expect(HttpStub::Configurer::Request::Http::Multipart).to receive(:new).with(model)
|
23
|
+
expect(HttpStub::Configurer::Request::Http::Multipart).to receive(:new).with(hash_including(model: model))
|
16
24
|
|
17
25
|
subject
|
18
26
|
end
|
19
27
|
|
28
|
+
context "when headers are provided" do
|
29
|
+
|
30
|
+
let(:headers) { (1..3).each_with_object({}) { |i, result| result["header#{i}"] = "value#{i}" } }
|
31
|
+
|
32
|
+
subject { described_class.multipart(path, model, headers) }
|
33
|
+
|
34
|
+
it "creates a multipart request with the provided headers" do
|
35
|
+
expect(HttpStub::Configurer::Request::Http::Multipart).to receive(:new).with(hash_including(headers: headers))
|
36
|
+
|
37
|
+
subject
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when no headers are provided" do
|
43
|
+
|
44
|
+
subject { described_class.multipart(path, model) }
|
45
|
+
|
46
|
+
it "creates a multipart request with the empty headers" do
|
47
|
+
expect(HttpStub::Configurer::Request::Http::Multipart).to receive(:new).with(hash_including(headers: {}))
|
48
|
+
|
49
|
+
subject
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
20
54
|
it "returns the created request" do
|
21
55
|
expect(subject).to eql(multipart_request)
|
22
56
|
end
|
@@ -25,47 +59,52 @@ describe HttpStub::Configurer::Request::Http::Factory do
|
|
25
59
|
|
26
60
|
describe "::get" do
|
27
61
|
|
28
|
-
let(:path)
|
29
|
-
|
62
|
+
let(:path) { "/some/get/path" }
|
63
|
+
|
30
64
|
let(:basic_request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
|
31
65
|
|
32
|
-
subject {
|
66
|
+
subject { described_class.get(path) }
|
33
67
|
|
34
|
-
before(:example)
|
35
|
-
|
36
|
-
|
68
|
+
before(:example) { allow(HttpStub::Configurer::Request::Http::Basic).to receive(:new).and_return(basic_request) }
|
69
|
+
|
70
|
+
it "creates a basic GET request" do
|
71
|
+
expect(HttpStub::Configurer::Request::Http::Basic).to receive(:new).with(hash_including(method: :get))
|
72
|
+
|
73
|
+
subject
|
74
|
+
end
|
75
|
+
|
76
|
+
it "creates a basic request with the provided path" do
|
77
|
+
expect(HttpStub::Configurer::Request::Http::Basic).to receive(:new).with(hash_including(path: path))
|
78
|
+
|
79
|
+
subject
|
37
80
|
end
|
38
81
|
|
39
|
-
context "when
|
82
|
+
context "when headers are provided" do
|
40
83
|
|
41
|
-
let(:
|
84
|
+
let(:headers) { (1..3).each_with_object({}) { |i, result| result["header#{i}"] = "value#{i}" } }
|
42
85
|
|
43
|
-
|
44
|
-
|
86
|
+
subject { described_class.get(path, headers) }
|
87
|
+
|
88
|
+
it "creates a basic request with the provided headers" do
|
89
|
+
expect(HttpStub::Configurer::Request::Http::Basic).to receive(:new).with(hash_including(headers: headers))
|
45
90
|
|
46
91
|
subject
|
47
92
|
end
|
48
93
|
|
49
94
|
end
|
50
95
|
|
51
|
-
context "when
|
96
|
+
context "when no headers are provided" do
|
52
97
|
|
53
|
-
|
98
|
+
subject { described_class.get(path) }
|
54
99
|
|
55
|
-
it "creates a
|
56
|
-
expect(
|
100
|
+
it "creates a basic request with empty headers" do
|
101
|
+
expect(HttpStub::Configurer::Request::Http::Basic).to receive(:new).with(hash_including(headers: {}))
|
57
102
|
|
58
103
|
subject
|
59
104
|
end
|
60
105
|
|
61
106
|
end
|
62
107
|
|
63
|
-
it "creates a basic request wrapping the GET request" do
|
64
|
-
expect(HttpStub::Configurer::Request::Http::Basic).to receive(:new).with(get_request)
|
65
|
-
|
66
|
-
subject
|
67
|
-
end
|
68
|
-
|
69
108
|
it "returns the created basic request" do
|
70
109
|
expect(subject).to eql(basic_request)
|
71
110
|
end
|
@@ -74,31 +113,34 @@ describe HttpStub::Configurer::Request::Http::Factory do
|
|
74
113
|
|
75
114
|
describe "::post" do
|
76
115
|
|
77
|
-
let(:path)
|
78
|
-
|
116
|
+
let(:path) { "/some/post/path" }
|
117
|
+
|
79
118
|
let(:basic_request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
|
80
119
|
|
81
|
-
subject {
|
120
|
+
subject { described_class.post(path) }
|
82
121
|
|
83
|
-
before(:example)
|
84
|
-
|
85
|
-
|
122
|
+
before(:example) { allow(HttpStub::Configurer::Request::Http::Basic).to receive(:new).and_return(basic_request) }
|
123
|
+
|
124
|
+
it "creates a basic POST request" do
|
125
|
+
expect(HttpStub::Configurer::Request::Http::Basic).to receive(:new).with(hash_including(method: :post))
|
126
|
+
|
127
|
+
subject
|
86
128
|
end
|
87
129
|
|
88
|
-
it "creates a
|
89
|
-
expect(
|
130
|
+
it "creates a basic request with the provided path" do
|
131
|
+
expect(HttpStub::Configurer::Request::Http::Basic).to receive(:new).with(hash_including(path: path))
|
90
132
|
|
91
133
|
subject
|
92
134
|
end
|
93
135
|
|
94
136
|
context "when parameters are provided" do
|
95
137
|
|
96
|
-
let(:parameters) { (1..3).each_with_object({}) { |i, result| result["
|
138
|
+
let(:parameters) { (1..3).each_with_object({}) { |i, result| result["parameter#{i}"] = "value#{i}" } }
|
97
139
|
|
98
|
-
subject {
|
140
|
+
subject { described_class.post(path, parameters) }
|
99
141
|
|
100
|
-
it "
|
101
|
-
expect(
|
142
|
+
it "creates a basic request with the provided parameters" do
|
143
|
+
expect(HttpStub::Configurer::Request::Http::Basic).to receive(:new).with(hash_including(parameters: parameters))
|
102
144
|
|
103
145
|
subject
|
104
146
|
end
|
@@ -107,22 +149,16 @@ describe HttpStub::Configurer::Request::Http::Factory do
|
|
107
149
|
|
108
150
|
context "when no parameters are provided" do
|
109
151
|
|
110
|
-
subject {
|
152
|
+
subject { described_class.post(path) }
|
111
153
|
|
112
|
-
it "
|
113
|
-
|
154
|
+
it "creates a basic POST request with empty parameters" do
|
155
|
+
allow(HttpStub::Configurer::Request::Http::Basic).to receive(:new).with(hash_including(parameters: {}))
|
114
156
|
|
115
157
|
subject
|
116
158
|
end
|
117
159
|
|
118
160
|
end
|
119
161
|
|
120
|
-
it "creates a basic request wrapping the POST request" do
|
121
|
-
expect(HttpStub::Configurer::Request::Http::Basic).to receive(:new).with(post_request)
|
122
|
-
|
123
|
-
subject
|
124
|
-
end
|
125
|
-
|
126
162
|
it "returns the created basic request" do
|
127
163
|
expect(subject).to eql(basic_request)
|
128
164
|
end
|
@@ -131,29 +167,52 @@ describe HttpStub::Configurer::Request::Http::Factory do
|
|
131
167
|
|
132
168
|
describe "::delete" do
|
133
169
|
|
134
|
-
let(:path)
|
135
|
-
|
136
|
-
let(:basic_request)
|
170
|
+
let(:path) { "/some/delete/path" }
|
171
|
+
|
172
|
+
let(:basic_request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
|
137
173
|
|
138
|
-
subject {
|
174
|
+
subject { described_class.delete(path) }
|
139
175
|
|
140
|
-
before(:example)
|
141
|
-
allow(Net::HTTP::Delete).to receive(:new).and_return(delete_request)
|
142
|
-
allow(HttpStub::Configurer::Request::Http::Basic).to receive(:new).and_return(basic_request)
|
143
|
-
end
|
176
|
+
before(:example) { allow(HttpStub::Configurer::Request::Http::Basic).to receive(:new).and_return(basic_request) }
|
144
177
|
|
145
|
-
it "creates a DELETE request
|
146
|
-
expect(
|
178
|
+
it "creates a basic DELETE request" do
|
179
|
+
expect(HttpStub::Configurer::Request::Http::Basic).to receive(:new).with(hash_including(method: :delete))
|
147
180
|
|
148
181
|
subject
|
149
182
|
end
|
150
183
|
|
151
|
-
it "creates a basic request
|
152
|
-
expect(HttpStub::Configurer::Request::Http::Basic).to receive(:new).with(
|
184
|
+
it "creates a basic request with the provided path" do
|
185
|
+
expect(HttpStub::Configurer::Request::Http::Basic).to receive(:new).with(hash_including(path: path))
|
153
186
|
|
154
187
|
subject
|
155
188
|
end
|
156
189
|
|
190
|
+
context "when headers are provided" do
|
191
|
+
|
192
|
+
let(:headers) { (1..3).each_with_object({}) { |i, result| result["header#{i}"] = "value#{i}" } }
|
193
|
+
|
194
|
+
subject { described_class.delete(path, headers) }
|
195
|
+
|
196
|
+
it "creates a basic request with the provided headers" do
|
197
|
+
expect(HttpStub::Configurer::Request::Http::Basic).to receive(:new).with(hash_including(headers: headers))
|
198
|
+
|
199
|
+
subject
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
context "when no headers are provided" do
|
205
|
+
|
206
|
+
subject { described_class.delete(path) }
|
207
|
+
|
208
|
+
it "creates a basic request with empty headers" do
|
209
|
+
expect(HttpStub::Configurer::Request::Http::Basic).to receive(:new).with(hash_including(headers: {}))
|
210
|
+
|
211
|
+
subject
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
215
|
+
|
157
216
|
it "returns the created basic request" do
|
158
217
|
expect(subject).to eql(basic_request)
|
159
218
|
end
|
@@ -13,9 +13,12 @@ describe HttpStub::Configurer::Request::Http::Multipart do
|
|
13
13
|
|
14
14
|
let(:payload) { { key: "value" } }
|
15
15
|
let(:response_files) { [] }
|
16
|
+
|
17
|
+
let(:path) { "some/model/path" }
|
16
18
|
let(:model) { HttpStub::Configurer::Request::SomeModel.new(payload: payload, response_files: response_files) }
|
19
|
+
let(:args) { { path: path , model: model } }
|
17
20
|
|
18
|
-
let(:multipart_request) { HttpStub::Configurer::Request::Http::Multipart.new(
|
21
|
+
let(:multipart_request) { HttpStub::Configurer::Request::Http::Multipart.new(args) }
|
19
22
|
|
20
23
|
describe "#to_http_request" do
|
21
24
|
|
@@ -34,14 +37,16 @@ describe HttpStub::Configurer::Request::Http::Multipart do
|
|
34
37
|
expect(subject).to eql(http_multipart_request)
|
35
38
|
end
|
36
39
|
|
37
|
-
it "creates a HTTP request with
|
38
|
-
expect(Net::HTTP::Post::Multipart).to receive(:new).with("/http_stub/
|
40
|
+
it "creates a HTTP request with the provided path prefixed with http_stub scoping" do
|
41
|
+
expect(Net::HTTP::Post::Multipart).to receive(:new).with("/http_stub/some/model/path", anything, anything)
|
39
42
|
|
40
43
|
subject
|
41
44
|
end
|
42
45
|
|
43
46
|
it "creates a HTTP request with a payload parameter containing the JSON representation of the payload" do
|
44
|
-
expect(Net::HTTP::Post::Multipart).to
|
47
|
+
expect(Net::HTTP::Post::Multipart).to(
|
48
|
+
receive(:new).with(anything, hash_including(payload: payload.to_json), anything)
|
49
|
+
)
|
45
50
|
|
46
51
|
subject
|
47
52
|
end
|
@@ -63,7 +68,9 @@ describe HttpStub::Configurer::Request::Http::Multipart do
|
|
63
68
|
)
|
64
69
|
result.tap { |hash| hash["response_file_#{response_file.id}"] = upload_file }
|
65
70
|
end
|
66
|
-
expect(Net::HTTP::Post::Multipart).to
|
71
|
+
expect(Net::HTTP::Post::Multipart).to(
|
72
|
+
receive(:new).with(anything, hash_including(expected_upload_parameters), anything)
|
73
|
+
)
|
67
74
|
|
68
75
|
subject
|
69
76
|
end
|
@@ -73,7 +80,33 @@ describe HttpStub::Configurer::Request::Http::Multipart do
|
|
73
80
|
context "when the payload contains no response files" do
|
74
81
|
|
75
82
|
it "creates a HTTP request with no upload parameters" do
|
76
|
-
expect(Net::HTTP::Post::Multipart).to receive(:new).with(anything, payload: payload.to_json)
|
83
|
+
expect(Net::HTTP::Post::Multipart).to receive(:new).with(anything, { payload: payload.to_json }, anything)
|
84
|
+
|
85
|
+
subject
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
context "when headers are provided" do
|
91
|
+
|
92
|
+
let(:headers) { (1..3).each_with_object({}) { |i, result| result["header#{i}"] = "value#{i}" } }
|
93
|
+
|
94
|
+
let(:args) { { path: path, headers: headers, model: model } }
|
95
|
+
|
96
|
+
it "creates a HTTP request with the provided headers" do
|
97
|
+
expect(Net::HTTP::Post::Multipart).to receive(:new).with(anything, anything, headers)
|
98
|
+
|
99
|
+
subject
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
context "when no headers are provided" do
|
105
|
+
|
106
|
+
let(:args) { { path: path, model: model } }
|
107
|
+
|
108
|
+
it "creates a HTTP request with empty headers" do
|
109
|
+
expect(Net::HTTP::Post::Multipart).to receive(:new).with(anything, anything, {})
|
77
110
|
|
78
111
|
subject
|
79
112
|
end
|
@@ -1,51 +1,25 @@
|
|
1
1
|
describe HttpStub::Configurer::Request::Stub do
|
2
2
|
|
3
3
|
let(:fixture) { HttpStub::StubFixture.new }
|
4
|
-
let(:stub_response) { instance_double(HttpStub::Configurer::Request::StubResponse)
|
5
|
-
let(:
|
4
|
+
let(:stub_response) { instance_double(HttpStub::Configurer::Request::StubResponse) }
|
5
|
+
let(:stub_triggers) { instance_double(HttpStub::Configurer::Request::Triggers) }
|
6
6
|
|
7
|
-
let(:stub)
|
8
|
-
HttpStub::Configurer::Request::Stub.new(fixture.configurer_payload.merge(triggers: trigger_builders))
|
9
|
-
end
|
10
|
-
|
11
|
-
before(:example) { allow(HttpStub::Configurer::Request::StubResponse).to receive(:new).and_return(stub_response) }
|
12
|
-
|
13
|
-
shared_context "triggers one stub" do
|
14
|
-
|
15
|
-
let(:trigger_payload) { HttpStub::StubFixture.new.configurer_payload }
|
16
|
-
let(:trigger_files) { [] }
|
17
|
-
let(:trigger) do
|
18
|
-
instance_double(HttpStub::Configurer::Request::Stub,
|
19
|
-
payload: trigger_payload, response_files: trigger_files)
|
20
|
-
end
|
21
|
-
let(:trigger_builders) do
|
22
|
-
[ instance_double(HttpStub::Configurer::DSL::StubBuilder, build: trigger) ]
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
shared_context "triggers many stubs" do
|
28
|
-
|
29
|
-
let(:trigger_payloads) { (1..3).map { HttpStub::StubFixture.new.configurer_payload } }
|
30
|
-
let(:triggers_files) { trigger_payloads.map { [] } }
|
31
|
-
let(:triggers) do
|
32
|
-
trigger_payloads.zip(triggers_files).map do |payload, files|
|
33
|
-
instance_double(HttpStub::Configurer::Request::Stub, payload: payload, response_files: files)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
let(:trigger_builders) do
|
37
|
-
triggers.map do |trigger|
|
38
|
-
instance_double(HttpStub::Configurer::DSL::StubBuilder, build: trigger)
|
39
|
-
end
|
40
|
-
end
|
7
|
+
let(:stub) { HttpStub::Configurer::Request::Stub.new(fixture.configurer_payload) }
|
41
8
|
|
9
|
+
before(:example) do
|
10
|
+
allow(HttpStub::Configurer::Request::StubResponse).to receive(:new).and_return(stub_response)
|
11
|
+
allow(HttpStub::Configurer::Request::Triggers).to receive(:new).and_return(stub_triggers)
|
42
12
|
end
|
43
13
|
|
44
14
|
describe "#payload" do
|
45
15
|
|
46
16
|
subject { stub.payload }
|
47
17
|
|
48
|
-
before(:example)
|
18
|
+
before(:example) do
|
19
|
+
allow(HttpStub::Configurer::Request::ControllableValue).to receive(:format)
|
20
|
+
allow(stub_response).to receive(:payload)
|
21
|
+
allow(stub_triggers).to receive(:payload)
|
22
|
+
end
|
49
23
|
|
50
24
|
context "when request headers" do
|
51
25
|
|
@@ -127,21 +101,18 @@ describe HttpStub::Configurer::Request::Stub do
|
|
127
101
|
|
128
102
|
it "creates a stub response with the provided response options" do
|
129
103
|
expect(HttpStub::Configurer::Request::StubResponse).to(
|
130
|
-
receive(:new).with(anything, fixture.response
|
104
|
+
receive(:new).with(anything, fixture.configurer_payload[:response]).and_return(stub_response)
|
131
105
|
)
|
132
106
|
|
133
107
|
subject
|
134
108
|
end
|
135
109
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
trigger_builders.each { |trigger_builder| expect(trigger_builder).to receive(:build) }
|
141
|
-
|
142
|
-
subject
|
143
|
-
end
|
110
|
+
it "creates stub triggers with the provided triggers options" do
|
111
|
+
expect(HttpStub::Configurer::Request::Triggers).to(
|
112
|
+
receive(:new).with(fixture.configurer_payload[:triggers]).and_return(stub_triggers)
|
113
|
+
)
|
144
114
|
|
115
|
+
subject
|
145
116
|
end
|
146
117
|
|
147
118
|
context "builds a hash that" do
|
@@ -180,30 +151,10 @@ describe HttpStub::Configurer::Request::Stub do
|
|
180
151
|
expect(subject).to include(response: "response payload")
|
181
152
|
end
|
182
153
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
it "has a triggers entry containing the stub trigger payload" do
|
187
|
-
expect(subject).to include(triggers: [ trigger_payload ])
|
188
|
-
end
|
189
|
-
|
190
|
-
end
|
191
|
-
|
192
|
-
context "when many triggers are added" do
|
193
|
-
include_context "triggers many stubs"
|
194
|
-
|
195
|
-
it "has a triggers entry containing the stub trigger payloads" do
|
196
|
-
expect(subject).to include(triggers: trigger_payloads)
|
197
|
-
end
|
198
|
-
|
199
|
-
end
|
200
|
-
|
201
|
-
context "when no triggers are added" do
|
202
|
-
|
203
|
-
it "has a triggers entry containing an empty hash" do
|
204
|
-
expect(subject).to include(triggers: [])
|
205
|
-
end
|
154
|
+
it "has an entry containing the triggers payload" do
|
155
|
+
allow(stub_triggers).to receive(:payload).and_return("triggers payload")
|
206
156
|
|
157
|
+
expect(subject).to include(triggers: "triggers payload")
|
207
158
|
end
|
208
159
|
|
209
160
|
end
|
@@ -212,66 +163,57 @@ describe HttpStub::Configurer::Request::Stub do
|
|
212
163
|
|
213
164
|
describe "#response_files" do
|
214
165
|
|
215
|
-
|
166
|
+
let(:stub_response_file) { nil }
|
167
|
+
let(:triggers_response_files) { [] }
|
216
168
|
|
217
|
-
|
218
|
-
|
219
|
-
let(:response_file) { instance_double(HttpStub::Configurer::Request::StubResponseFile) }
|
169
|
+
subject { stub.response_files }
|
220
170
|
|
221
|
-
|
171
|
+
before(:example) do
|
172
|
+
allow(stub_response).to receive(:file).and_return(stub_response_file)
|
173
|
+
allow(stub_triggers).to receive(:response_files).and_return(triggers_response_files)
|
174
|
+
end
|
222
175
|
|
223
|
-
|
224
|
-
include_context "triggers many stubs"
|
176
|
+
context "when the response contains a file" do
|
225
177
|
|
226
|
-
|
227
|
-
trigger_payloads.map { (1..3).map { instance_double(HttpStub::Configurer::Request::StubResponseFile) } }
|
228
|
-
end
|
178
|
+
let(:stub_response_file) { instance_double(HttpStub::Configurer::Request::StubResponseFile) }
|
229
179
|
|
230
|
-
|
231
|
-
expect(subject).to eql(([ response_file ] + triggers_files).flatten)
|
232
|
-
end
|
180
|
+
let(:triggers_response_files) { [] }
|
233
181
|
|
182
|
+
it "includes the stub response's file" do
|
183
|
+
expect(subject).to include(stub_response_file)
|
234
184
|
end
|
235
185
|
|
236
|
-
|
237
|
-
include_context "triggers many stubs"
|
186
|
+
end
|
238
187
|
|
239
|
-
|
188
|
+
context "when the triggers contain files" do
|
240
189
|
|
241
|
-
|
242
|
-
|
243
|
-
|
190
|
+
let(:triggers_response_files) do
|
191
|
+
(1..3).map { instance_double(HttpStub::Configurer::Request::StubResponseFile) }
|
192
|
+
end
|
244
193
|
|
194
|
+
it "includes the triggers files" do
|
195
|
+
expect(subject).to include(*triggers_response_files)
|
245
196
|
end
|
246
197
|
|
247
198
|
end
|
248
199
|
|
249
|
-
context "when the response
|
250
|
-
|
251
|
-
before(:example) { allow(stub_response).to receive(:file).and_return(nil) }
|
252
|
-
|
253
|
-
context "and the triggers contain files" do
|
254
|
-
include_context "triggers many stubs"
|
255
|
-
|
256
|
-
let(:triggers_files) do
|
257
|
-
trigger_payloads.map { (1..3).map { instance_double(HttpStub::Configurer::Request::StubResponseFile) } }
|
258
|
-
end
|
259
|
-
|
260
|
-
it "returns the stub response's file and the triggers files" do
|
261
|
-
expect(subject).to eql(triggers_files.flatten)
|
262
|
-
end
|
200
|
+
context "when both the response and triggers contain files" do
|
263
201
|
|
202
|
+
let(:stub_response_file) { instance_double(HttpStub::Configurer::Request::StubResponseFile) }
|
203
|
+
let(:triggers_response_files) do
|
204
|
+
(1..3).map { instance_double(HttpStub::Configurer::Request::StubResponseFile) }
|
264
205
|
end
|
265
206
|
|
266
|
-
|
267
|
-
|
207
|
+
it "is all the files" do
|
208
|
+
expect(subject).to eql(([ stub_response_file ] + triggers_response_files).flatten)
|
209
|
+
end
|
268
210
|
|
269
|
-
|
211
|
+
end
|
270
212
|
|
271
|
-
|
272
|
-
expect(subject).to eql([])
|
273
|
-
end
|
213
|
+
context "when neither the response or triggers contain files" do
|
274
214
|
|
215
|
+
it "returns an empty array" do
|
216
|
+
expect(subject).to eql([])
|
275
217
|
end
|
276
218
|
|
277
219
|
end
|