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 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
#lookup_middleware, #register_middleware, #registered_middleware, #unregister_middleware
Methods included from Parallelism
#inherited, #supports_parallel?
Constructor Details
Instance Attribute Details
#stubs ⇒ Object
Returns the value of attribute stubs.
63 64 65 |
# File 'lib/faraday/adapter/test.rb', line 63 def stubs @stubs end |
Instance Method Details
#call(env) ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/faraday/adapter/test.rb', line 269 def call(env) super env.request.params_encoder ||= Faraday::Utils.default_params_encoder env[:params] = env.params_encoder.decode(env[:url].query) || {} stub, = stubs.match(env) unless stub raise Stubs::NotFound, "no stubbed request for #{env[:method]} " \ "#{env[:url]} #{env[:body]} #{env[:headers]}" end block_arity = stub.block.arity params = if block_arity >= 0 [env, ].take(block_arity) else [env, ] end timeout = request_timeout(:open, env[:request]) timeout ||= request_timeout(:read, env[:request]) status, headers, body = if timeout ::Timeout.timeout(timeout, Faraday::TimeoutError) do stub.block.call(*params) end else stub.block.call(*params) end # We need to explicitly pass `reason_phrase = nil` here to avoid keyword args conflicts. # See https://github.com/lostisland/faraday/issues/1444 # TODO: remove `nil` explicit reason_phrase once Ruby 3.0 becomes minimum req. version save_response(env, status, body, headers, nil) @app.call(env) end |
#configure {|stubs| ... } ⇒ Object
264 265 266 |
# File 'lib/faraday/adapter/test.rb', line 264 def configure yield(stubs) end |