http_stub 0.22.4 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/lib/http_stub.rb +15 -5
  3. data/lib/http_stub/configurer/dsl/request_attribute_referencer.rb +19 -0
  4. data/lib/http_stub/configurer/dsl/request_referencer.rb +24 -0
  5. data/lib/http_stub/configurer/dsl/scenario_activator.rb +2 -2
  6. data/lib/http_stub/configurer/dsl/scenario_builder.rb +2 -2
  7. data/lib/http_stub/configurer/dsl/server.rb +4 -4
  8. data/lib/http_stub/configurer/dsl/stub_builder.rb +5 -3
  9. data/lib/http_stub/configurer/request/controllable_value.rb +1 -3
  10. data/lib/http_stub/configurer/request/http/factory.rb +2 -2
  11. data/lib/http_stub/configurer/request/omittable.rb +2 -4
  12. data/lib/http_stub/configurer/request/regexpable.rb +3 -8
  13. data/lib/http_stub/configurer/server/command_processor.rb +5 -7
  14. data/lib/http_stub/configurer/server/facade.rb +2 -4
  15. data/lib/http_stub/extensions/core/hash.rb +4 -11
  16. data/lib/http_stub/extensions/core/hash/formatted.rb +23 -0
  17. data/lib/http_stub/extensions/core/hash/indifferent_and_insensitive_access.rb +24 -0
  18. data/lib/http_stub/extensions/core/hash/with_indifferent_and_insensitive_access.rb +18 -0
  19. data/lib/http_stub/extensions/rack/handler.rb +1 -1
  20. data/lib/http_stub/rake/task_generators.rb +1 -1
  21. data/lib/http_stub/server/application.rb +10 -11
  22. data/lib/http_stub/server/application_helpers.rb +3 -5
  23. data/lib/http_stub/server/daemon.rb +5 -6
  24. data/lib/http_stub/server/request.rb +3 -10
  25. data/lib/http_stub/server/request/headers.rb +25 -0
  26. data/lib/http_stub/server/request/parameters.rb +21 -0
  27. data/lib/http_stub/server/request/request.rb +21 -0
  28. data/lib/http_stub/server/scenario/links.rb +1 -1
  29. data/lib/http_stub/server/stub/controller.rb +1 -1
  30. data/lib/http_stub/server/stub/empty.rb +4 -0
  31. data/lib/http_stub/server/stub/match/hash_matcher.rb +19 -0
  32. data/lib/http_stub/server/stub/match/omitted_value_matcher.rb +1 -3
  33. data/lib/http_stub/server/stub/match/rule/body.rb +2 -4
  34. data/lib/http_stub/server/stub/match/rule/headers.rb +5 -11
  35. data/lib/http_stub/server/stub/match/rule/json_body.rb +3 -5
  36. data/lib/http_stub/server/stub/match/rule/method.rb +1 -1
  37. data/lib/http_stub/server/stub/match/rule/parameters.rb +4 -7
  38. data/lib/http_stub/server/stub/match/rule/simple_body.rb +3 -3
  39. data/lib/http_stub/server/stub/match/rule/truthy.rb +27 -0
  40. data/lib/http_stub/server/stub/match/rule/uri.rb +3 -3
  41. data/lib/http_stub/server/stub/match/string_value_matcher.rb +4 -13
  42. data/lib/http_stub/server/stub/response.rb +5 -2
  43. data/lib/http_stub/server/stub/response/attribute/body.rb +32 -0
  44. data/lib/http_stub/server/stub/response/attribute/headers.rb +26 -0
  45. data/lib/http_stub/server/stub/response/attribute/interpolator.rb +26 -0
  46. data/lib/http_stub/server/stub/response/attribute/interpolator/headers.rb +27 -0
  47. data/lib/http_stub/server/stub/response/attribute/interpolator/parameters.rb +27 -0
  48. data/lib/http_stub/server/stub/response/base.rb +5 -16
  49. data/lib/http_stub/server/stub/response/file.rb +6 -2
  50. data/lib/http_stub/server/stub/response/text.rb +12 -0
  51. data/lib/http_stub/server/stub/stub.rb +4 -0
  52. data/lib/http_stub/version.rb +1 -1
  53. data/spec/acceptance/request_reference_spec.rb +44 -0
  54. data/spec/lib/http_stub/configurer/dsl/request_attribute_referencer_spec.rb +37 -0
  55. data/spec/lib/http_stub/configurer/dsl/request_referencer_spec.rb +37 -0
  56. data/spec/lib/http_stub/configurer/dsl/scenario_activator_spec.rb +14 -14
  57. data/spec/lib/http_stub/configurer/dsl/server_spec.rb +2 -6
  58. data/spec/lib/http_stub/configurer/dsl/stub_builder_spec.rb +34 -8
  59. data/spec/lib/http_stub/{server/formatted_hash_spec.rb → extensions/core/hash/formatted_spec.rb} +4 -6
  60. data/spec/lib/http_stub/{hash_with_indifferent_and_insensitive_access_spec.rb → extensions/core/hash/indifferent_and_insensitive_access_spec.rb} +8 -4
  61. data/spec/lib/http_stub/extensions/core/hash/with_indifferent_and_insensitive_access_spec.rb +41 -0
  62. data/spec/lib/http_stub/extensions/core/hash_spec.rb +11 -129
  63. data/spec/lib/http_stub/server/application_spec.rb +1 -1
  64. data/spec/lib/http_stub/server/payload_file_consolidator_spec.rb +1 -1
  65. data/spec/lib/http_stub/server/request/headers_spec.rb +89 -0
  66. data/spec/lib/http_stub/server/request/parameters_spec.rb +60 -0
  67. data/spec/lib/http_stub/server/request/request_spec.rb +84 -0
  68. data/spec/lib/http_stub/server/request_spec.rb +9 -98
  69. data/spec/lib/http_stub/server/response_spec.rb +2 -6
  70. data/spec/lib/http_stub/server/scenario/controller_spec.rb +1 -1
  71. data/spec/lib/http_stub/server/scenario/parser_spec.rb +3 -1
  72. data/spec/lib/http_stub/server/stub/controller_spec.rb +11 -4
  73. data/spec/lib/http_stub/server/stub/empty_spec.rb +10 -0
  74. data/spec/lib/http_stub/server/stub/match/hash_matcher_spec.rb +122 -0
  75. data/spec/lib/http_stub/server/stub/match/rule/body_spec.rb +4 -4
  76. data/spec/lib/http_stub/server/stub/match/rule/headers_spec.rb +54 -45
  77. data/spec/lib/http_stub/server/stub/match/rule/json_body_spec.rb +5 -5
  78. data/spec/lib/http_stub/server/stub/match/rule/method_spec.rb +19 -17
  79. data/spec/lib/http_stub/server/stub/match/rule/parameters_spec.rb +26 -33
  80. data/spec/lib/http_stub/server/stub/match/rule/simple_body_spec.rb +16 -25
  81. data/spec/lib/http_stub/server/stub/match/{truthy_matcher_spec.rb → rule/truthy_spec.rb} +3 -5
  82. data/spec/lib/http_stub/server/stub/match/rule/uri_spec.rb +16 -25
  83. data/spec/lib/http_stub/server/stub/match/string_value_matcher_spec.rb +2 -12
  84. data/spec/lib/http_stub/server/stub/parser_spec.rb +5 -3
  85. data/spec/lib/http_stub/server/stub/response/attribute/body_spec.rb +98 -0
  86. data/spec/lib/http_stub/server/stub/response/attribute/headers_spec.rb +57 -0
  87. data/spec/lib/http_stub/server/stub/response/attribute/interpolator/headers_spec.rb +53 -0
  88. data/spec/lib/http_stub/server/stub/response/attribute/interpolator/parameters_spec.rb +53 -0
  89. data/spec/lib/http_stub/server/stub/response/attribute/interpolator_spec.rb +41 -0
  90. data/spec/lib/http_stub/server/stub/response/base_spec.rb +6 -53
  91. data/spec/lib/http_stub/server/stub/response/file_spec.rb +48 -7
  92. data/spec/lib/http_stub/server/stub/response/text_spec.rb +66 -1
  93. data/spec/lib/http_stub/server/stub/stub_spec.rb +25 -4
  94. data/spec/spec_helper.rb +1 -0
  95. data/spec/support/http_stub/server/request_fixture.rb +1 -1
  96. metadata +86 -26
  97. data/lib/http_stub/hash_with_indifferent_and_insensitive_access.rb +0 -18
  98. data/lib/http_stub/server/formatted_hash.rb +0 -18
  99. data/lib/http_stub/server/header_parser.rb +0 -17
  100. data/lib/http_stub/server/stub/match/hash_with_string_value_matchers.rb +0 -26
  101. data/lib/http_stub/server/stub/match/truthy_matcher.rb +0 -25
  102. data/spec/lib/http_stub/server/header_parser_spec.rb +0 -51
  103. data/spec/lib/http_stub/server/stub/match/hash_with_string_value_matchers_spec.rb +0 -166
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74144ffbb6dae5921a1631ba6a219e0fbc4bdff7
4
- data.tar.gz: e789bd03754aeb44631801f7154a9585d7f08842
3
+ metadata.gz: 83d11882c6f2e8da679ce7ea3385600f36aa6a80
4
+ data.tar.gz: f6d82ab5f7aec1b153f82eeee569090851bb45a6
5
5
  SHA512:
