http_stub 0.14.2 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/lib/http_stub/configurer/request/http/basic.rb +21 -0
  3. data/lib/http_stub/configurer/request/http/factory.rb +43 -0
  4. data/lib/http_stub/configurer/request/http/multipart.rb +33 -0
  5. data/lib/http_stub/configurer/request/stub.rb +24 -8
  6. data/lib/http_stub/configurer/request/stub_activator.rb +12 -8
  7. data/lib/http_stub/configurer/request/{stub_activator_payload_builder.rb → stub_activator_builder.rb} +4 -4
  8. data/lib/http_stub/configurer/request/stub_builder.rb +34 -0
  9. data/lib/http_stub/configurer/request/stub_response.rb +40 -0
  10. data/lib/http_stub/configurer/request/stub_response_file.rb +20 -0
  11. data/lib/http_stub/configurer/server/command.rb +5 -1
  12. data/lib/http_stub/configurer/server/command_processor.rb +1 -1
  13. data/lib/http_stub/configurer/server/dsl.rb +4 -4
  14. data/lib/http_stub/configurer/server/facade.rb +25 -11
  15. data/lib/http_stub/extensions/core/hash.rb +26 -0
  16. data/lib/http_stub/rake/server_daemon_tasks.rb +1 -1
  17. data/lib/http_stub/rake/server_tasks.rb +1 -1
  18. data/lib/http_stub/rake/task_generators.rb +3 -3
  19. data/lib/http_stub/server/application.rb +117 -0
  20. data/lib/http_stub/server/daemon.rb +39 -0
  21. data/lib/http_stub/{models → server}/exact_value_matcher.rb +1 -1
  22. data/lib/http_stub/{models → server}/hash_with_string_value_matchers.rb +2 -2
  23. data/lib/http_stub/{models → server}/headers.rb +1 -1
  24. data/lib/http_stub/{models → server}/omitted_value_matcher.rb +1 -1
  25. data/lib/http_stub/{models → server}/regexp_value_matcher.rb +1 -1
  26. data/lib/http_stub/{models → server}/registry.rb +10 -3
  27. data/lib/http_stub/{models → server}/request_header_parser.rb +1 -1
  28. data/lib/http_stub/server/response.rb +13 -0
  29. data/lib/http_stub/server/response_pipeline.rb +18 -0
  30. data/lib/http_stub/{models → server}/string_value_matcher.rb +4 -4
  31. data/lib/http_stub/server/stub.rb +37 -0
  32. data/lib/http_stub/{models → server}/stub_activator.rb +10 -2
  33. data/lib/http_stub/{controllers → server}/stub_activator_controller.rb +5 -5
  34. data/lib/http_stub/{controllers → server}/stub_controller.rb +4 -4
  35. data/lib/http_stub/server/stub_factory.rb +30 -0
  36. data/lib/http_stub/{models → server}/stub_headers.rb +4 -4
  37. data/lib/http_stub/{models → server}/stub_parameters.rb +2 -2
  38. data/lib/http_stub/{models → server}/stub_registry.rb +4 -4
  39. data/lib/http_stub/server/stub_response/base.rb +62 -0
  40. data/lib/http_stub/server/stub_response/file.rb +48 -0
  41. data/lib/http_stub/server/stub_response/text.rb +17 -0
  42. data/lib/http_stub/server/stub_response.rb +14 -0
  43. data/lib/http_stub/{models → server}/stub_triggers.rb +6 -2
  44. data/lib/http_stub/{models → server}/stub_uri.rb +2 -2
  45. data/lib/http_stub/{views → server/views}/_stub.haml +0 -0
  46. data/lib/http_stub/{views → server/views}/application.sass +0 -0
  47. data/lib/http_stub/{views → server/views}/layout.haml +0 -0
  48. data/lib/http_stub/{views → server/views}/stub_activators.haml +0 -0
  49. data/lib/http_stub/{views → server/views}/stubs.haml +0 -0
  50. data/lib/http_stub/version.rb +1 -1
  51. data/lib/http_stub.rb +41 -24
  52. data/spec/lib/http_stub/configurer/deprecated_dsl_spec.rb +2 -2
  53. data/spec/lib/http_stub/configurer/request/http/basic_spec.rb +15 -0
  54. data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +148 -0
  55. data/spec/lib/http_stub/configurer/request/http/multipart_spec.rb +74 -0
  56. data/spec/lib/http_stub/configurer/request/stub_activator_builder_spec.rb +119 -0
  57. data/spec/lib/http_stub/configurer/request/stub_activator_spec.rb +24 -22
  58. data/spec/lib/http_stub/configurer/request/stub_builder_spec.rb +154 -0
  59. data/spec/lib/http_stub/configurer/request/stub_response_spec.rb +136 -0
  60. data/spec/lib/http_stub/configurer/request/stub_spec.rb +238 -17
  61. data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +7 -3
  62. data/spec/lib/http_stub/configurer/server/command_spec.rb +7 -6
  63. data/spec/lib/http_stub/configurer/server/dsl_spec.rb +58 -94
  64. data/spec/lib/http_stub/configurer/server/facade_spec.rb +56 -41
  65. data/spec/lib/http_stub/configurer_integration_spec.rb +180 -81
  66. data/spec/lib/http_stub/{hash_extensions_spec.rb → extensions/core/hash_spec.rb} +1 -1
  67. data/spec/lib/http_stub/rake/server_daemon_tasks_smoke_spec.rb +1 -1
  68. data/spec/lib/http_stub/{server_integration_spec.rb → server/application_integration_spec.rb} +1 -1
  69. data/spec/lib/http_stub/server/application_spec.rb +205 -0
  70. data/spec/lib/http_stub/server/daemon_integration_spec.rb +7 -0
  71. data/spec/lib/http_stub/{server_daemon_spec.rb → server/daemon_spec.rb} +4 -4
  72. data/spec/lib/http_stub/{models → server}/exact_value_matcher_spec.rb +2 -2
  73. data/spec/lib/http_stub/{models → server}/hash_with_string_value_matchers_spec.rb +5 -5
  74. data/spec/lib/http_stub/{models → server}/headers_spec.rb +2 -2
  75. data/spec/lib/http_stub/{models → server}/omitted_value_matcher_spec.rb +2 -2
  76. data/spec/lib/http_stub/{models → server}/regexp_value_matcher_spec.rb +2 -2
  77. data/spec/lib/http_stub/{models → server}/registry_spec.rb +52 -55
  78. data/spec/lib/http_stub/{models → server}/request_header_parser_spec.rb +4 -4
  79. data/spec/lib/http_stub/server/response_pipeline_spec.rb +29 -0
  80. data/spec/lib/http_stub/server/response_spec.rb +41 -0
  81. data/spec/lib/http_stub/{models → server}/string_value_matcher_spec.rb +11 -11
  82. data/spec/lib/http_stub/server/stub_activator_controller_spec.rb +85 -0
  83. data/spec/lib/http_stub/server/stub_activator_spec.rb +124 -0
  84. data/spec/lib/http_stub/server/stub_controller_spec.rb +74 -0
  85. data/spec/lib/http_stub/server/stub_factory_spec.rb +117 -0
  86. data/spec/lib/http_stub/{models → server}/stub_headers_spec.rb +9 -9
  87. data/spec/lib/http_stub/{models → server}/stub_parameters_spec.rb +6 -6
  88. data/spec/lib/http_stub/{models → server}/stub_registry_integration_spec.rb +3 -3
  89. data/spec/lib/http_stub/{models → server}/stub_registry_spec.rb +15 -35
  90. data/spec/lib/http_stub/server/stub_response/base_spec.rb +225 -0
  91. data/spec/lib/http_stub/server/stub_response/file_spec.rb +140 -0
  92. data/spec/lib/http_stub/server/stub_response/text_spec.rb +103 -0
  93. data/spec/lib/http_stub/server/stub_response_spec.rb +49 -0
  94. data/spec/lib/http_stub/{models → server}/stub_spec.rb +34 -18
  95. data/spec/lib/http_stub/{models → server}/stub_triggers_spec.rb +26 -16
  96. data/spec/lib/http_stub/{models → server}/stub_uri_spec.rb +5 -5
  97. data/spec/resources/sample.pdf +0 -0
  98. data/spec/resources/sample.txt +1 -0
  99. data/spec/spec_helper.rb +13 -4
  100. data/spec/support/stub_fixture.rb +106 -0
  101. metadata +148 -102
  102. data/lib/http_stub/configurer/request/stub_payload_builder.rb +0 -46
  103. data/lib/http_stub/hash_extensions.rb +0 -22
  104. data/lib/http_stub/models/request_pipeline.rb +0 -13
  105. data/lib/http_stub/models/response.rb +0 -43
  106. data/lib/http_stub/models/stub.rb +0 -35
  107. data/lib/http_stub/server.rb +0 -114
  108. data/lib/http_stub/server_daemon.rb +0 -36
  109. data/spec/lib/http_stub/configurer/request/stub_activator_payload_builder_spec.rb +0 -103
  110. data/spec/lib/http_stub/configurer/request/stub_payload_builder_spec.rb +0 -304
  111. data/spec/lib/http_stub/controllers/stub_activator_controller_spec.rb +0 -94
  112. data/spec/lib/http_stub/controllers/stub_controller_spec.rb +0 -83
  113. data/spec/lib/http_stub/models/request_pipeline_spec.rb +0 -17
  114. data/spec/lib/http_stub/models/response_spec.rb +0 -206
  115. data/spec/lib/http_stub/models/stub_activator_spec.rb +0 -76
  116. data/spec/lib/http_stub/server_daemon_integration_spec.rb +0 -7
  117. data/spec/lib/http_stub/server_spec.rb +0 -234
  118. data/spec/support/http_stub/configurer/request/stub_payload_builder_shared_context.rb +0 -27
