class Faraday::Adapter::Test::Stubs
A stack of Stubs
Public Class Methods
Source
# File lib/faraday/adapter/test.rb, line 50 def initialize # { get: [Stub, Stub] } @stack = {} @consumed = {} yield(self) if block_given? end
Public Instance Methods
Source
# File lib/faraday/adapter/test.rb, line 95 def delete(path, headers = {}, &block) new_stub(:delete, path, headers, &block) end
Source
# File lib/faraday/adapter/test.rb, line 75 def get(path, headers = {}, &block) new_stub(:get, path, headers, &block) end
Source
# File lib/faraday/adapter/test.rb, line 79 def head(path, headers = {}, &block) new_stub(:head, path, headers, &block) end
Source
# File lib/faraday/adapter/test.rb, line 61 def match(request_method, host, path, headers, body) return false unless @stack.key?(request_method) stack = @stack[request_method] consumed = (@consumed[request_method] ||= []) stub, meta = matches?(stack, host, path, headers, body) if stub consumed << stack.delete(stub) return stub, meta end matches?(consumed, host, path, headers, body) end
Source
# File lib/faraday/adapter/test.rb, line 99 def options(path, headers = {}, &block) new_stub(:options, path, headers, &block) end
Source
# File lib/faraday/adapter/test.rb, line 91 def patch(path, body = nil, headers = {}, &block) new_stub(:patch, path, headers, body, &block) end
Source
# File lib/faraday/adapter/test.rb, line 83 def post(path, body = nil, headers = {}, &block) new_stub(:post, path, headers, body, &block) end
Source
# File lib/faraday/adapter/test.rb, line 87 def put(path, body = nil, headers = {}, &block) new_stub(:put, path, headers, body, &block) end
Source
# File lib/faraday/adapter/test.rb, line 104 def verify_stubbed_calls failed_stubs = [] @stack.each do |method, stubs| next if stubs.empty? failed_stubs.concat( stubs.map do |stub| "Expected #{method} #{stub}." end ) end raise failed_stubs.join(' ') unless failed_stubs.empty? end
Raises an error if any of the stubbed calls have not been made.
Protected Instance Methods
Source
# File lib/faraday/adapter/test.rb, line 135 def matches?(stack, host, path, headers, body) stack.each do |stub| match_result, meta = stub.matches?(host, path, headers, body) return stub, meta if match_result end nil end
Source
# File lib/faraday/adapter/test.rb, line 120 def new_stub(request_method, path, headers = {}, body = nil, &block) normalized_path, host = if path.is_a?(Regexp) path else [ Faraday::Utils.normalize_path(path), Faraday::Utils.URI(path).host ] end stub = Stub.new(host, normalized_path, headers, body, block) (@stack[request_method] ||= []) << stub end