Class: Faraday::Adapter::Test

### Home Classes Methods

### In Files

- lib/faraday/adapter/test.rb

### Parent

Faraday::Adapter

### Namespace

- CLASS Faraday::Adapter::Test::Stub
- CLASS Faraday::Adapter::Test::Stubs

### Methods

- ::new
- #call
- #configure

### Class/Module Index

Quicksearch

- Faraday
- Faraday::Adapter
- Faraday::Adapter::EMHttp
- Faraday::Adapter::EMHttp::Manager
- Faraday::Adapter::EMHttp::Options
- Faraday::Adapter::EMSynchrony
- Faraday::Adapter::EMSynchrony::ParallelManager
- Faraday::Adapter::Excon
- Faraday::Adapter::HTTPClient
- Faraday::Adapter::NetHttp
- Faraday::Adapter::NetHttpPersistent
- Faraday::Adapter::Parallelism
- Faraday::Adapter::Patron
- Faraday::Adapter::Rack
- Faraday::Adapter::Test
- Faraday::Adapter::Test::Stub
- Faraday::Adapter::Test::Stubs
- Faraday::Adapter::Test::Stubs::NotFound
- Faraday::Adapter::Typhoeus
- Faraday::AutoloadHelper
- Faraday::ClientError
- Faraday::CompositeReadIO
- Faraday::Connection
- Faraday::ConnectionFailed
- Faraday::ConnectionOptions
- Faraday::Env
- Faraday::Error
- Faraday::FlatParamsEncoder
- Faraday::Middleware
- Faraday::MiddlewareRegistry
- Faraday::MissingDependency
- Faraday::NestedParamsEncoder
- Faraday::Options
- Faraday::ParsingError
- Faraday::ProxyOptions
- Faraday::RackBuilder
- Faraday::RackBuilder::Handler
- Faraday::RackBuilder::StackLocked
- Faraday::Request
- Faraday::Request::Authorization
- Faraday::Request::BasicAuthentication
- Faraday::Request::Instrumentation
- Faraday::Request::Instrumentation::Options
- Faraday::Request::Multipart
- Faraday::Request::Retry
- Faraday::Request::Retry::Options
- Faraday::Request::TokenAuthentication
- Faraday::Request::UrlEncoded
- Faraday::RequestOptions
- Faraday::ResourceNotFound
- Faraday::Response
- Faraday::Response::Logger
- Faraday::Response::Middleware
- Faraday::Response::RaiseError
- Faraday::SSLError
- Faraday::SSLOptions
- Faraday::TimeoutError
- Faraday::Utils
- Faraday::Utils::Headers
- Faraday::Utils::ParamsHash
- EmHttpSslPatch
- Object

No matching classes.

# Faraday::Adapter::Test

test = Faraday::Connection.new do

    use Faraday::Adapter::Test do |stub|
      stub.get '/nigiri/sake.json' do
        [200, {}, 'hi world']
      end
    end

end

resp = test.get '/nigiri/sake.json' resp.body # => 'hi world'

### Attributes

stubs[RW]

### Public Class Methods

new(app, stubs=nil, &block) click to toggle source

    # File lib/faraday/adapter/test.rb, line 134
    def initialize(app, stubs=nil, &block)
      super(app)
      @stubs = stubs || Stubs.new
      configure(&block) if block
    end

### Public Instance Methods

call(env) click to toggle source

    # File lib/faraday/adapter/test.rb, line 144
    def call(env)
      super
      normalized_path = Faraday::Utils.normalize_path(env[:url])
      params_encoder = env.request.params_encoder || Faraday::Utils.default_params_encoder

      if stub = stubs.match(env[:method], normalized_path, env.request_headers, env[:body])
        env[:params] = (query = env[:url].query) ?
          params_encoder.decode(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() click to toggle source

    # File lib/faraday/adapter/test.rb, line 140
    def configure
      yield(stubs)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.