class MnoeFaradayTestAdapter::Stubs

Public Class Methods

new() { |self| ... } click to toggle source
# File lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb, line 23
def initialize
  # {:get => [Stub, Stub]}
  @stack, @consumed = {}, {}
  yield(self) if block_given?
end

Public Instance Methods

delete(path, headers = {}, &block) click to toggle source
# File lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb, line 66
def delete(path, headers = {}, &block)
  new_stub(:delete, path, headers, &block)
end
empty?() click to toggle source
# File lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb, line 29
def empty?
  @stack.empty?
end
get(path, headers = {}, &block) click to toggle source
# File lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb, line 46
def get(path, headers = {}, &block)
  new_stub(:get, path, headers, &block)
end
head(path, headers = {}, &block) click to toggle source
# File lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb, line 50
def head(path, headers = {}, &block)
  new_stub(:head, path, headers, &block)
end
match(request_method, path, headers, body) click to toggle source
# File lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb, line 33
def match(request_method, path, headers, body)
  return false if !@stack.key?(request_method)
  stack = @stack[request_method]
  consumed = (@consumed[request_method] ||= [])

  if stub = matches?(stack, path, headers, body)
    consumed << stack.delete(stub)
    stub
  else
    matches?(consumed, path, headers, body)
  end
end
options(path, headers = {}, &block) click to toggle source
# File lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb, line 70
def options(path, headers = {}, &block)
  new_stub(:options, path, headers, &block)
end
patch(path, body=nil, headers = {}, &block) click to toggle source
# File lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb, line 62
def patch(path, body=nil, headers = {}, &block)
  new_stub(:patch, path, headers, body, &block)
end
post(path, body=nil, headers = {}, &block) click to toggle source
# File lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb, line 54
def post(path, body=nil, headers = {}, &block)
  new_stub(:post, path, headers, body, &block)
end
put(path, body=nil, headers = {}, &block) click to toggle source
# File lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb, line 58
def put(path, body=nil, headers = {}, &block)
  new_stub(:put, path, headers, 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/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb, line 75
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, headers, body) click to toggle source
# File lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb, line 94
def matches?(stack, path, headers, body)
  stack.detect { |stub| stub.matches?(path, headers, body) }
end
new_stub(request_method, path, headers = {}, body=nil, &block) click to toggle source
# File lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb, line 89
def new_stub(request_method, path, headers = {}, body=nil, &block)
  normalized_path = Faraday::Utils.normalize_path(path)
  (@stack[request_method] ||= []) << Stub.new(normalized_path, headers, body, block)
end