6
- metadata.gz: 73947db83ba0eb75d7b40028c3f1868f77aa34123d6ef8822e39648062312d21fbe4eec0331df59b095078373d99f9b7e5b2a076e880c0dca27d77e7bdb6b62b
7
- data.tar.gz: f715347c8d45c0109c25ec08d704797301b2d8b803ab15c64d4a21d37e736effa4fb7cb27c5a5f615db32491e7724019cfe2f67abb7f88be91f1672e99f91550
6
+ metadata.gz: a0a219718f1abb17958d155c0b0e87def0f8f4fca68c30a5908d14726756912d65d41169c861abfb1f1e728b96395ddc4ce9871b82c00ad01ebc654bdca651a1
7
+ data.tar.gz: 169a55811bea9ed005aee6aee936f7472c8c0820427f2993ae34bc26f335f6d70d449ec082029098874b609fd00ef2d03174266c13dc134d1b459c7487a1ba5a
data/lib/http_stub.rb CHANGED
@@ -17,19 +17,22 @@ require 'active_support/core_ext/hash/slice'
17
17
  require 'active_support/core_ext/hash/deep_merge'
18
18
  require 'active_support/core_ext/hash/indifferent_access'
19
19
 
20
- require_relative 'http_stub/hash_with_indifferent_and_insensitive_access'
20
+ require_relative 'http_stub/extensions/core/hash/formatted'
21
+ require_relative 'http_stub/extensions/core/hash/indifferent_and_insensitive_access'
22
+ require_relative 'http_stub/extensions/core/hash/with_indifferent_and_insensitive_access'
21
23
  require_relative 'http_stub/extensions/core/hash'
