class RSpecApib::Element::HttpRequest

Represents a http request in api-elements (api-elements.readthedocs.io/en/latest/)

Public Class Methods

attributes_schema() click to toggle source
# File lib/rspec_apib/elements/http_request.rb, line 35
def self.attributes_schema
  {
    href: "TemplatedHref"
  }
end
attrs_to_inherit() click to toggle source

Inherit href and hrefVariables from any ancestor

# File lib/rspec_apib/elements/http_request.rb, line 19
def self.attrs_to_inherit
  [:href, :hrefVariables, :method]
end

Public Instance Methods

matches?(request, options: {}) click to toggle source

Indicates if the incoming request matches the method, path and path vars @param [::RSpecApib::Request] The incoming request - normalized @return [Boolean] true if matches else false

# File lib/rspec_apib/elements/http_request.rb, line 12
def matches?(request, options: {})
  matches_method?(request) &&
    matches_path?(request) &&
    matches_headers?(request, options)
end
path() click to toggle source
# File lib/rspec_apib/elements/http_request.rb, line 27
def path
  attributes && attributes["href"] && attributes["href"].path
end
request_method() click to toggle source
# File lib/rspec_apib/elements/http_request.rb, line 23
def request_method
  attributes && attributes["method"] && attributes["method"].downcase.to_sym
end
url() click to toggle source
# File lib/rspec_apib/elements/http_request.rb, line 31
def url
  attributes && attributes["href"].to_s
end

Private Instance Methods

compared_headers() click to toggle source
# File lib/rspec_apib/elements/http_request.rb, line 52
def compared_headers
  attributes && attributes["headers"] && attributes["headers"].keep_if {|k, _v| k == "Content-Type" || k == "Accept"}
end
matches_headers?(request_or_response, _options) click to toggle source
# File lib/rspec_apib/elements/http_request.rb, line 43
def matches_headers?(request_or_response, _options)
  headers = compared_headers
  return true if headers.nil?
  headers.each_pair do |header_key, header_value|
    return false unless request_or_response.headers.key?(header_key) &&
                        request_or_response.headers[header_key] == header_value
  end
end
matches_method?(request) click to toggle source
# File lib/rspec_apib/elements/http_request.rb, line 56
def matches_method?(request)
  attributes && attributes["method"] && attributes["method"].downcase.to_sym == request.request_method
end
matches_path?(request) click to toggle source
# File lib/rspec_apib/elements/http_request.rb, line 60
def matches_path?(request)
  attributes && attributes["href"] && attributes["href"].matches_path?(request)
end