@@ -1,5 +1,5 @@
1
1
  module HttpStub
2
- module Models
2
+ module Server
3
3
 
4
4
  class OmittedValueMatcher
5
5
 
@@ -1,5 +1,5 @@
1
1
  module HttpStub
2
- module Models
2
+ module Server
3
3
 
4
4
  class RegexpValueMatcher
5
5
 
@@ -1,5 +1,5 @@
1
1
  module HttpStub
2
- module Models
2
+ module Server
3
3
 
4
4
  class Registry
5
5
 
@@ -18,16 +18,23 @@ module HttpStub
18
18
  @models.find { |model| model.satisfies?(request) }
19
19
  end
20
20
 
21
+ def last
22
+ @models.first
23
+ end
24
+
21
25
  def all
22
26
  Array.new(@models)
23
27
  end
24
28
 
25
- def copy
26
- Marshal.load(Marshal.dump(self))
29
+ def rollback_to(model)
30
+ starting_index = @models.index(model)
31
+ @models[0..starting_index].each(&:clear)
32
+ @models = @models.slice(starting_index..-1)
27
33
  end
28
34
 
29
35
  def clear(request)
30
36
  request.logger.info "Clearing #{@model_name} registry"
37
+ @models.each(&:clear)
31
38
  @models.clear
