class Typhoeus::Expectation

responses were returned one by one.
wether they match. If thats the case, the attached
to the request url and options in order to evaluate
an url and options, like a request. They were compared
of the stubbing mechanism. An expectation contains
This class represents an expectation. It is part

def all

Returns:
  • (Array) - The expectations.

Other tags:
    Example: Return expectations. -
def all
  @expectations ||= []
end

def and_return(response)

Other tags:
    Example: Add response. -
def and_return(response)
  responses << response
end

def clear

Other tags:
    Example: Clear expectations. -
def clear
  all.clear
end

def find_by(request)

Returns:
  • (Expectation) - The matching expectation.

Other tags:
    Example: Find expectation. -
def find_by(request)
  all.find do |expectation|
    expectation.matches?(request)
  end
end

def initialize(url, options = {})

Returns:
  • (Expectation) - The created expactation.

Other tags:
    Example: Create expactation. -
def initialize(url, options = {})
  @url = url
  @options = options
  @response_counter = 0
end

def matches?(request)

Returns:
  • (Boolean) - True when matches, else false.

Parameters:
  • The (Request) -- request to check.

Other tags:
    Example: Check if request matches. -
def matches?(request)
  url_match?(request.url) &&
    (options ? options.all?{ |k,v| request.original_options[k] == v } : true)
end

def response

Returns:
  • (Response) - The response.

Other tags:
    Example: Return response. -
def response
  response = responses.fetch(@response_counter, responses.last)
  @response_counter += 1
  response
end

def responses

Returns:
  • (Array) - The responses.

Other tags:
    Example: Return responses. -
def responses
  @responses ||= []
end

def url_match?(request_url)

all urls.
Nil serves as a placeholder in case you want to match

regexp were checked, nil is always true. Else false.
The url can be a string, regex or nil. String and
Check wether the url matches the request url.
def url_match?(request_url)
  case url
  when String
    url == request_url
  when Regexp
    !!request_url.match(url)
  when nil
    true
  else
    false
  end
end