22
24
  require_relative 'http_stub/extensions/rack/handler'
23
- require_relative 'http_stub/server/formatted_hash'
24
- require_relative 'http_stub/server/header_parser'
25
+ require_relative 'http_stub/server/request/parameters'
26
+ require_relative 'http_stub/server/request/headers'
27
+ require_relative 'http_stub/server/request/request'
25
28
  require_relative 'http_stub/server/request'
26
29
  require_relative 'http_stub/server/registry'
27
30
  require_relative 'http_stub/server/stub/match/omitted_value_matcher'
28
31
  require_relative 'http_stub/server/stub/match/regexp_value_matcher'
29
32
  require_relative 'http_stub/server/stub/match/exact_value_matcher'
30
33
  require_relative 'http_stub/server/stub/match/string_value_matcher'
31
- require_relative 'http_stub/server/stub/match/hash_with_string_value_matchers'
32
- require_relative 'http_stub/server/stub/match/truthy_matcher'
34
+ require_relative 'http_stub/server/stub/match/hash_matcher'
35
+ require_relative 'http_stub/server/stub/match/rule/truthy'
33
36
  require_relative 'http_stub/server/stub/match/rule/uri'
34
37
  require_relative 'http_stub/server/stub/match/rule/method'
35
38
  require_relative 'http_stub/server/stub/match/rule/headers'