32
39
  end
33
40
 
@@ -1,5 +1,5 @@
1
1
  module HttpStub
2
- module Models
2
+ module Server
3
3
 
4
4
  class RequestHeaderParser
5
5
 
@@ -0,0 +1,13 @@
1
+ module HttpStub
2
+ module Server
3
+
4
+ class Response
5
+
6
+ SUCCESS = HttpStub::Server::StubResponse::Text.new("status" => 200, "body" => "OK").freeze
7
+ ERROR = HttpStub::Server::StubResponse::Text.new("status" => 404, "body" => "ERROR").freeze
8
+ EMPTY = HttpStub::Server::StubResponse::Text.new.freeze
9
+
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ module HttpStub
2
+ module Server
3
+
4
+ class ResponsePipeline
5
+
6
+ def initialize(server)
7
+ @server = server
8
+ end
9
+
10
+ def process(response)
11
+ sleep response.delay_in_seconds
12
+ response.serve_on(@server)
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
@@ -1,13 +1,13 @@
1
1
  module HttpStub
2
- module Models
2
+ module Server
3
3
 
4
4
  class StringValueMatcher
5
5
 
6
6
  private
7
7
 
8
- MATCHERS = [ HttpStub::Models::OmittedValueMatcher,
9
- HttpStub::Models::RegexpValueMatcher,
10
- HttpStub::Models::ExactValueMatcher ].freeze
8
+ MATCHERS = [ HttpStub::Server::OmittedValueMatcher,
9
+ HttpStub::Server::RegexpValueMatcher,
10
+ HttpStub::Server::ExactValueMatcher ].freeze
11
11
 
