Class: Faraday::Adapter::Test
- Inherits:
-
Faraday::Adapter
- Object
- Middleware
- 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.
Class Method Summary collapse
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 Faraday::AutoloadHelper
#all_loaded_constants, #autoload_all, #load_autoloaded_constants, #lookup_module, #register_lookup_modules
Methods inherited from Middleware
dependency, setup_parallel_manager
Constructor Details
Instance Attribute Details
#stubs ⇒ Object
Returns the value of attribute stubs.
15 16 17 |
# File 'lib/faraday/adapter/test.rb', line 15 def stubs @stubs end |
Class Method Details
.loaded? ⇒ Boolean
17 |
# File 'lib/faraday/adapter/test.rb', line 17 def self.loaded?() false end |
Instance Method Details
#call(env) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/faraday/adapter/test.rb', line 130 def call(env) super normalized_path = Faraday::Utils.normalize_path(env[:url]) if stub = stubs.match(env[:method], normalized_path, env[:body]) env[:params] = (query = env[:url].query) ? Rack::Utils.parse_nested_query(query) : {} status, headers, body = stub.block.call(env) save_response(env, status, body, headers) else raise Stubs::NotFound, "no stubbed request for #{env[:method]} #{normalized_path} #{env[:body]}" end @app.call(env) end |
#configure {|stubs| ... } ⇒ Object
126 127 128 |
# File 'lib/faraday/adapter/test.rb', line 126 def configure yield stubs end |