@@ -37,6 +40,11 @@ require_relative 'http_stub/server/stub/match/rule/parameters'
37
40
  require_relative 'http_stub/server/stub/match/rule/simple_body'
38
41
  require_relative 'http_stub/server/stub/match/rule/json_body'
39
42
  require_relative 'http_stub/server/stub/match/rule/body'
43
+ require_relative 'http_stub/server/stub/response/attribute/interpolator/headers'
44
+ require_relative 'http_stub/server/stub/response/attribute/interpolator/parameters'
45
+ require_relative 'http_stub/server/stub/response/attribute/interpolator'
46
+ require_relative 'http_stub/server/stub/response/attribute/headers'
47
+ require_relative 'http_stub/server/stub/response/attribute/body'
40
48
  require_relative 'http_stub/server/stub/response/base'
41
49
  require_relative 'http_stub/server/stub/response/text'
42
50
  require_relative 'http_stub/server/stub/response/file'
@@ -77,6 +85,8 @@ require_relative 'http_stub/configurer/server/command_processor'
77
85
  require_relative 'http_stub/configurer/server/buffered_command_processor'
78
86
  require_relative 'http_stub/configurer/server/request_processor'
79
87
  require_relative 'http_stub/configurer/server/facade'
88
+ require_relative 'http_stub/configurer/dsl/request_attribute_referencer'
89
+ require_relative 'http_stub/configurer/dsl/request_referencer'
80
90
  require_relative 'http_stub/configurer/dsl/stub_builder'
81
91
  require_relative 'http_stub/configurer/dsl/stub_builder_producer'
82
92
  require_relative 'http_stub/configurer/dsl/scenario_activator'
@@ -0,0 +1,19 @@
1
+ module HttpStub
2
+ module Configurer
3
+ module DSL
4
+
5
+ class RequestAttributeReferencer
6
+
7
+ def initialize(attribute_type)
8
+ @attribute_type = attribute_type
9
+ end
10
+
11
+ def [](name)
12
+ "control:request.#{@attribute_type}[#{name}]"
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ module HttpStub
2
+ module Configurer
3
+ module DSL
4
+
5
+ class RequestReferencer
6
+
7
+ def initialize
8
+ @parameter_referencer = HttpStub::Configurer::DSL::RequestAttributeReferencer.new(:parameters)
9
+ @header_referencer = HttpStub::Configurer::DSL::RequestAttributeReferencer.new(:headers)
10
+ end
11
+
12
+ def parameters
13
+ @parameter_referencer
14
+ end
15
+
16
+ def headers
17
+ @header_referencer
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -4,8 +4,8 @@ module HttpStub
4
4
 
5
5
  module ScenarioActivator
6
6
 
7
- def activate!(*uri)
8
- activate_all!(uri.flatten)
7
+ def activate!(*names)
8
+ activate_all!(names.flatten)
9
9
  end
10
10
 
11
11
  end
@@ -26,8 +26,8 @@ module HttpStub
26
26
 
27
27
  private
28
28
 
29
- def activate_all!(uris)
30
- @triggered_scenario_names.concat(uris)
29
+ def activate_all!(names)
30
+ @triggered_scenario_names.concat(names)
31
31
  end
32
32
 
33
33
  end
@@ -38,9 +38,9 @@ module HttpStub
38
38
  @server_facade.stub_response(resolved_builder.build)
39
39
  end
40
40
 