12
12
  public
13
13
 
@@ -0,0 +1,37 @@
1
+ module HttpStub
2
+ module Server
3
+
4
+ class Stub
5
+
6
+ attr_reader :method, :uri, :headers, :parameters, :response, :triggers
7
+
8
+ def initialize(args)
9
+ @method = args["method"]
10
+ @uri = HttpStub::Server::StubUri.new(args["uri"])
11
+ @headers = HttpStub::Server::StubHeaders.new(args["headers"])
12
+ @parameters = HttpStub::Server::StubParameters.new(args["parameters"])
13
+ @response = HttpStub::Server::StubResponse.create(args["response"])
14
+ @triggers = HttpStub::Server::StubTriggers.new(args["triggers"])
15
+ @description = args.to_s
16
+ end
17
+
18
+ def satisfies?(request)
19
+ @uri.match?(request) &&
20
+ @method.downcase == request.request_method.downcase &&
21
+ @headers.match?(request) &&
22
+ @parameters.match?(request)
23
+ end
24
+
25
+ def clear
26
+ @response.clear
27
+ @triggers.clear
28
+ end
29
+
30
+ def to_s
31
+ @description
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+ end
@@ -1,11 +1,15 @@
1
1
  module HttpStub
2
- module Models
2
+ module Server
3
3
 
4
4
  class StubActivator
5
5
 
6
+ def self.create_from(request)
7
+ self.new(JSON.parse(request.params["payload"] || request.body.read))
8
+ end
9
+
6
10
  def initialize(args)
7
11
  @args = args
8
- @stub = HttpStub::Models::Stub.new(args)
12
+ @stub = HttpStub::Server::Stub.new(args)
9
13
  end
10
14
 
11
15
  def satisfies?(request)
@@ -20,6 +24,10 @@ module HttpStub
20
24
  @args["activation_uri"]
21
25
  end
22
26
 
27
+ def clear
28
+ @stub.clear
29
+ end
30
+
23
31
  def to_s
24
32
  @args.to_s
25
33
  end
@@ -1,5 +1,5 @@
1
1
  module HttpStub
2
- module Controllers
2
+ module Server
3
3
 
4
4
  class StubActivatorController
5
5
 
@@ -9,17 +9,17 @@ module HttpStub
9
9
  end
10
10
 
11
11
  def register(request)
12
- @stub_activator_registry.add(HttpStub::Models::StubActivator.new(JSON.parse(request.body.read)), request)
13
- HttpStub::Models::Response::SUCCESS
12
+ @stub_activator_registry.add(HttpStub::Server::StubActivator.create_from(request), request)
13
+ HttpStub::Server::Response::SUCCESS
14
14
  end
15
15
 
16
16
  def activate(request)
17
17
  activator = @stub_activator_registry.find_for(request)
18
18
  if activator
19
19
  @stub_registry.add(activator.the_stub, request)
20
- HttpStub::Models::Response::SUCCESS
20
+ HttpStub::Server::Response::SUCCESS
21
21
  else
