Parent

Typhoeus::HydraMock

Attributes

method[R]
requests[R]
uri[R]
url[R]

Public Class Methods

new(url, method, options = {}) click to toggle source
# File lib/typhoeus/hydra_mock.rb, line 5
def initialize(url, method, options = {})
  @url      = url
  @uri      = URI.parse(url) if url.kind_of?(String)
  @method   = method
  @requests = []
  @options = options
  if @options[:headers]
    @options[:headers] = Typhoeus::NormalizedHeaderHash.new(@options[:headers])
  end

  @current_response_index = 0
end

Public Instance Methods

add_request(request) click to toggle source
# File lib/typhoeus/hydra_mock.rb, line 34
def add_request(request)
  @requests << request
end
and_return(val) click to toggle source
# File lib/typhoeus/hydra_mock.rb, line 38
def and_return(val)
  if val.respond_to?(:each)
    @responses = val
  else
    @responses = [val]
  end

  # make sure to mark them as a mock.
  @responses.each { |r| r.mock = true }

  val
end
body() click to toggle source
# File lib/typhoeus/hydra_mock.rb, line 18
def body
  @options[:body]
end
body?() click to toggle source
# File lib/typhoeus/hydra_mock.rb, line 22
def body?
  @options.has_key?(:body)
end
headers() click to toggle source
# File lib/typhoeus/hydra_mock.rb, line 26
def headers
  @options[:headers]
end
headers?() click to toggle source
# File lib/typhoeus/hydra_mock.rb, line 30
def headers?
  @options.has_key?(:headers)
end
matches?(request) click to toggle source
# File lib/typhoeus/hydra_mock.rb, line 61
def matches?(request)
  if !method_matches?(request) or !url_matches?(request)
    return false
  end

  if body?
    return false unless body_matches?(request)
  end

  if headers?
    return false unless headers_match?(request)
  end

  true
end
response() click to toggle source
# File lib/typhoeus/hydra_mock.rb, line 51
def response
  if @current_response_index == (@responses.length - 1)
    @responses.last
  else
    value = @responses[@current_response_index]
    @current_response_index += 1
    value
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.