41
- def add_scenario!(name, &block)
41
+ def add_scenario!(name, &_block)
42
42
  builder = HttpStub::Configurer::DSL::ScenarioBuilder.new(@default_stub_builder, name)
43
- block.call(builder)
43
+ yield builder
44
44
  @server_facade.define_scenario(builder.build)
45
45
  end
46
46
 
@@ -54,9 +54,9 @@ module HttpStub
54
54
  HttpStub::Configurer::DSL::EndpointTemplate.new(self).tap { |template| template.invoke(&block) }
55
55
  end
56
56
 
57
- def add_activator!(&block)
57
+ def add_activator!(&_block)
58
58
  builder = HttpStub::Configurer::DSL::StubActivatorBuilder.new(@default_stub_builder)
59
- block.call(builder)
59
+ yield builder
60
60
  @server_facade.define_scenario(builder.build)
61
61
  end
62
62
 
@@ -21,8 +21,10 @@ module HttpStub
21
21
  { schema: { type: type, definition: definition } }
22
22
  end
23
23
 
24
- def respond_with(args)
25
- self.tap { @response.deep_merge!(args) }
24
+ def respond_with(args={}, &_block)
25
+ resolved_args = args
26
+ resolved_args = yield HttpStub::Configurer::DSL::RequestReferencer.new if block_given?
27
+ self.tap { @response.deep_merge!(resolved_args) }
26
28
  end
27
29
 
28
30
  def trigger(stub_builder_or_builders)
@@ -33,7 +35,7 @@ module HttpStub
33
35
  end
34
36
 
35
37
  def invoke(&block)
36
- block.arity == 0 ? self.instance_eval(&block) : block.call(self)
38
+ block.arity == 0 ? self.instance_eval(&block) : (yield self)
37
39
  end
38
40
 
39
41
  def merge!(stub_builder)
@@ -4,12 +4,10 @@ module HttpStub
4
4
 
5
5
  class ControllableValue
6
6
 
7
- private
8
-
9
7
  CONTROL_FORMATTERS = [ HttpStub::Configurer::Request::Regexpable,
10
8
  HttpStub::Configurer::Request::Omittable ].freeze
11
9
 
12
- public
10
+ private_constant :CONTROL_FORMATTERS
13
11
 
14
12
  def self.format(value)
15
13
  CONTROL_FORMATTERS.reduce(value) { |result, formatter| formatter.format(result) }
@@ -25,10 +25,10 @@ module HttpStub
25
25
 
26
26
  private
27
27
 
28
- def create_basic_request(request_method, path, &block)
28
+ def create_basic_request(request_method, path, &_block)
29
29
  http_request_class = Net::HTTP.const_get(request_method.to_s.capitalize)
30
30
  http_request = http_request_class.new(path)
31
- block.call(http_request) if block_given?
31
+ yield http_request if block_given?
32
32
  HttpStub::Configurer::Request::Http::Basic.new(http_request)
33
33
  end
34
34
 
@@ -12,11 +12,9 @@ module HttpStub
12
12
 
13
13
  private
14
14
 
15
- def format_hash(value)
16
- value.reduce({}) do |result, entry|
17
- key, value = entry
15
+ def format_hash(hash)
16
+ hash.each_with_object({}) do |(key, value), result|
18
17
  result[key] = value == :omitted ? "control:omitted" : value
19
- result
20
18
  end
21
19
  end
22
20
 
@@ -6,11 +6,9 @@ module HttpStub
6
6
 
7
7
  class << self
8
8
 
9
- private
10
-
11
9
  FORMATTERS = { Regexp => :format_regexp, Hash => :format_hash }.freeze
12
10
 
13
- public
11
+ private_constant :FORMATTERS
14
12
 
15
13
  def format(value)
16
14
  formatter = FORMATTERS.find { |formatter_entry| value.is_a?(formatter_entry[0]) }
@@ -20,14 +18,11 @@ module HttpStub
20
18
  private
21
19
 
22
20
  def format_regexp(regexp)