22
- HttpStub::Models::Response::EMPTY
22
+ HttpStub::Server::Response::EMPTY
23
23
  end
24
24
  end
25
25
 
@@ -1,5 +1,5 @@
1
1
  module HttpStub
2
- module Controllers
2
+ module Server
3
3
 
4
4
  class StubController
5
5
 
@@ -8,13 +8,13 @@ module HttpStub
8
8
  end
9
9
 
10
10
  def register(request)
11
- @registry.add(HttpStub::Models::Stub.new(JSON.parse(request.body.read)), request)
12
- HttpStub::Models::Response::SUCCESS
11
+ @registry.add(HttpStub::Server::StubFactory.create(request), request)
12
+ HttpStub::Server::Response::SUCCESS
13
13
  end
14
14
 
15
15
  def replay(request)
16
16
  stub = @registry.find_for(request)
17
- stub ? stub.response : HttpStub::Models::Response::EMPTY
17
+ stub ? stub.response : HttpStub::Server::Response::EMPTY
18
18
  end
19
19
 
20
20
  def clear(request)
@@ -0,0 +1,30 @@
1
+ module HttpStub
2
+ module Server
3
+
4
+ class StubFactory
5
+
6
+ class << self
7
+
8
+ def create(request)
9
+ payload = JSON.parse(request.params["payload"] || request.body.read)
10
+ consolidated_payload = consolidate_files_into_payload(payload, request)
11
+ HttpStub::Server::Stub.new(consolidated_payload)
12
+ end
13
+
14
+ private
15
+
16
+ def consolidate_files_into_payload(payload, request)
17
+ response_file = request.params["response_file_#{payload["id"]}"]
18
+ payload["response"]["body"] = response_file if response_file
19
+ payload["triggers"].each do |trigger_payload|
20
+ consolidate_files_into_payload(trigger_payload, request)
21
+ end if payload["triggers"]
22
+ payload
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
@@ -1,11 +1,11 @@
1
1
  module HttpStub
2
- module Models
2
+ module Server
3
3
 
4
- class StubHeaders < HttpStub::Models::Headers
4
+ class StubHeaders < HttpStub::Server::Headers
5
5
 
6
6
  def initialize(headers)
7
7
  super(headers)
8
- @headers = HttpStub::Models::HashWithStringValueMatchers.new((headers || {}).downcase_and_underscore_keys)
8
+ @headers = HttpStub::Server::HashWithStringValueMatchers.new((headers || {}).downcase_and_underscore_keys)
9
9
  end
10
10
 
11
11
  def match?(request)
@@ -15,7 +15,7 @@ module HttpStub
15
15
  private
16
16
 
17
17
  def headers_in(request)
18
- HttpStub::Models::RequestHeaderParser.parse(request)
18
+ HttpStub::Server::RequestHeaderParser.parse(request)
19
19
  end
20
20
 
21
21
  end
@@ -1,10 +1,10 @@
1
1
  module HttpStub
2
- module Models
2
+ module Server
3
3
 
4
4
  class StubParameters
5
5
 
6
6
  def initialize(parameters)
7
- @parameters = HttpStub::Models::HashWithStringValueMatchers.new(parameters || {})
7
+ @parameters = HttpStub::Server::HashWithStringValueMatchers.new(parameters || {})
8
8
  end
9
9
 
10
10
  def match?(request)
@@ -1,12 +1,12 @@
1
1
  module HttpStub
2
- module Models
2
+ module Server
3
3
 
4
4
  class StubRegistry
5
5
 
6
6
  delegate :add, :all, :clear, to: :@registry
7
7
 
8
8
  def initialize
9
- @registry = HttpStub::Models::Registry.new("stub")
9
+ @registry = HttpStub::Server::Registry.new("stub")
10
10
  end
11
11
 
12
12
  def find_for(request)
@@ -16,11 +16,11 @@ module HttpStub
16
16
  end
17
17
 
18
18
  def remember
19
- @remembered_registry = @registry.copy
19
+ @remembered_stub = @registry.last
20
20
  end
21
21
 
