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.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/lib/http_stub.rb +37 -27
  3. data/lib/http_stub/configurer.rb +2 -2
  4. data/lib/http_stub/configurer/dsl/deprecated.rb +60 -0
  5. data/lib/http_stub/configurer/{server/dsl.rb → dsl/sanctioned.rb} +18 -18
  6. data/lib/http_stub/configurer/dsl/scenario_activator.rb +15 -0
  7. data/lib/http_stub/configurer/dsl/scenario_builder.rb +37 -0
  8. data/lib/http_stub/configurer/dsl/stub_activator_builder.rb +24 -0
  9. data/lib/http_stub/configurer/{request → dsl}/stub_builder.rb +4 -3
  10. data/lib/http_stub/configurer/dsl/stub_builder_producer.rb +21 -0
  11. data/lib/http_stub/configurer/request/http/factory.rb +8 -2
  12. data/lib/http_stub/configurer/request/scenario.rb +29 -0
  13. data/lib/http_stub/configurer/server/facade.rb +7 -7
  14. data/lib/http_stub/server/application.rb +21 -14
  15. data/lib/http_stub/server/registry.rb +7 -3
  16. data/lib/http_stub/server/response.rb +3 -3
  17. data/lib/http_stub/server/scenario.rb +12 -0
  18. data/lib/http_stub/server/scenario/activator.rb +25 -0
  19. data/lib/http_stub/server/scenario/controller.rb +36 -0
  20. data/lib/http_stub/server/scenario/instance.rb +36 -0
  21. data/lib/http_stub/server/scenario/request_parser.rb +19 -0
  22. data/lib/http_stub/server/stub.rb +3 -23
  23. data/lib/http_stub/server/stub/controller.rb +30 -0
  24. data/lib/http_stub/server/stub/exact_value_matcher.rb +15 -0
  25. data/lib/http_stub/server/stub/hash_with_string_value_matchers.rb +22 -0
  26. data/lib/http_stub/server/stub/headers.rb +19 -0
  27. data/lib/http_stub/server/stub/instance.rb +31 -0
  28. data/lib/http_stub/server/stub/method.rb +23 -0
  29. data/lib/http_stub/server/stub/omitted_value_matcher.rb +21 -0
  30. data/lib/http_stub/server/stub/payload_file_consolidator.rb +18 -0
  31. data/lib/http_stub/server/stub/regexp_value_matcher.rb +16 -0
  32. data/lib/http_stub/server/stub/registry.rb +31 -0
  33. data/lib/http_stub/server/stub/request_header_parser.rb +19 -0
  34. data/lib/http_stub/server/stub/request_headers.rb +28 -0
  35. data/lib/http_stub/server/stub/request_parameters.rb +23 -0
  36. data/lib/http_stub/server/stub/request_parser.rb +17 -0
  37. data/lib/http_stub/server/stub/response.rb +16 -0
  38. data/lib/http_stub/server/stub/response/base.rb +64 -0
  39. data/lib/http_stub/server/stub/response/file.rb +36 -0
  40. data/lib/http_stub/server/stub/response/text.rb +19 -0
  41. data/lib/http_stub/server/stub/string_value_matcher.rb +31 -0
  42. data/lib/http_stub/server/stub/triggers.rb +25 -0
  43. data/lib/http_stub/server/stub/uri.rb +23 -0
  44. data/lib/http_stub/server/views/_scenario.haml +16 -0
  45. data/lib/http_stub/server/views/application.sass +4 -0
  46. data/lib/http_stub/server/views/scenarios.haml +3 -0
  47. data/lib/http_stub/version.rb +1 -1
  48. data/spec/acceptance/activator_spec.rb +81 -0
  49. data/spec/acceptance/configurer_initialization_spec.rb +158 -0
  50. data/spec/acceptance/scenario_spec.rb +91 -0
  51. data/spec/acceptance/stub_control_values_spec.rb +160 -0
  52. data/spec/acceptance/stub_spec.rb +290 -0
  53. data/spec/acceptance/stub_trigger_spec.rb +144 -0
  54. data/spec/lib/http_stub/configurer/{deprecated_dsl_spec.rb → dsl/deprecated_spec.rb} +21 -13
  55. data/spec/lib/http_stub/configurer/{server/dsl_spec.rb → dsl/sanctioned_spec.rb} +74 -97
  56. data/spec/lib/http_stub/configurer/dsl/scenario_activator_spec.rb +62 -0
  57. data/spec/lib/http_stub/configurer/dsl/scenario_builder_spec.rb +146 -0
  58. data/spec/lib/http_stub/configurer/dsl/stub_activator_builder_spec.rb +120 -0
  59. data/spec/lib/http_stub/configurer/dsl/stub_builder_producer_spec.rb +105 -0
  60. data/spec/lib/http_stub/configurer/{request → dsl}/stub_builder_spec.rb +33 -5
  61. data/spec/lib/http_stub/configurer/request/controllable_value_spec.rb +1 -1
  62. data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +46 -5
  63. data/spec/lib/http_stub/configurer/request/omittable_spec.rb +1 -1
  64. data/spec/lib/http_stub/configurer/request/scenario_spec.rb +69 -0
  65. data/spec/lib/http_stub/configurer/request/stub_spec.rb +2 -2
  66. data/spec/lib/http_stub/configurer/server/facade_spec.rb +17 -17
  67. data/spec/lib/http_stub/configurer_spec.rb +1 -1
  68. data/spec/lib/http_stub/server/application_integration_spec.rb +23 -13
  69. data/spec/lib/http_stub/server/application_spec.rb +40 -38
  70. data/spec/lib/http_stub/server/daemon_spec.rb +2 -2
  71. data/spec/lib/http_stub/server/registry_spec.rb +66 -17
  72. data/spec/lib/http_stub/server/{request_parser_spec.rb → request_file_consolidator_spec.rb} +20 -33
  73. data/spec/lib/http_stub/server/response_pipeline_spec.rb +1 -1
  74. data/spec/lib/http_stub/server/scenario/activator_spec.rb +106 -0
  75. data/spec/lib/http_stub/server/scenario/controller_spec.rb +102 -0
  76. data/spec/lib/http_stub/server/scenario/instance_spec.rb +126 -0
  77. data/spec/lib/http_stub/server/scenario/request_parser_spec.rb +59 -0
  78. data/spec/lib/http_stub/server/scenario_spec.rb +24 -0
  79. data/spec/lib/http_stub/server/{stub_controller_spec.rb → stub/controller_spec.rb} +13 -17
  80. data/spec/lib/http_stub/server/{exact_value_matcher_spec.rb → stub/exact_value_matcher_spec.rb} +3 -3
  81. data/spec/lib/http_stub/server/{hash_with_string_value_matchers_spec.rb → stub/hash_with_string_value_matchers_spec.rb} +7 -5
  82. data/spec/lib/http_stub/server/{headers_spec.rb → stub/headers_spec.rb} +2 -2
  83. data/spec/lib/http_stub/server/stub/instance_spec.rb +201 -0
  84. data/spec/lib/http_stub/server/stub/method_spec.rb +95 -0
  85. data/spec/lib/http_stub/server/{omitted_value_matcher_spec.rb → stub/omitted_value_matcher_spec.rb} +3 -3
  86. data/spec/lib/http_stub/server/{regexp_value_matcher_spec.rb → stub/regexp_value_matcher_spec.rb} +3 -3
  87. data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +56 -0
  88. data/spec/lib/http_stub/server/{stub_registry_spec.rb → stub/registry_spec.rb} +27 -14
  89. data/spec/lib/http_stub/server/{request_header_parser_spec.rb → stub/request_header_parser_spec.rb} +6 -6
  90. data/spec/lib/http_stub/server/stub/request_headers_spec.rb +68 -0
  91. data/spec/lib/http_stub/server/{stub_parameters_spec.rb → stub/request_parameters_spec.rb} +19 -17
  92. data/spec/lib/http_stub/server/stub/request_parser_spec.rb +56 -0
  93. data/spec/lib/http_stub/server/{stub_response → stub/response}/base_spec.rb +5 -5
  94. data/spec/lib/http_stub/server/{stub_response → stub/response}/file_spec.rb +3 -3
  95. data/spec/lib/http_stub/server/{stub_response → stub/response}/text_spec.rb +3 -3
  96. data/spec/lib/http_stub/server/{stub_response_spec.rb → stub/response_spec.rb} +8 -8
  97. data/spec/lib/http_stub/server/{string_value_matcher_spec.rb → stub/string_value_matcher_spec.rb} +25 -13
  98. data/spec/lib/http_stub/server/{stub_triggers_spec.rb → stub/triggers_spec.rb} +7 -9
  99. data/spec/lib/http_stub/server/stub/uri_spec.rb +43 -0
  100. data/spec/lib/http_stub/server/stub_spec.rb +10 -185
  101. data/spec/spec_helper.rb +10 -5
  102. data/spec/support/configurer_integration.rb +24 -0
  103. data/spec/support/scenario_fixture.rb +33 -0
  104. data/spec/support/stub_fixture.rb +1 -1
  105. metadata +126 -84
  106. data/lib/http_stub/configurer/deprecated_dsl.rb +0 -57
  107. data/lib/http_stub/configurer/request/stub_activator.rb +0 -26
  108. data/lib/http_stub/configurer/request/stub_activator_builder.rb +0 -25
  109. data/lib/http_stub/server/exact_value_matcher.rb +0 -13
  110. data/lib/http_stub/server/hash_with_string_value_matchers.rb +0 -20
  111. data/lib/http_stub/server/headers.rb +0 -17
  112. data/lib/http_stub/server/omitted_value_matcher.rb +0 -19
  113. data/lib/http_stub/server/regexp_value_matcher.rb +0 -14
  114. data/lib/http_stub/server/request_header_parser.rb +0 -17
  115. data/lib/http_stub/server/request_parser.rb +0 -29
  116. data/lib/http_stub/server/string_value_matcher.rb +0 -29
  117. data/lib/http_stub/server/stub_activator.rb +0 -30
  118. data/lib/http_stub/server/stub_activator_controller.rb +0 -34
  119. data/lib/http_stub/server/stub_controller.rb +0 -28
  120. data/lib/http_stub/server/stub_headers.rb +0 -24
  121. data/lib/http_stub/server/stub_parameters.rb +0 -21
  122. data/lib/http_stub/server/stub_registry.rb +0 -29
  123. data/lib/http_stub/server/stub_response.rb +0 -14
  124. data/lib/http_stub/server/stub_response/base.rb +0 -62
  125. data/lib/http_stub/server/stub_response/file.rb +0 -34
  126. data/lib/http_stub/server/stub_response/text.rb +0 -17
  127. data/lib/http_stub/server/stub_triggers.rb +0 -23
  128. data/lib/http_stub/server/stub_uri.rb +0 -21
  129. data/lib/http_stub/server/views/stub_activators.haml +0 -6
  130. data/spec/lib/http_stub/configurer/request/stub_activator_builder_spec.rb +0 -119
  131. data/spec/lib/http_stub/configurer/request/stub_activator_spec.rb +0 -45
  132. data/spec/lib/http_stub/configurer_integration_spec.rb +0 -837
  133. data/spec/lib/http_stub/server/stub_activator_controller_spec.rb +0 -95
  134. data/spec/lib/http_stub/server/stub_activator_spec.rb +0 -83
  135. data/spec/lib/http_stub/server/stub_headers_spec.rb +0 -68
  136. data/spec/lib/http_stub/server/stub_registry_integration_spec.rb +0 -62
  137. 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: de9073e7cd507e925511a4e9e4ab51c7182cb44c