23
- "regexp:#{regexp.source.gsub(/\\\//, "/")}"
21
+ "regexp:#{regexp.source.gsub(%r{\\\/}, "/")}"
24
22
  end
25
23
 
26
24
  def format_hash(hash)
27
- hash.reduce({}) do |result, entry|
28
- result[entry[0]] = format(entry[1])
29
- result
30
- end
25
+ hash.each_with_object({}) { |entry, result| result[entry[0]] = format(entry[1]) }
31
26
  end
32
27
 
33
28
  end
@@ -9,13 +9,11 @@ module HttpStub
9
9
  end
10
10
 
11
11
  def process(command)
12
- begin
13
- response = Net::HTTP.start(host, port) { |http| http.request(command.http_request) }
14
- raise "#{error_message_prefix(command)}: #{response.code} #{response.message}" unless response.code == "200"
15
- response
16
- rescue Exception => exc
17
- raise "#{error_message_prefix(command)}: #{exc}"
18
- end
12
+ response = Net::HTTP.start(host, port) { |http| http.request(command.http_request) }
13
+ raise "#{error_message_prefix(command)}: #{response.code} #{response.message}" unless response.code == "200"
14
+ response
15
+ rescue StandardError => err
16
+ raise "#{error_message_prefix(command)}: #{err}"
19
17
  end
20
18
 
21
19
  private
@@ -4,14 +4,12 @@ module HttpStub
4
4
 
5
5
  class Facade
6
6
 
7
- private
8
-
9
7
  STUBS_BASE_URI = "/http_stub/stubs".freeze
10
8
  STUB_MEMORY_URI = "#{STUBS_BASE_URI}/memory".freeze
11
9
  SCENARIOS_BASE_URI = "/http_stub/scenarios".freeze
12
10
  SCENARIO_ACTIVATION_URI = "#{SCENARIOS_BASE_URI}/activate".freeze
13
11
 
14
- public
12
+ private_constant :STUBS_BASE_URI, :STUB_MEMORY_URI, :SCENARIOS_BASE_URI, :SCENARIO_ACTIVATION_URI
15
13
 
16
14
  def initialize(configurer)
17
15
  @request_processor = HttpStub::Configurer::Server::RequestProcessor.new(configurer)
@@ -32,7 +30,7 @@ module HttpStub
32
30
  end
33
31
 
34
32
  def activate(scenario_name)