22
22
  def recall
23
- @registry = @remembered_registry.copy if @remembered_registry
23
+ @registry.rollback_to(@remembered_stub) if @remembered_stub
24
24
  end
25
25
 
26
26
  end
@@ -0,0 +1,62 @@
1
+ module HttpStub
2
+ module Server
3
+ module StubResponse
4
+
5
+ class Base
6
+
7
+ private
8
+
9
+ DEFAULT_ARGS = { "status" => 200, "delay_in_seconds" => 0 }.freeze
10
+
11
+ public
12
+
13
+ class << self
14
+
15
+ def add_default_headers(headers)
16
+ default_headers.merge!(headers)
17
+ end
18
+
19
+ def merge_defaults(args)
20
+ args.clone.tap do |result|
21
+ headers = result["headers"] ||= {}
22
+ DEFAULT_ARGS.each { |key, value| result[key] = value if !result[key] || result[key] == "" }
23
+ default_headers.each { |key, value| headers[key] = value if !headers[key] || headers[key] == "" }
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def default_headers
30
+ @default_headers ||= {}
31
+ end
32
+
33
+ end
34
+
35
+ attr_reader :status, :body, :delay_in_seconds, :headers
36
+
37
+ def initialize(args={})
38
+ @original_args = args
39
+ resolved_args = self.class.merge_defaults(args)
40
+ @status = resolved_args["status"]
41
+ @body = resolved_args["body"]
42
+ @delay_in_seconds = resolved_args["delay_in_seconds"]
43
+ @headers = HttpStub::Server::Headers.new(resolved_args["headers"])
44
+ end
45
+
46
+ def empty?
47
+ @original_args.empty?
48
+ end
49
+
50
+ def clear
51
+ # Intentionally blank
52
+ end
53
+
54
+ def to_s
55
+ @original_args.to_s
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,48 @@
1
+ module HttpStub
2
+ module Server
3
+ module StubResponse
4
+
5
+ class File < HttpStub::Server::StubResponse::Base
6
+
7
+ private
8
+
9
+ STORAGE_DIR = "#{HttpStub::BASE_DIR}/tmp/response_files".freeze
10
+
11
+ public
12
+
13
+ add_default_headers "content-type" => "application/octet-stream"
14
+
15
+ def initialize(args)
16
+ @file_path = store_file(args["body"])
17
+ super(args.merge("body" => @file_path))
18
+ end
19
+
20
+ def serve_on(server)
21
+ server.send_file(@file_path, send_options)
22
+ end
23
+
24
+ def clear
25
+ FileUtils.rm_f(@file_path)
26
+ end
27
+
28
+ private
29
+
30
+ def store_file(upload)
31
+ FileUtils.mkdir_p(STORAGE_DIR)
32
+ "#{STORAGE_DIR}/#{upload[:filename]}".tap do |file_path|
33
+ ::File.open(file_path, "w") { |file| file.write(upload[:tempfile].read) }
34
+ end
35
+ end
36
+
37
+ def send_options
38
+ { status: @status, type: @headers["content-type"] }.tap do |options|
39
+ options[:last_modified] = @headers["last-modified"] if @headers["last-modified"]
40
+ options[:disposition] = @headers["content-disposition"] if @headers["content-disposition"]
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,17 @@
1
+ module HttpStub
2
+ module Server
3
+ module StubResponse
4
+
5
+ class Text < HttpStub::Server::StubResponse::Base
6
+
7
+ add_default_headers "content-type" => "application/json"
8
+
9
+ def serve_on(server)
10
+ server.halt(@status, @headers.to_hash, @body)
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ module HttpStub
2
+ module Server
3
+
4
+ module StubResponse
5
+
6
+ def self.create(args)
7
+ args["body"].is_a?(Hash) ?
8
+ HttpStub::Server::StubResponse::File.new(args) : HttpStub::Server::StubResponse::Text.new(args)
9
+ end
10
+
11
+ end
12
+
13
+ end
14
+ end
@@ -1,18 +1,22 @@
1
1
  module HttpStub
