Class: Faraday::Adapter::Test
- Inherits:
-
Faraday::Adapter
- Object
- Faraday::Adapter
- Faraday::Adapter::Test
- Defined in:
- lib/faraday/adapter/test.rb
Overview
Defined Under Namespace
Constant Summary
Constants inherited from Faraday::Adapter
Instance Attribute Summary collapse
-
#stubs ⇒ Object
Returns the value of attribute stubs.
Attributes included from DependencyLoader
Attributes included from Parallelism
Instance Method Summary collapse
- #call(env) ⇒ Object
- #configure {|stubs| ... } ⇒ Object
-
#initialize(app, stubs = nil, &block) ⇒ Test
constructor
A new instance of Test.
Methods inherited from Faraday::Adapter
Methods included from MiddlewareRegistry
#fetch_middleware, #load_middleware, #lookup_middleware, #middleware_mutex, #register_middleware, #unregister_middleware
Methods included from DependencyLoader
#dependency, #inherited, #loaded?, #new
Methods included from Parallelism
#inherited, #supports_parallel?
Methods included from Faraday::AutoloadHelper
#all_loaded_constants, #autoload_all, #load_autoloaded_constants
Constructor Details
Instance Attribute Details
#stubs ⇒ Object
Returns the value of attribute stubs.
43 44 45 |
# File 'lib/faraday/adapter/test.rb', line 43 def stubs @stubs end |
Instance Method Details
#call(env) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/faraday/adapter/test.rb', line 213 def call(env) super host = env[:url].host normalized_path = Faraday::Utils.normalize_path(env[:url]) params_encoder = env.request.params_encoder || Faraday::Utils.default_params_encoder stub, = stubs.match(env[:method], host, normalized_path, env.request_headers, env[:body]) unless stub raise Stubs::NotFound, "no stubbed request for #{env[:method]} "\ "#{normalized_path} #{env[:body]}" end env[:params] = if (query = env[:url].query) params_encoder.decode(query) else {} end block_arity = stub.block.arity status, headers, body = if block_arity >= 0 stub.block.call(*[env, ].take(block_arity)) else stub.block.call(env, ) end save_response(env, status, body, headers) @app.call(env) end |
#configure {|stubs| ... } ⇒ Object
209 210 211 |
# File 'lib/faraday/adapter/test.rb', line 209 def configure yield(stubs) end |