http_stub 0.15.5 → 0.16.0.pre1
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 +37 -27
- data/lib/http_stub/configurer.rb +2 -2
- data/lib/http_stub/configurer/dsl/deprecated.rb +60 -0
- data/lib/http_stub/configurer/{server/dsl.rb → dsl/sanctioned.rb} +18 -18
- data/lib/http_stub/configurer/dsl/scenario_activator.rb +15 -0
- data/lib/http_stub/configurer/dsl/scenario_builder.rb +37 -0
- data/lib/http_stub/configurer/dsl/stub_activator_builder.rb +24 -0
- data/lib/http_stub/configurer/{request → dsl}/stub_builder.rb +4 -3
- data/lib/http_stub/configurer/dsl/stub_builder_producer.rb +21 -0
- data/lib/http_stub/configurer/request/http/factory.rb +8 -2
- data/lib/http_stub/configurer/request/scenario.rb +29 -0
- data/lib/http_stub/configurer/server/facade.rb +7 -7
- data/lib/http_stub/server/application.rb +21 -14
- data/lib/http_stub/server/registry.rb +7 -3
- data/lib/http_stub/server/response.rb +3 -3
- data/lib/http_stub/server/scenario.rb +12 -0
- data/lib/http_stub/server/scenario/activator.rb +25 -0
- data/lib/http_stub/server/scenario/controller.rb +36 -0
- data/lib/http_stub/server/scenario/instance.rb +36 -0
- data/lib/http_stub/server/scenario/request_parser.rb +19 -0
- data/lib/http_stub/server/stub.rb +3 -23
- data/lib/http_stub/server/stub/controller.rb +30 -0
- data/lib/http_stub/server/stub/exact_value_matcher.rb +15 -0
- data/lib/http_stub/server/stub/hash_with_string_value_matchers.rb +22 -0
- data/lib/http_stub/server/stub/headers.rb +19 -0
- data/lib/http_stub/server/stub/instance.rb +31 -0
- data/lib/http_stub/server/stub/method.rb +23 -0
- data/lib/http_stub/server/stub/omitted_value_matcher.rb +21 -0
- data/lib/http_stub/server/stub/payload_file_consolidator.rb +18 -0
- data/lib/http_stub/server/stub/regexp_value_matcher.rb +16 -0
- data/lib/http_stub/server/stub/registry.rb +31 -0
- data/lib/http_stub/server/stub/request_header_parser.rb +19 -0
- data/lib/http_stub/server/stub/request_headers.rb +28 -0
- data/lib/http_stub/server/stub/request_parameters.rb +23 -0
- data/lib/http_stub/server/stub/request_parser.rb +17 -0
- data/lib/http_stub/server/stub/response.rb +16 -0
- data/lib/http_stub/server/stub/response/base.rb +64 -0
- data/lib/http_stub/server/stub/response/file.rb +36 -0
- data/lib/http_stub/server/stub/response/text.rb +19 -0
- data/lib/http_stub/server/stub/string_value_matcher.rb +31 -0
- data/lib/http_stub/server/stub/triggers.rb +25 -0
- data/lib/http_stub/server/stub/uri.rb +23 -0
- data/lib/http_stub/server/views/_scenario.haml +16 -0
- data/lib/http_stub/server/views/application.sass +4 -0
- data/lib/http_stub/server/views/scenarios.haml +3 -0
- data/lib/http_stub/version.rb +1 -1
- data/spec/acceptance/activator_spec.rb +81 -0
- data/spec/acceptance/configurer_initialization_spec.rb +158 -0
- data/spec/acceptance/scenario_spec.rb +91 -0
- data/spec/acceptance/stub_control_values_spec.rb +160 -0
- data/spec/acceptance/stub_spec.rb +290 -0
- data/spec/acceptance/stub_trigger_spec.rb +144 -0
- data/spec/lib/http_stub/configurer/{deprecated_dsl_spec.rb → dsl/deprecated_spec.rb} +21 -13
- data/spec/lib/http_stub/configurer/{server/dsl_spec.rb → dsl/sanctioned_spec.rb} +74 -97
- data/spec/lib/http_stub/configurer/dsl/scenario_activator_spec.rb +62 -0
- data/spec/lib/http_stub/configurer/dsl/scenario_builder_spec.rb +146 -0
- data/spec/lib/http_stub/configurer/dsl/stub_activator_builder_spec.rb +120 -0
- data/spec/lib/http_stub/configurer/dsl/stub_builder_producer_spec.rb +105 -0
- data/spec/lib/http_stub/configurer/{request → dsl}/stub_builder_spec.rb +33 -5
- data/spec/lib/http_stub/configurer/request/controllable_value_spec.rb +1 -1
- data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +46 -5
- data/spec/lib/http_stub/configurer/request/omittable_spec.rb +1 -1
- data/spec/lib/http_stub/configurer/request/scenario_spec.rb +69 -0
- data/spec/lib/http_stub/configurer/request/stub_spec.rb +2 -2
- data/spec/lib/http_stub/configurer/server/facade_spec.rb +17 -17
- data/spec/lib/http_stub/configurer_spec.rb +1 -1
- data/spec/lib/http_stub/server/application_integration_spec.rb +23 -13
- data/spec/lib/http_stub/server/application_spec.rb +40 -38
- data/spec/lib/http_stub/server/daemon_spec.rb +2 -2
- data/spec/lib/http_stub/server/registry_spec.rb +66 -17
- data/spec/lib/http_stub/server/{request_parser_spec.rb → request_file_consolidator_spec.rb} +20 -33
- data/spec/lib/http_stub/server/response_pipeline_spec.rb +1 -1
- data/spec/lib/http_stub/server/scenario/activator_spec.rb +106 -0
- data/spec/lib/http_stub/server/scenario/controller_spec.rb +102 -0
- data/spec/lib/http_stub/server/scenario/instance_spec.rb +126 -0
- data/spec/lib/http_stub/server/scenario/request_parser_spec.rb +59 -0
- data/spec/lib/http_stub/server/scenario_spec.rb +24 -0
- data/spec/lib/http_stub/server/{stub_controller_spec.rb → stub/controller_spec.rb} +13 -17
- data/spec/lib/http_stub/server/{exact_value_matcher_spec.rb → stub/exact_value_matcher_spec.rb} +3 -3
- data/spec/lib/http_stub/server/{hash_with_string_value_matchers_spec.rb → stub/hash_with_string_value_matchers_spec.rb} +7 -5
- data/spec/lib/http_stub/server/{headers_spec.rb → stub/headers_spec.rb} +2 -2
- data/spec/lib/http_stub/server/stub/instance_spec.rb +201 -0
- data/spec/lib/http_stub/server/stub/method_spec.rb +95 -0
- data/spec/lib/http_stub/server/{omitted_value_matcher_spec.rb → stub/omitted_value_matcher_spec.rb} +3 -3
- data/spec/lib/http_stub/server/{regexp_value_matcher_spec.rb → stub/regexp_value_matcher_spec.rb} +3 -3
- data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +56 -0
- data/spec/lib/http_stub/server/{stub_registry_spec.rb → stub/registry_spec.rb} +27 -14
- data/spec/lib/http_stub/server/{request_header_parser_spec.rb → stub/request_header_parser_spec.rb} +6 -6
- data/spec/lib/http_stub/server/stub/request_headers_spec.rb +68 -0
- data/spec/lib/http_stub/server/{stub_parameters_spec.rb → stub/request_parameters_spec.rb} +19 -17
- data/spec/lib/http_stub/server/stub/request_parser_spec.rb +56 -0
- data/spec/lib/http_stub/server/{stub_response → stub/response}/base_spec.rb +5 -5
- data/spec/lib/http_stub/server/{stub_response → stub/response}/file_spec.rb +3 -3
- data/spec/lib/http_stub/server/{stub_response → stub/response}/text_spec.rb +3 -3
- data/spec/lib/http_stub/server/{stub_response_spec.rb → stub/response_spec.rb} +8 -8
- data/spec/lib/http_stub/server/{string_value_matcher_spec.rb → stub/string_value_matcher_spec.rb} +25 -13
- data/spec/lib/http_stub/server/{stub_triggers_spec.rb → stub/triggers_spec.rb} +7 -9
- data/spec/lib/http_stub/server/stub/uri_spec.rb +43 -0
- data/spec/lib/http_stub/server/stub_spec.rb +10 -185
- data/spec/spec_helper.rb +10 -5
- data/spec/support/configurer_integration.rb +24 -0
- data/spec/support/scenario_fixture.rb +33 -0
- data/spec/support/stub_fixture.rb +1 -1
- metadata +126 -84
- data/lib/http_stub/configurer/deprecated_dsl.rb +0 -57
- data/lib/http_stub/configurer/request/stub_activator.rb +0 -26
- data/lib/http_stub/configurer/request/stub_activator_builder.rb +0 -25
- data/lib/http_stub/server/exact_value_matcher.rb +0 -13
- data/lib/http_stub/server/hash_with_string_value_matchers.rb +0 -20
- data/lib/http_stub/server/headers.rb +0 -17
- data/lib/http_stub/server/omitted_value_matcher.rb +0 -19
- data/lib/http_stub/server/regexp_value_matcher.rb +0 -14
- data/lib/http_stub/server/request_header_parser.rb +0 -17
- data/lib/http_stub/server/request_parser.rb +0 -29
- data/lib/http_stub/server/string_value_matcher.rb +0 -29
- data/lib/http_stub/server/stub_activator.rb +0 -30
- data/lib/http_stub/server/stub_activator_controller.rb +0 -34
- data/lib/http_stub/server/stub_controller.rb +0 -28
- data/lib/http_stub/server/stub_headers.rb +0 -24
- data/lib/http_stub/server/stub_parameters.rb +0 -21
- data/lib/http_stub/server/stub_registry.rb +0 -29
- data/lib/http_stub/server/stub_response.rb +0 -14
- data/lib/http_stub/server/stub_response/base.rb +0 -62
- data/lib/http_stub/server/stub_response/file.rb +0 -34
- data/lib/http_stub/server/stub_response/text.rb +0 -17
- data/lib/http_stub/server/stub_triggers.rb +0 -23
- data/lib/http_stub/server/stub_uri.rb +0 -21
- data/lib/http_stub/server/views/stub_activators.haml +0 -6
- data/spec/lib/http_stub/configurer/request/stub_activator_builder_spec.rb +0 -119
- data/spec/lib/http_stub/configurer/request/stub_activator_spec.rb +0 -45
- data/spec/lib/http_stub/configurer_integration_spec.rb +0 -837
- data/spec/lib/http_stub/server/stub_activator_controller_spec.rb +0 -95
- data/spec/lib/http_stub/server/stub_activator_spec.rb +0 -83
- data/spec/lib/http_stub/server/stub_headers_spec.rb +0 -68
- data/spec/lib/http_stub/server/stub_registry_integration_spec.rb +0 -62
- data/spec/lib/http_stub/server/stub_uri_spec.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e089a8fb77ad42e2691e6c05fe6a2d766ac07626
|
4
|
+
data.tar.gz: 5bb5f0740862f3e106b5fc9015c85fddb3452d49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51fb2fc9c208dc1af31405a5bc1520c743693cf155a6834d6a555d414c5cf1d722b7eca43edb2c3e7d2e60d8bf7d589776b8f7499097f3d026edf4c3ee416031
|
7
|
+
data.tar.gz: 3403a0f714d40df0e387332213695d672f0f443adff2031b061bd65f46a6b17e989c1bb47677b1842febdf2a5cd3edd71ac7a2fb1a903bc26189226f387a116c
|
data/lib/http_stub.rb
CHANGED
@@ -9,6 +9,7 @@ require 'http_server_manager'
|
|
9
9
|
|
10
10
|
require 'active_support/core_ext/module/aliasing'
|
11
11
|
require 'active_support/core_ext/module/delegation'
|
12
|
+
require 'active_support/core_ext/object/blank'
|
12
13
|
require 'active_support/core_ext/string/inflections'
|
13
14
|
require 'active_support/core_ext/hash/slice'
|
14
15
|
require 'active_support/core_ext/hash/deep_merge'
|
@@ -17,30 +18,36 @@ require 'active_support/core_ext/hash/indifferent_access'
|
|
17
18
|
require_relative 'http_stub/hash_with_indifferent_and_insensitive_access'
|
18
19
|
require_relative 'http_stub/extensions/core/hash'
|
19
20
|
require_relative 'http_stub/extensions/rack/handler'
|
20
|
-
require_relative 'http_stub/server/headers'
|
21
|
-
require_relative 'http_stub/server/omitted_value_matcher'
|
22
|
-
require_relative 'http_stub/server/regexp_value_matcher'
|
23
|
-
require_relative 'http_stub/server/exact_value_matcher'
|
24
|
-
require_relative 'http_stub/server/string_value_matcher'
|
25
|
-
require_relative 'http_stub/server/hash_with_string_value_matchers'
|
26
|
-
require_relative 'http_stub/server/request_header_parser'
|
27
|
-
require_relative 'http_stub/server/stub_uri'
|
28
|
-
require_relative 'http_stub/server/stub_headers'
|
29
|
-
require_relative 'http_stub/server/stub_parameters'
|
30
|
-
require_relative 'http_stub/server/stub_response/base'
|
31
|
-
require_relative 'http_stub/server/stub_response/text'
|
32
|
-
require_relative 'http_stub/server/stub_response/file'
|
33
|
-
require_relative 'http_stub/server/stub_response'
|
34
|
-
require_relative 'http_stub/server/response'
|
35
|
-
require_relative 'http_stub/server/stub_triggers'
|
36
|
-
require_relative 'http_stub/server/stub'
|
37
|
-
require_relative 'http_stub/server/stub_activator'
|
38
|
-
require_relative 'http_stub/server/request_parser'
|
39
21
|
require_relative 'http_stub/server/registry'
|
40
|
-
require_relative 'http_stub/server/
|
22
|
+
require_relative 'http_stub/server/stub/omitted_value_matcher'
|
23
|
+
require_relative 'http_stub/server/stub/regexp_value_matcher'
|
24
|
+
require_relative 'http_stub/server/stub/exact_value_matcher'
|
25
|
+
require_relative 'http_stub/server/stub/string_value_matcher'
|
26
|
+
require_relative 'http_stub/server/stub/hash_with_string_value_matchers'
|
27
|
+
require_relative 'http_stub/server/stub/headers'
|
28
|
+
require_relative 'http_stub/server/stub/request_header_parser'
|
29
|
+
require_relative 'http_stub/server/stub/payload_file_consolidator'
|
30
|
+
require_relative 'http_stub/server/stub/request_parser'
|
31
|
+
require_relative 'http_stub/server/stub/method'
|
32
|
+
require_relative 'http_stub/server/stub/uri'
|
33
|
+
require_relative 'http_stub/server/stub/request_parameters'
|
34
|
+
require_relative 'http_stub/server/stub/request_headers'
|
35
|
+
require_relative 'http_stub/server/stub/response/base'
|
36
|
+
require_relative 'http_stub/server/stub/response/text'
|
37
|
+
require_relative 'http_stub/server/stub/response/file'
|
38
|
+
require_relative 'http_stub/server/stub/response'
|
39
|
+
require_relative 'http_stub/server/stub/triggers'
|
40
|
+
require_relative 'http_stub/server/stub/instance'
|
41
|
+
require_relative 'http_stub/server/stub/registry'
|
42
|
+
require_relative 'http_stub/server/stub/controller'
|
43
|
+
require_relative 'http_stub/server/stub'
|
44
|
+
require_relative 'http_stub/server/scenario/request_parser'
|
45
|
+
require_relative 'http_stub/server/scenario/instance'
|
46
|
+
require_relative 'http_stub/server/scenario/activator'
|
47
|
+
require_relative 'http_stub/server/scenario/controller'
|
48
|
+
require_relative 'http_stub/server/scenario'
|
49
|
+
require_relative 'http_stub/server/response'
|
41
50
|
require_relative 'http_stub/server/response_pipeline'
|
42
|
-
require_relative 'http_stub/server/stub_controller'
|
43
|
-
require_relative 'http_stub/server/stub_activator_controller'
|
44
51
|
require_relative 'http_stub/server/application'
|
45
52
|
require_relative 'http_stub/server/daemon'
|
46
53
|
require_relative 'http_stub/configurer/request/http/basic'
|
@@ -52,14 +59,17 @@ require_relative 'http_stub/configurer/request/controllable_value'
|
|
52
59
|
require_relative 'http_stub/configurer/request/stub_response_file'
|
53
60
|
require_relative 'http_stub/configurer/request/stub_response'
|
54
61
|
require_relative 'http_stub/configurer/request/stub'
|
55
|
-
require_relative 'http_stub/configurer/request/
|
56
|
-
require_relative 'http_stub/configurer/request/stub_activator'
|
57
|
-
require_relative 'http_stub/configurer/request/stub_activator_builder'
|
62
|
+
require_relative 'http_stub/configurer/request/scenario'
|
58
63
|
require_relative 'http_stub/configurer/server/command'
|
59
64
|
require_relative 'http_stub/configurer/server/command_processor'
|
60
65
|
require_relative 'http_stub/configurer/server/buffered_command_processor'
|
61
66
|
require_relative 'http_stub/configurer/server/request_processor'
|
62
67
|
require_relative 'http_stub/configurer/server/facade'
|
63
|
-
require_relative 'http_stub/configurer/
|
64
|
-
require_relative 'http_stub/configurer/
|
68
|
+
require_relative 'http_stub/configurer/dsl/stub_builder'
|
69
|
+
require_relative 'http_stub/configurer/dsl/stub_builder_producer'
|
70
|
+
require_relative 'http_stub/configurer/dsl/scenario_activator'
|
71
|
+
require_relative 'http_stub/configurer/dsl/scenario_builder'
|
72
|
+
require_relative 'http_stub/configurer/dsl/stub_activator_builder'
|
73
|
+
require_relative 'http_stub/configurer/dsl/sanctioned'
|
74
|
+
require_relative 'http_stub/configurer/dsl/deprecated'
|
65
75
|
require_relative 'http_stub/configurer'
|
data/lib/http_stub/configurer.rb
CHANGED
@@ -5,7 +5,7 @@ module HttpStub
|
|
5
5
|
def self.included(mod)
|
6
6
|
mod.extend(HttpStub::Configurer::ClassMethods)
|
7
7
|
mod.send(:include, HttpStub::Configurer::InstanceMethods)
|
8
|
-
mod.send(:include, HttpStub::Configurer::
|
8
|
+
mod.send(:include, HttpStub::Configurer::DSL::Deprecated)
|
9
9
|
end
|
10
10
|
|
11
11
|
module ClassMethods
|
@@ -31,7 +31,7 @@ module HttpStub
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def stub_server
|
34
|
-
@dsl ||= HttpStub::Configurer::
|
34
|
+
@dsl ||= HttpStub::Configurer::DSL::Sanctioned.new(server_facade)
|
35
35
|
end
|
36
36
|
|
37
37
|
def initialize!
|
@@ -0,0 +1,60 @@
|
|
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, 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,8 +1,10 @@
|
|
1
1
|
module HttpStub
|
2
2
|
module Configurer
|
3
|
-
module
|
3
|
+
module DSL
|
4
4
|
|
5
|
-
class
|
5
|
+
class Sanctioned
|
6
|
+
include HttpStub::Configurer::DSL::StubBuilderProducer
|
7
|
+
include HttpStub::Configurer::DSL::ScenarioActivator
|
6
8
|
|
7
9
|
def initialize(server_facade)
|
8
10
|
@server_facade = server_facade
|
@@ -17,29 +19,21 @@ module HttpStub
|
|
17
19
|
@server_facade.server_has_started
|
18
20
|
end
|
19
21
|
|
20
|
-
def build_stub(&block)
|
21
|
-
builder = HttpStub::Configurer::Request::StubBuilder.new(@response_defaults)
|
22
|
-
block.call(builder) if block_given?
|
23
|
-
builder
|
24
|
-
end
|
25
|
-
|
26
22
|
def add_stub!(builder=nil, &block)
|
27
23
|
resolved_builder = builder || self.build_stub(&block)
|
28
24
|
@server_facade.stub_response(resolved_builder.build)
|
29
25
|
end
|
30
26
|
|
31
|
-
def
|
32
|
-
|
27
|
+
def add_scenario!(name, &block)
|
28
|
+
builder = HttpStub::Configurer::DSL::ScenarioBuilder.new(@response_defaults, name)
|
29
|
+
block.call(builder)
|
30
|
+
@server_facade.define_scenario(builder.build)
|
33
31
|
end
|
34
32
|
|
35
33
|
def add_activator!(&block)
|
36
|
-
builder = HttpStub::Configurer::
|
34
|
+
builder = HttpStub::Configurer::DSL::StubActivatorBuilder.new(@response_defaults)
|
37
35
|
block.call(builder)
|
38
|
-
@server_facade.
|
39
|
-
end
|
40
|
-
|
41
|
-
def activate!(uri)
|
42
|
-
@server_facade.activate(uri)
|
36
|
+
@server_facade.define_scenario(builder.build)
|
43
37
|
end
|
44
38
|
|
45
39
|
def remember_stubs
|
@@ -54,8 +48,14 @@ module HttpStub
|
|
54
48
|
@server_facade.clear_stubs
|
55
49
|
end
|
56
50
|
|
57
|
-
def
|
58
|
-
@server_facade.
|
51
|
+
def clear_scenarios!
|
52
|
+
@server_facade.clear_scenarios
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def activate_all!(scenario_names)
|
58
|
+
scenario_names.each { |scenario_name| @server_facade.activate(scenario_name) }
|
59
59
|
end
|
60
60
|
|
61
61
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module HttpStub
|
2
|
+
module Configurer
|
3
|
+
module DSL
|
4
|
+
|
5
|
+
class ScenarioBuilder
|
6
|
+
include HttpStub::Configurer::DSL::StubBuilderProducer
|
7
|
+
include HttpStub::Configurer::DSL::ScenarioActivator
|
8
|
+
|
9
|
+
def initialize(response_defaults, name)
|
10
|
+
@response_defaults = response_defaults
|
11
|
+
@name = name
|
12
|
+
@stub_builders = []
|
13
|
+
@triggered_scenario_names = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_stub!(builder=nil, &block)
|
17
|
+
resolved_builder = builder || build_stub(&block)
|
18
|
+
@stub_builders << resolved_builder
|
19
|
+
end
|
20
|
+
|
21
|
+
def build
|
22
|
+
HttpStub::Configurer::Request::Scenario.new(
|
23
|
+
name: @name, stubs: @stub_builders.map(&:build), triggered_scenario_names: @triggered_scenario_names
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def activate_all!(uris)
|
30
|
+
@triggered_scenario_names.concat(uris)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,24 @@
|
|
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(response_defaults)
|
11
|
+
@response_defaults = response_defaults
|
12
|
+
end
|
13
|
+
|
14
|
+
def on(activation_uri)
|
15
|
+
@scenario_builder = HttpStub::Configurer::DSL::ScenarioBuilder.new(@response_defaults, activation_uri)
|
16
|
+
@stub_builder = HttpStub::Configurer::DSL::StubBuilder.new(@response_defaults)
|
17
|
+
@scenario_builder.add_stub!(@stub_builder)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module HttpStub
|
2
2
|
module Configurer
|
3
|
-
module
|
3
|
+
module DSL
|
4
4
|
|
5
5
|
class StubBuilder
|
6
6
|
|
@@ -10,17 +10,18 @@ module HttpStub
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def match_requests(uri, args={})
|
13
|
-
@request = { uri: uri }.merge(args)
|
13
|
+
self.tap { @request = { uri: uri }.merge(args) }
|
14
14
|
end
|
15
15
|
|
16
16
|
def respond_with(args)
|
17
|
-
@response.deep_merge!(args)
|
17
|
+
self.tap { @response.deep_merge!(args) }
|
18
18
|
end
|
19
19
|
|
20
20
|
def trigger(stub_builder_or_builders)
|
21
21
|
resolved_builders =
|
22
22
|
stub_builder_or_builders.is_a?(Array) ? stub_builder_or_builders : [ stub_builder_or_builders ]
|
23
23
|
@triggers.concat(resolved_builders)
|
24
|
+
self
|
24
25
|
end
|
25
26
|
|
26
27
|
def build
|
@@ -0,0 +1,21 @@
|
|
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(@response_defaults)
|
9
|
+
block.arity == 0 ? builder.instance_eval(&block) : block.call(builder) 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
|
@@ -11,8 +11,14 @@ module HttpStub
|
|
11
11
|
HttpStub::Configurer::Request::Http::Multipart.new("/stubs", model)
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
HttpStub::Configurer::Request::Http::Multipart.new("/stubs/
|
14
|
+
def scenario(model)
|
15
|
+
HttpStub::Configurer::Request::Http::Multipart.new("/stubs/scenarios", model)
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method :stub_activator, :scenario
|
19
|
+
|
20
|
+
def activate(uri)
|
21
|
+
get(uri.start_with?("/") ? uri : "/#{uri}")
|
16
22
|
end
|
17
23
|
|
18
24
|
def get(path)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module HttpStub
|
2
|
+
module Configurer
|
3
|
+
module Request
|
4
|
+
|
5
|
+
class Scenario
|
6
|
+
|
7
|
+
def initialize(args)
|
8
|
+
@name = args[:name]
|
9
|
+
@stubs = args[:stubs]
|
10
|
+
@triggered_scenario_names = args[:triggered_scenario_names]
|
11
|
+
end
|
12
|
+
|
13
|
+
def payload
|
14
|
+
{ name: @name, stubs: @stubs.map(&:payload), triggered_scenario_names: @triggered_scenario_names }
|
15
|
+
end
|
16
|
+
|
17
|
+
def response_files
|
18
|
+
@stubs.map(&:response_files).flatten
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
@name
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -15,16 +15,16 @@ module HttpStub
|
|
15
15
|
)
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
18
|
+
def define_scenario(model)
|
19
19
|
@request_processor.submit(
|
20
|
-
request: HttpStub::Configurer::Request::Http::Factory.
|
21
|
-
description: "registering
|
20
|
+
request: HttpStub::Configurer::Request::Http::Factory.scenario(model),
|
21
|
+
description: "registering scenario '#{model}'"
|
22
22
|
)
|
23
23
|
end
|
24
24
|
|
25
25
|
def activate(uri)
|
26
26
|
@request_processor.submit(
|
27
|
-
request: HttpStub::Configurer::Request::Http::Factory.
|
27
|
+
request: HttpStub::Configurer::Request::Http::Factory.activate(uri),
|
28
28
|
description: "activating '#{uri}'"
|
29
29
|
)
|
30
30
|
end
|
@@ -49,10 +49,10 @@ module HttpStub
|
|
49
49
|
description: "clearing stubs")
|
50
50
|
end
|
51
51
|
|
52
|
-
def
|
52
|
+
def clear_scenarios
|
53
53
|
@request_processor.submit(
|
54
|
-
request: HttpStub::Configurer::Request::Http::Factory.delete("/stubs/
|
55
|
-
description: "clearing
|
54
|
+
request: HttpStub::Configurer::Request::Http::Factory.delete("/stubs/scenarios"),
|
55
|
+
description: "clearing scenarios"
|
56
56
|
)
|
57
57
|
end
|
58
58
|
|