2
- module Models
2
+ module Server
3
3
 
4
4
  class StubTriggers
5
5
 
6
6
  delegate :each, to: :@triggers
7
7
 
8
8
  def initialize(triggers)
9
- @triggers = (triggers || []).map { |trigger| HttpStub::Models::Stub.new(trigger) }
9
+ @triggers = (triggers || []).map { |trigger| HttpStub::Server::Stub.new(trigger) }
10
10
  end
11
11
 
12
12
  def add_to(registry, request)
13
13
  @triggers.each { |trigger| registry.add(trigger, request) }
14
14
  end
15
15
 
16
+ def clear
17
+ @triggers.each(&:clear)
18
+ end
19
+
16
20
  def to_s
17
21
  @triggers.reduce("") { |result, trigger| "#{result}\n#{trigger}" }
18
22
  end
@@ -1,10 +1,10 @@
1
1
  module HttpStub
2
- module Models
2
+ module Server
3
3
 
4
4
  class StubUri
5
5
 
6
6
  def initialize(uri)
7
- @uri = HttpStub::Models::StringValueMatcher.new(uri)
7
+ @uri = HttpStub::Server::StringValueMatcher.new(uri)
8
8
  end
9
9
 
10
10
  def match?(request)
File without changes
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  module HttpStub
2
- VERSION = "0.14.2".freeze
2
+ VERSION = "0.15.0".freeze
3
3
  end
data/lib/http_stub.rb CHANGED
@@ -3,6 +3,7 @@ require 'sinatra/partial'
3
3
  require 'haml'
4
4
  require 'sass'
5
5
  require 'net/http'
6
+ require 'net/http/post/multipart'
6
7
  require 'json'
7
8
  require 'http_server_manager'
8
9
 
@@ -11,36 +12,52 @@ require 'active_support/core_ext/module/delegation'
11
12
  require 'active_support/core_ext/hash/slice'
12
13
  require 'active_support/core_ext/hash/deep_merge'
13
14
 
15
+ module HttpStub
16
+
17
+ BASE_DIR = ::File.expand_path("../..", __FILE__)
18
+
19
+ end
20
+
21
+ require_relative 'http_stub/extensions/core/hash'
14
22
  require_relative 'http_stub/extensions/rack/handler'
15
- require_relative 'http_stub/hash_extensions'
16
- require_relative 'http_stub/models/headers'
17
- require_relative 'http_stub/models/response'
18
- require_relative 'http_stub/models/omitted_value_matcher'
19
- require_relative 'http_stub/models/regexp_value_matcher'
20
- require_relative 'http_stub/models/exact_value_matcher'
21
- require_relative 'http_stub/models/string_value_matcher'
22
- require_relative 'http_stub/models/hash_with_string_value_matchers'
23
- require_relative 'http_stub/models/request_header_parser'
24
- require_relative 'http_stub/models/stub_uri'
25
- require_relative 'http_stub/models/stub_headers'
26
- require_relative 'http_stub/models/stub_parameters'
27
- require_relative 'http_stub/models/stub_triggers'
28
- require_relative 'http_stub/models/stub'
29
- require_relative 'http_stub/models/stub_activator'
30
- require_relative 'http_stub/models/registry'
31
- require_relative 'http_stub/models/stub_registry'
32
- require_relative 'http_stub/models/request_pipeline'
33
- require_relative 'http_stub/controllers/stub_controller'
34
- require_relative 'http_stub/controllers/stub_activator_controller'
35
- require_relative 'http_stub/server'
36
- require_relative 'http_stub/server_daemon'
23
+ require_relative 'http_stub/server/headers'
24
+ require_relative 'http_stub/server/omitted_value_matcher'
25
+ require_relative 'http_stub/server/regexp_value_matcher'
26
+ require_relative 'http_stub/server/exact_value_matcher'
27
+ require_relative 'http_stub/server/string_value_matcher'
28
+ require_relative 'http_stub/server/hash_with_string_value_matchers'
29
+ require_relative 'http_stub/server/request_header_parser'
30
+ require_relative 'http_stub/server/stub_uri'
31
+ require_relative 'http_stub/server/stub_headers'
32
+ require_relative 'http_stub/server/stub_parameters'
33
+ require_relative 'http_stub/server/stub_response/base'
34
+ require_relative 'http_stub/server/stub_response/text'
35
+ require_relative 'http_stub/server/stub_response/file'
36
+ require_relative 'http_stub/server/stub_response'
37
+ require_relative 'http_stub/server/response'
38
+ require_relative 'http_stub/server/stub_triggers'
39
+ require_relative 'http_stub/server/stub'
40
+ require_relative 'http_stub/server/stub_factory'
41
+ require_relative 'http_stub/server/stub_activator'
42
+ require_relative 'http_stub/server/registry'
43
+ require_relative 'http_stub/server/stub_registry'
44
+ require_relative 'http_stub/server/response_pipeline'
45
+ require_relative 'http_stub/server/stub_controller'
46
+ require_relative 'http_stub/server/stub_activator_controller'
47
+ require_relative 'http_stub/server/application'
48
+ require_relative 'http_stub/server/daemon'
49
+ require_relative 'http_stub/configurer/request/http/basic'
50
+ require_relative 'http_stub/configurer/request/http/multipart'
51
+ require_relative 'http_stub/configurer/request/http/factory'
37
52
  require_relative 'http_stub/configurer/request/omittable'
