# File lib/faraday/adapter/test.rb, line 21 def initialize # {:get => [Stub, Stub]} @stack, @consumed = {}, {} yield self if block_given? end
# File lib/faraday/adapter/test.rb, line 65 def delete(path, &block) new_stub(:delete, path, &block) end
# File lib/faraday/adapter/test.rb, line 27 def empty? @stack.empty? end
# File lib/faraday/adapter/test.rb, line 45 def get(path, &block) new_stub(:get, path, &block) end
# File lib/faraday/adapter/test.rb, line 49 def head(path, &block) new_stub(:head, path, &block) end
# 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
# File lib/faraday/adapter/test.rb, line 69 def options(path, &block) new_stub(:options, path, &block) end
# File lib/faraday/adapter/test.rb, line 61 def patch(path, body=nil, &block) new_stub(:patch, path, body, &block) end
# File lib/faraday/adapter/test.rb, line 53 def post(path, body=nil, &block) new_stub(:post, path, body, &block) end
# File lib/faraday/adapter/test.rb, line 57 def put(path, body=nil, &block) new_stub(:put, path, body, &block) end
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
# File lib/faraday/adapter/test.rb, line 92 def matches?(stack, path, body) stack.detect { |stub| stub.matches?(path, body) } end
# 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
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