4
- data.tar.gz: 0922450c8acc9793b0472877dfd2f603008588cf
3
+ metadata.gz: e089a8fb77ad42e2691e6c05fe6a2d766ac07626
4
+ data.tar.gz: 5bb5f0740862f3e106b5fc9015c85fddb3452d49
5
5
  SHA512:
6
- metadata.gz: 3722e4850fd58d0c2f104896e7f8b3662a39f596762ab78e35cebe8bdebe0266d956e94045f57ba1a659d6d4e89a9c163f8ca211da3e25064c5a85af86aad778
7
- data.tar.gz: c9b22acf23548d508c60f5c00bec96b758cfbf2efee142d5e8fa43a3039095403f6b96f113e2703350c7a7949afe9a668a2ec8193f3716b36d33eb496d807aef
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/stub_registry'
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/stub_builder'
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/server/dsl'
64
- require_relative 'http_stub/configurer/deprecated_dsl'
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'
@@ -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::DeprecatedDSL)
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::Server::DSL.new(server_facade)
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 Server
3
+ module DSL
4
4
 
5
- class DSL
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 add_stubs!(builders)
32
- builders.each { |builder| add_stub!(builder) }
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::Request::StubActivatorBuilder.new(@response_defaults)
34
+ builder = HttpStub::Configurer::DSL::StubActivatorBuilder.new(@response_defaults)
37
35
  block.call(builder)
38
- @server_facade.stub_activator(builder.build)
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 clear_activators!
58
- @server_facade.clear_activators
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,15 @@
1
+ module HttpStub
2
+ module Configurer
3
+ module DSL
4
+
5
+ module ScenarioActivator
6
+
7
+ def activate!(*uri)
8
+ activate_all!(uri.flatten)
9
+ end
10
+
11
+ end
12
+
13
+ end
14
+ end
15
+ 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 Request
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 stub_activator(model)
15
- HttpStub::Configurer::Request::Http::Multipart.new("/stubs/activators", model)
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 stub_activator(model)
18
+ def define_scenario(model)
19
19
  @request_processor.submit(
20
- request: HttpStub::Configurer::Request::Http::Factory.stub_activator(model),
21
- description: "registering activator '#{model}'"
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.get(uri),
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 clear_activators
52
+ def clear_scenarios
53
53
  @request_processor.submit(
54
- request: HttpStub::Configurer::Request::Http::Factory.delete("/stubs/activators"),
55
- description: "clearing activators"
54
+ request: HttpStub::Configurer::Request::Http::Factory.delete("/stubs/scenarios"),
55
+ description: "clearing scenarios"
56
56
  )
57
57
  end
58
58