38
53
  require_relative 'http_stub/configurer/request/regexpable'
39
54
  require_relative 'http_stub/configurer/request/controllable_value'
55
+ require_relative 'http_stub/configurer/request/stub_response_file'
56
+ require_relative 'http_stub/configurer/request/stub_response'
40
57
  require_relative 'http_stub/configurer/request/stub'
41
- require_relative 'http_stub/configurer/request/stub_payload_builder'
58
+ require_relative 'http_stub/configurer/request/stub_builder'
42
59
  require_relative 'http_stub/configurer/request/stub_activator'
43
- require_relative 'http_stub/configurer/request/stub_activator_payload_builder'
60
+ require_relative 'http_stub/configurer/request/stub_activator_builder'
44
61
  require_relative 'http_stub/configurer/server/command'
45
62
  require_relative 'http_stub/configurer/server/command_processor'
46
63
  require_relative 'http_stub/configurer/server/buffered_command_processor'
@@ -142,7 +142,7 @@ describe HttpStub::Configurer::DeprecatedDSL do
142
142
 
143
143
  include_context "a method stubbing a response"
144
144
 
145
- let(:builder) { instance_double(HttpStub::Configurer::Request::StubPayloadBuilder) }
145
+ let(:builder) { instance_double(HttpStub::Configurer::Request::StubBuilder) }
146
146
 
147
147
  subject { dsl_object.send(method, stub_uri, options) }
148
148
 
@@ -164,7 +164,7 @@ describe HttpStub::Configurer::DeprecatedDSL do
164
164
 
165
165
  include_context "a method stubbing a response"
166
166
 
167
- let(:builder) { instance_double(HttpStub::Configurer::Request::StubActivatorPayloadBuilder) }
167
+ let(:builder) { instance_double(HttpStub::Configurer::Request::StubActivatorBuilder) }
168
168
 
169
169
  subject { dsl_object.stub_activator(activation_uri, stub_uri, options) }
170
170
 
@@ -0,0 +1,15 @@
1
+ describe HttpStub::Configurer::Request::Http::Basic do
2
+
3
+ let(:http_request) { instance_double(Net::HTTPRequest) }
4
+
5
+ let(:basic_request) { HttpStub::Configurer::Request::Http::Basic.new(http_request) }
6
+
7
+ describe "#to_http_request" do
8
+
9
+ it "returns the provided HTTP request" do
10
+ expect(basic_request.to_http_request).to eql(http_request)
11
+ end
12
+
13
+ end
14
+
15
+ end