Class: Faraday::Adapter::MockRequest::Stubs

Inherits:
Object
  • Object
show all
Defined in:
lib/faraday/adapter/mock_request.rb

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Stubs

Returns a new instance of Stubs

Yields:

  • (_self)

Yield Parameters:


10
11
12
13
14
# File 'lib/faraday/adapter/mock_request.rb', line 10

def initialize
  # {:get => [Stub, Stub]}
  @stack = {}
  yield self if block_given?
end

Instance Method Details

#empty?Boolean


16
17
18
# File 'lib/faraday/adapter/mock_request.rb', line 16

def empty?
  @stack.empty?
end

#get(path, request_headers = {}, &block) ⇒ Object


25
26
27
# File 'lib/faraday/adapter/mock_request.rb', line 25

def get(path, request_headers = {}, &block)
  (@stack[:get] ||= []) << new_stub(path, request_headers, block)
end

#match(request_method, path, request_headers) ⇒ Object


20
21
22
23
# File 'lib/faraday/adapter/mock_request.rb', line 20

def match(request_method, path, request_headers)
  return false if !@stack.key?(request_method)
  @stack[request_method].detect { |stub| stub.matches?(path, request_headers) }
end

#new_stub(path, request_headers, block) ⇒ Object


29
30
31
32
# File 'lib/faraday/adapter/mock_request.rb', line 29

def new_stub(path, request_headers, block)
  status, response_headers, body = block.call
  Stub.new(path, request_headers, status, response_headers, body)
end