35
- request = HttpStub::Configurer::Request::Http::Factory.post(SCENARIO_ACTIVATION_URI, :name => scenario_name)
33
+ request = HttpStub::Configurer::Request::Http::Factory.post(SCENARIO_ACTIVATION_URI, name: scenario_name)
36
34
  @request_processor.submit(
37
35
  request: request,
38
36
  description: "activating '#{scenario_name}'"
@@ -4,21 +4,14 @@ module HttpStub
4
4
 
5
5
  module Hash
6
6
 
7
- def downcase_and_underscore_keys
8
- self.reduce({}) do |result, element|
9
- result[element[0].is_a?(::String) ? element[0].downcase.gsub(/-/, '_') : element[0]] = element[1]
10
- result
11
- end
12
- end
13
-
14
- def has_hash?(other_hash)
15
- other_hash.nil? || other_hash.reduce(true) do |result, element|
16
- result && (self[element[0]] == element[1])
7
+ def underscore_keys
8
+ self.each_with_object({}) do |element, result|
9
+ result[element[0].is_a?(::String) ? element[0].tr("-", "_") : element[0]] = element[1]
17
10
  end
18
11
  end
19
12
 
20
13
  def with_indifferent_and_insensitive_access
21
- HttpStub::HashWithIndifferentAndInsensitiveAccess.new(self)
14
+ HttpStub::Extensions::Core::Hash::WithIndifferentAndInsensitiveAccess.new(self)
22
15
  end
23
16
 
24
17
  end
@@ -0,0 +1,23 @@
1
+ module HttpStub
2
+ module Extensions
3
+ module Core
4
+ module Hash
5
+
6
+ module Formatted
7
+
8
+ def initialize(hash, key_value_delimiter, entry_delimiter=", ")
9
+ self.merge!(hash || {})
10
+ @key_value_delimiter = key_value_delimiter
11
+ @entry_delimiter = entry_delimiter
12
+ end
13
+
14
+ def to_s
15
+ self.map { |key_and_value| key_and_value.map(&:to_s).join(@key_value_delimiter) }.join(@entry_delimiter)
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ module HttpStub
2
+ module Extensions
3
+ module Core
4
+ module Hash
5
+
6
+ module IndifferentAndInsensitiveAccess
7
+
8
+ def [](key)
9
+ self.key?(key) ? super : indifferent_and_insensitive_find(key)
10
+ end
11
+
12
+ private
13
+
14
+ def indifferent_and_insensitive_find(key)
15
+ entry = self.find { |entry_key, _entry_value| entry_key.to_s.casecmp(key.to_s) == 0 }
16
+ entry ? entry[1] : nil
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ module HttpStub
2
+ module Extensions
3
+ module Core
4
+ module Hash
5
+
6
+ class WithIndifferentAndInsensitiveAccess < ::Hash
7
+ include HttpStub::Extensions::Core::Hash::IndifferentAndInsensitiveAccess
8
+
9
+ def initialize(hash={})
10
+ self.merge!(hash || {})
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -15,7 +15,7 @@ module HttpStub
15
15
 
16
16
  def get_with_run_check(server)
17
17
  handler = get_without_run_check(server)
18
- raise NameError.new("#{server} Rack handler is invalid") unless handler.respond_to?(:run)
18
+ raise NameError, "#{server} Rack handler is invalid" unless handler.respond_to?(:run)
19
19
  handler
20
20
  end
21
21
 
@@ -1,5 +1,5 @@
1
1
  require ::File.expand_path('../../../http_stub', __FILE__)
2
- require 'rake/tasklib' unless defined? (::Rake::TaskLib)
2
+ require 'rake/tasklib' unless defined? ::Rake::TaskLib
3
3
 
4
4
  require 'http_server_manager/rake/task_generators'
5
5
 
@@ -3,6 +3,10 @@ module HttpStub
3
3
 
4
4
  class Application < Sinatra::Base
5
5
 
6
+ SUPPORTED_REQUEST_TYPES = [ :get, :post, :put, :delete, :patch, :options ].freeze
7
+
8
+ private_constant :SUPPORTED_REQUEST_TYPES
9
+
6
10
  set :root, File.dirname(__FILE__)
7
11
 
8
12
  register Sinatra::Partial
@@ -10,6 +14,11 @@ module HttpStub
10
14
  enable :dump_errors, :logging, :partial_underscores
11
15
  disable :protection
12
16
 
17
+ def self.any_request_type(path, opts={}, &block)
18
+ SUPPORTED_REQUEST_TYPES.each { |type| self.send(type, path, opts, &block) }
19
+ end
20
+ private_class_method :any_request_type
21
+
13
22
  def initialize
14
23
  super()
15
24
  @match_result_registry = HttpStub::Server::Registry.new("match result")
@@ -19,21 +28,11 @@ module HttpStub
19
28
  @scenario_controller = HttpStub::Server::Scenario::Controller.new(@scenario_registry, @stub_registry)
20
29
  end
21
30
 
22
- private
23
-
24
- SUPPORTED_REQUEST_TYPES = [ :get, :post, :put, :delete, :patch, :options ].freeze
25
-
26
- def self.any_request_type(path, opts={}, &block)
27
- SUPPORTED_REQUEST_TYPES.each { |type| self.send(type, path, opts, &block) }
28
- end
29
-
30
31
  before do
31
32
  @response_pipeline = HttpStub::Server::ResponsePipeline.new(self)
32
- @http_stub_request = HttpStub::Server::Request.new(request)
33
+ @http_stub_request = HttpStub::Server::Request.create(request)
33
34
  end
34
35
 
35
- public
36
-
37
36
  get "/http_stub" do
38
37
  haml :index, {}
39
38
  end