Class: Faraday::Adapter::Test::Stubs

### Home Classes Methods

### In Files

- lib/faraday/adapter/test.rb

### Parent

Object

### Namespace

- CLASS Faraday::Adapter::Test::Stubs::NotFound

### Methods

- ::new
- #delete
- #empty?
- #get
- #head
- #match
- #matches?
- #new_stub
- #normalize_path
- #options
- #patch
- #post
- #put
- #verify_stubbed_calls

### 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::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::Builder
- Faraday::Builder::Handler
- Faraday::Builder::StackLocked
- Faraday::CompositeReadIO
- Faraday::Connection
- Faraday::Error
- Faraday::Error::ClientError
- Faraday::Error::ConnectionFailed
- Faraday::Error::MissingDependency
- Faraday::Error::ParsingError
- Faraday::Error::ResourceNotFound
- Faraday::Error::TimeoutError
- Faraday::Middleware
- Faraday::MiddlewareRegistry
- Faraday::Request
- Faraday::Request::Authorization
- Faraday::Request::BasicAuthentication
- Faraday::Request::Multipart
- Faraday::Request::Retry
- Faraday::Request::TokenAuthentication
- Faraday::Request::UrlEncoded
- Faraday::Response
- Faraday::Response::Logger
- Faraday::Response::Middleware
- Faraday::Response::RaiseError
- Faraday::Utils
- Faraday::Utils::Headers
- Faraday::Utils::ParamsHash
- Object

No matching classes.

# Faraday::Adapter::Test::Stubs

### Public Class Methods

new() click to toggle source

    # File lib/faraday/adapter/test.rb, line 21
    def initialize
      # {:get => [Stub, Stub]}
      @stack, @consumed = {}, {}
      yield self if block_given?
    end

### Public Instance Methods

delete(path, &block) click to toggle source

    # File lib/faraday/adapter/test.rb, line 65
    def delete(path, &block)
      new_stub(:delete, path, &block)
    end

empty?() click to toggle source

    # File lib/faraday/adapter/test.rb, line 27
    def empty?
      @stack.empty?
    end

get(path, &block) click to toggle source

    # File lib/faraday/adapter/test.rb, line 45
    def get(path, &block)
      new_stub(:get, path, &block)
    end

head(path, &block) click to toggle source

    # File lib/faraday/adapter/test.rb, line 49
    def head(path, &block)
      new_stub(:head, path, &block)
    end

match(request_method, path, body) click to toggle source

    # File lib/faraday/adapter/test.rb, line 31
    def match(request_method, path, body)
      return false if !@stack.key?(request_method)
      stack = @stack[request_method]
      consumed = (@consumed[request_method] ||= [])
      path = normalize_path(path)

      if stub = matches?(stack, path, body)
        consumed << stack.delete(stub)
        stub
      else
        matches?(consumed, path, body)
      end
    end

options(path, &block) click to toggle source

    # File lib/faraday/adapter/test.rb, line 69
    def options(path, &block)
      new_stub(:options, path, &block)
    end

patch(path, body=nil, &block) click to toggle source

    # File lib/faraday/adapter/test.rb, line 61
    def patch(path, body=nil, &block)
      new_stub(:patch, path, body, &block)
    end

post(path, body=nil, &block) click to toggle source

    # File lib/faraday/adapter/test.rb, line 53
    def post(path, body=nil, &block)
      new_stub(:post, path, body, &block)
    end

put(path, body=nil, &block) click to toggle source

    # File lib/faraday/adapter/test.rb, line 57
    def put(path, body=nil, &block)
      new_stub(:put, path, body, &block)
    end

verify_stubbed_calls() click to toggle source

Raises an error if any of the stubbed calls have not been made.

    # File lib/faraday/adapter/test.rb, line 74
    def verify_stubbed_calls
      failed_stubs = []
      @stack.each do |method, stubs|
        unless stubs.size == 0
          failed_stubs.concat(stubs.map {|stub|
            "Expected #{method} #{stub}."
          })
        end
      end
      raise failed_stubs.join(" ") unless failed_stubs.size == 0
    end

### Protected Instance Methods

matches?(stack, path, body) click to toggle source

    # File lib/faraday/adapter/test.rb, line 92
    def matches?(stack, path, body)
      stack.detect { |stub| stub.matches?(path, body) }
    end

new_stub(request_method, path, body=nil, &block) click to toggle source

    # File lib/faraday/adapter/test.rb, line 88
    def new_stub(request_method, path, body=nil, &block)
      (@stack[request_method] ||= []) << Stub.new(normalize_path(path), body, block)
    end

normalize_path(path) click to toggle source

ensure leading + trailing slash

    # File lib/faraday/adapter/test.rb, line 97
    def normalize_path(path)
      path = '/' + path if path.index('/') != 0
      path = path.sub('?', '/?')
      path = path + '/' unless $&
      path.gsub('//', '/')
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.