http_stub 0.25.1 → 0.26.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,60 +0,0 @@
|
|
1
|
-
module HttpStub
|
2
|
-
module Configurer
|
3
|
-
module DSL
|
4
|
-
|
5
|
-
module Deprecated
|
6
|
-
|
7
|
-
def self.included(mod)
|
8
|
-
mod.extend(HttpStub::Configurer::DSL::Deprecated::Methods)
|
9
|
-
mod.send(:include, HttpStub::Configurer::DSL::Deprecated::Methods)
|
10
|
-
end
|
11
|
-
|
12
|
-
module Methods
|
13
|
-
|
14
|
-
def server_has_started!
|
15
|
-
stub_server.has_started!
|
16
|
-
end
|
17
|
-
|
18
|
-
def stub!(uri, options)
|
19
|
-
stub_server.add_stub! { |stub| add_stub_options_to_builder(stub, uri, options) }
|
20
|
-
end
|
21
|
-
|
22
|
-
alias_method :stub_response!, :stub!
|
23
|
-
|
24
|
-
def stub_activator(activation_uri, stub_uri, options)
|
25
|
-
stub_server.add_activator! do |activator|
|
26
|
-
activator.on(activation_uri)
|
27
|
-
add_stub_options_to_builder(activator, stub_uri, options)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def activate!(uri)
|
32
|
-
stub_server.activate!(uri)
|
33
|
-
end
|
34
|
-
|
35
|
-
def recall_stubs!
|
36
|
-
stub_server.recall_stubs!
|
37
|
-
end
|
38
|
-
|
39
|
-
def clear_stubs!
|
40
|
-
stub_server.clear_stubs!
|
41
|
-
end
|
42
|
-
|
43
|
-
def clear_activators!
|
44
|
-
stub_server.clear_scenarios!
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def add_stub_options_to_builder(stub, uri, options)
|
50
|
-
stub.match_requests({ uri: uri }.merge(options.slice(:method, :headers, :parameters)))
|
51
|
-
stub.respond_with(options[:response])
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module HttpStub
|
2
|
-
module Configurer
|
3
|
-
module DSL
|
4
|
-
|
5
|
-
class EndpointTemplate
|
6
|
-
|
7
|
-
delegate :match_requests, :schema, :respond_with, :trigger, :invoke, to: :@template_stub_builder
|
8
|
-
|
9
|
-
def initialize(server)
|
10
|
-
@server = server
|
11
|
-
@template_stub_builder = HttpStub::Configurer::DSL::StubBuilder.new
|
12
|
-
end
|
13
|
-
|
14
|
-
def build_stub(response_overrides={}, &block)
|
15
|
-
@server.build_stub { |stub| compose_stub(stub, response_overrides, &block) }
|
16
|
-
end
|
17
|
-
|
18
|
-
def add_stub!(response_overrides={}, &block)
|
19
|
-
@server.add_stub! { |stub| compose_stub(stub, response_overrides, &block) }
|
20
|
-
end
|
21
|
-
|
22
|
-
def add_scenario!(name, response_overrides={}, &block)
|
23
|
-
@server.add_scenario_with_one_stub!(name) { |stub| compose_stub(stub, response_overrides, &block) }
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def compose_stub(stub_builder, response_overrides, &block)
|
29
|
-
stub_builder.merge!(@template_stub_builder)
|
30
|
-
stub_builder.respond_with(response_overrides)
|
31
|
-
stub_builder.invoke(&block) if block_given?
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module HttpStub
|
2
|
-
module Configurer
|
3
|
-
module DSL
|
4
|
-
|
5
|
-
class StubActivatorBuilder
|
6
|
-
|
7
|
-
delegate :build, to: :@scenario_builder
|
8
|
-
delegate :match_requests, :respond_with, :trigger, to: :@stub_builder
|
9
|
-
|
10
|
-
def initialize(default_stub_builder)
|
11
|
-
@default_stub_builder = default_stub_builder
|
12
|
-
end
|
13
|
-
|
14
|
-
def on(activation_uri)
|
15
|
-
@scenario_builder = HttpStub::Configurer::DSL::ScenarioBuilder.new(@default_stub_builder, activation_uri)
|
16
|
-
@stub_builder = HttpStub::Configurer::DSL::StubBuilder.new(@default_stub_builder)
|
17
|
-
@scenario_builder.add_stub!(@stub_builder)
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module HttpStub
|
2
|
-
module Configurer
|
3
|
-
module DSL
|
4
|
-
|
5
|
-
module StubBuilderProducer
|
6
|
-
|
7
|
-
def build_stub(&block)
|
8
|
-
builder = HttpStub::Configurer::DSL::StubBuilder.new(@default_stub_builder)
|
9
|
-
builder.invoke(&block) if block_given?
|
10
|
-
builder
|
11
|
-
end
|
12
|
-
|
13
|
-
def add_stubs!(builders)
|
14
|
-
builders.each { |builder| add_stub!(builder) }
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module HttpStub
|
2
|
-
module Server
|
3
|
-
module Scenario
|
4
|
-
|
5
|
-
class Activator
|
6
|
-
|
7
|
-
def initialize(scenario_registry, stub_registry)
|
8
|
-
@scenario_registry = scenario_registry
|
9
|
-
@stub_registry = stub_registry
|
10
|
-
end
|
11
|
-
|
12
|
-
def activate(scenario, logger)
|
13
|
-
@stub_registry.concat(scenario.stubs, logger)
|
14
|
-
scenario.triggered_scenarios.each do |triggered_scenario|
|
15
|
-
scenario_to_activate = @scenario_registry.find(triggered_scenario.name, logger)
|
16
|
-
raise "Scenario not found with name '#{triggered_scenario.name}'" unless scenario_to_activate
|
17
|
-
activate(scenario_to_activate, logger)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
:javascript
|
2
|
-
$(window).load(function() {
|
3
|
-
$("a.activate_scenario").on("click", function(event) {
|
4
|
-
event.preventDefault();
|
5
|
-
var button = $(event.target)
|
6
|
-
button.prop("disabled", true);
|
7
|
-
$.post(
|
8
|
-
"scenarios/activate", { name: button.data("name") }, null, "html"
|
9
|
-
).done(
|
10
|
-
function() {
|
11
|
-
button.html("Activated").css("color", "green");
|
12
|
-
setTimeout(function() { button.html("Activate").css("color", "inherit"); }, 3000);
|
13
|
-
}
|
14
|
-
).fail(
|
15
|
-
function() {
|
16
|
-
button.html("Failed").css("color", "red");
|
17
|
-
setTimeout(function() { button.html("Activate").css("color", "inherit"); }, 3000);
|
18
|
-
}
|
19
|
-
).always(
|
20
|
-
function() { button.prop("disabled", false); }
|
21
|
-
);
|
22
|
-
});
|
23
|
-
});
|
@@ -1,8 +0,0 @@
|
|
1
|
-
%h1 http_stub diagnostics
|
2
|
-
%a{ href: "/http_stub/scenarios", id: :scenarios, class: :link } List Scenarios
|
3
|
-
%br
|
4
|
-
%a{ href: "/http_stub/stubs", id: :stubs, class: :link } List Stubs
|
5
|
-
%br
|
6
|
-
%a{ href: "/http_stub/stubs/matches", id: :stub_matches, class: :link } List Stub Matches
|
7
|
-
%br
|
8
|
-
%a{ href: "/http_stub/stubs/misses", id: :stub_misses, class: :link } List Stub Misses
|
@@ -1,81 +0,0 @@
|
|
1
|
-
describe "Stub activator acceptance" do
|
2
|
-
include_context "configurer integration"
|
3
|
-
|
4
|
-
context "when a configurer that contains a stub activator is initialised" do
|
5
|
-
|
6
|
-
let(:configurer) { HttpStub::Examples::ConfigurerWithDeprecatedActivator.new }
|
7
|
-
|
8
|
-
before(:example) { configurer.class.initialize! }
|
9
|
-
|
10
|
-
context "and the stub is activated" do
|
11
|
-
|
12
|
-
context "and the response contains text" do
|
13
|
-
|
14
|
-
before(:example) { configurer.activate!("an_activator") }
|
15
|
-
|
16
|
-
context "and the stub request is made" do
|
17
|
-
|
18
|
-
let(:response) { HTTParty.get("#{server_uri}/stub_path") }
|
19
|
-
|
20
|
-
it "replays the stubbed response" do
|
21
|
-
expect(response.code).to eql(200)
|
22
|
-
expect(response.body).to eql("Stub activator body")
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
context "and a stub is not activated" do
|
32
|
-
|
33
|
-
context "and the stub request is made" do
|
34
|
-
|
35
|
-
let(:response) { HTTParty.get("#{server_uri}/stub_path") }
|
36
|
-
|
37
|
-
it "responds with a 404 status code" do
|
38
|
-
expect(response.code).to eql(404)
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
context "and initialization activates activators" do
|
46
|
-
|
47
|
-
let(:configurer) { HttpStub::Examples::ConfigurerWithComplexInitializer.new }
|
48
|
-
|
49
|
-
it "registers the activated activator" do
|
50
|
-
response = HTTParty.get("#{server_uri}/activated_during_initialization_stub_path")
|
51
|
-
|
52
|
-
expect(response.code).to eql(200)
|
53
|
-
expect(response.body).to eql("Activated during initialization body")
|
54
|
-
end
|
55
|
-
|
56
|
-
context "and another stub is registered" do
|
57
|
-
|
58
|
-
before(:example) do
|
59
|
-
configurer.stub_response!("/another_stub", method: :get, response: { body: "Another stub body" })
|
60
|
-
end
|
61
|
-
|
62
|
-
context "and the servers remembered stubs are recalled" do
|
63
|
-
|
64
|
-
before(:example) { configurer.recall_stubs! }
|
65
|
-
|
66
|
-
it "retains the activated activator during initialization" do
|
67
|
-
response = HTTParty.get("#{server_uri}/activated_during_initialization_stub_path")
|
68
|
-
|
69
|
-
expect(response.code).to eql(200)
|
70
|
-
expect(response.body).to eql("Activated during initialization body")
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
@@ -1,240 +0,0 @@
|
|
1
|
-
describe HttpStub::Configurer::DSL::Deprecated do
|
2
|
-
|
3
|
-
let(:stub_server) { double("StubServer") }
|
4
|
-
|
5
|
-
shared_context "a method stubbing a response" do
|
6
|
-
|
7
|
-
let(:stub_uri) { "/some/stub/uri" }
|
8
|
-
let(:method) { :put }
|
9
|
-
let(:headers) { { header_key: "header value" } }
|
10
|
-
let(:parameters) { { parameter_key: "parameter value" } }
|
11
|
-
let(:response) { { response_key: "response value" } }
|
12
|
-
let(:options) { { method: method, headers: headers, parameters: parameters, response: response } }
|
13
|
-
|
14
|
-
before(:example) do
|
15
|
-
allow(builder).to receive(:match_requests)
|
16
|
-
allow(builder).to receive(:respond_with)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "causes the builder being added to match requests on the provided uri" do
|
20
|
-
expect(builder).to receive(:match_requests).with(hash_including(uri: stub_uri))
|
21
|
-
|
22
|
-
subject
|
23
|
-
end
|
24
|
-
|
25
|
-
context "when a method is provided" do
|
26
|
-
|
27
|
-
it "causes the builder being added to match requests on the provided method" do
|
28
|
-
expect(builder).to receive(:match_requests).with(hash_including(method: method))
|
29
|
-
|
30
|
-
subject
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when a method is omitted" do
|
36
|
-
|
37
|
-
let(:options) { {} }
|
38
|
-
|
39
|
-
it "causes the builder being added to not match requests based on method" do
|
40
|
-
expect(builder).to receive(:match_requests).with(hash_excluding(:method))
|
41
|
-
|
42
|
-
subject
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
context "when parameters are provided" do
|
48
|
-
|
49
|
-
it "causes the builder being added to match requests on the provided parameters" do
|
50
|
-
expect(builder).to receive(:match_requests).with(hash_including(parameters: parameters))
|
51
|
-
|
52
|
-
subject
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
context "when parameters are omitted" do
|
58
|
-
|
59
|
-
let(:options) { {} }
|
60
|
-
|
61
|
-
it "causes the builder being added to not match requests based on parameters" do
|
62
|
-
expect(builder).to receive(:match_requests).with(hash_excluding(:parameters))
|
63
|
-
|
64
|
-
subject
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
context "when headers are provided" do
|
70
|
-
|
71
|
-
it "causes the builder being added to match requests on the provided headers" do
|
72
|
-
expect(builder).to receive(:match_requests).with(hash_including(headers: headers))
|
73
|
-
|
74
|
-
subject
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
context "when headers are omitted" do
|
80
|
-
|
81
|
-
let(:options) { {} }
|
82
|
-
|
83
|
-
it "causes the builder being added to not match requests based on headers" do
|
84
|
-
expect(builder).to receive(:match_requests).with(hash_excluding(:headers))
|
85
|
-
|
86
|
-
subject
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
it "adds the provided response data to the builder" do
|
92
|
-
expect(builder).to receive(:respond_with).with(response)
|
93
|
-
|
94
|
-
subject
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
shared_examples_for "a deprecated DSL object" do
|
100
|
-
|
101
|
-
[ :recall_stubs!, :clear_stubs! ].each do |stub_server_delegate_method|
|
102
|
-
|
103
|
-
describe "##{stub_server_delegate_method}" do
|
104
|
-
|
105
|
-
it "delegates to the stub server available to the dsl" do
|
106
|
-
expect(stub_server).to receive(stub_server_delegate_method)
|
107
|
-
|
108
|
-
dsl_object.send(stub_server_delegate_method)
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
describe "#server_has_started!" do
|
116
|
-
|
117
|
-
it "informs the stub server that it has started" do
|
118
|
-
expect(stub_server).to receive(:has_started!)
|
119
|
-
|
120
|
-
dsl_object.server_has_started!
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
124
|
-
|
125
|
-
describe "#activate!" do
|
126
|
-
|
127
|
-
let(:activation_uri) { "/some/activation/uri" }
|
128
|
-
|
129
|
-
it "delegates to the stub server available to the dsl" do
|
130
|
-
expect(stub_server).to receive(:activate!).with(activation_uri)
|
131
|
-
|
132
|
-
dsl_object.activate!(activation_uri)
|
133
|
-
end
|
134
|
-
|
135
|
-
end
|
136
|
-
|
137
|
-
[ :stub!, :stub_response! ].each do |method|
|
138
|
-
|
139
|
-
describe "##{method}" do
|
140
|
-
|
141
|
-
include_context "a method stubbing a response"
|
142
|
-
|
143
|
-
let(:builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder) }
|
144
|
-
|
145
|
-
subject { dsl_object.send(method, stub_uri, options) }
|
146
|
-
|
147
|
-
before(:example) { allow(stub_server).to receive(:add_stub!).and_yield(builder) }
|
148
|
-
|
149
|
-
it "adds a stub to the stub server" do
|
150
|
-
expect(stub_server).to receive(:add_stub!)
|
151
|
-
|
152
|
-
subject
|
153
|
-
end
|
154
|
-
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|
158
|
-
|
159
|
-
describe "#stub_activator" do
|
160
|
-
|
161
|
-
let(:activation_uri) { "/some/activation/uri" }
|
162
|
-
|
163
|
-
include_context "a method stubbing a response"
|
164
|
-
|
165
|
-
let(:builder) { instance_double(HttpStub::Configurer::DSL::StubActivatorBuilder) }
|
166
|
-
|
167
|
-
subject { dsl_object.stub_activator(activation_uri, stub_uri, options) }
|
168
|
-
|
169
|
-
before(:example) do
|
170
|
-
allow(stub_server).to receive(:add_activator!).and_yield(builder)
|
171
|
-
allow(builder).to receive(:on)
|
172
|
-
end
|
173
|
-
|
174
|
-
it "adds an activator to the stub server" do
|
175
|
-
expect(stub_server).to receive(:add_activator!)
|
176
|
-
|
177
|
-
subject
|
178
|
-
end
|
179
|
-
|
180
|
-
it "causes the builder being added to activate on the provided uri" do
|
181
|
-
expect(builder).to receive(:on).with(activation_uri)
|
182
|
-
|
183
|
-
subject
|
184
|
-
end
|
185
|
-
|
186
|
-
end
|
187
|
-
|
188
|
-
describe "#clear_activators!" do
|
189
|
-
|
190
|
-
it "informs the stub server to clear scenarios" do
|
191
|
-
expect(stub_server).to receive(:clear_scenarios!)
|
192
|
-
|
193
|
-
dsl_object.clear_activators!
|
194
|
-
end
|
195
|
-
|
196
|
-
end
|
197
|
-
|
198
|
-
end
|
199
|
-
|
200
|
-
context "when included in a class" do
|
201
|
-
|
202
|
-
class HttpStub::Configurer::DSL::DeprecatedTest
|
203
|
-
include HttpStub::Configurer::DSL::Deprecated
|
204
|
-
|
205
|
-
class << self
|
206
|
-
|
207
|
-
attr_accessor :stub_server
|
208
|
-
|
209
|
-
end
|
210
|
-
|
211
|
-
attr_accessor :stub_server
|
212
|
-
|
213
|
-
end
|
214
|
-
|
215
|
-
describe "the class in which the module was included" do
|
216
|
-
|
217
|
-
let(:dsl_object) do
|
218
|
-
HttpStub::Configurer::DSL::DeprecatedTest.stub_server = stub_server
|
219
|
-
HttpStub::Configurer::DSL::DeprecatedTest
|
220
|
-
end
|
221
|
-
|
222
|
-
it_behaves_like "a deprecated DSL object"
|
223
|
-
|
224
|
-
end
|
225
|
-
|
226
|
-
describe "an instance of the class in which the module was included" do
|
227
|
-
|
228
|
-
let(:dsl_object) do
|
229
|
-
dsl_object = HttpStub::Configurer::DSL::DeprecatedTest.new
|
230
|
-
dsl_object.stub_server = stub_server
|
231
|
-
dsl_object
|
232
|
-
end
|
233
|
-
|
234
|
-
it_behaves_like "a deprecated DSL object"
|
235
|
-
|
236
|
-
end
|
237
|
-
|
238
|
-
end
|
239
|
-
|
240
|
-
end
|