module RSpec::HttpHelpers

RSpec matchers for HTTP requests and responses

Public Class Methods

normalize_querystring(query) click to toggle source

@api private

# File lib/rspec/http_helpers.rb, line 29
def normalize_querystring(query)
  return '' if query.nil?

  parts = query.split('&')
  parts = parts.sort_by do |param|
    name, actual_value = param.split('&')
    value = actual_value.nil? ? '' : actual_value
    [name, value, actual_value ? 1 : 0]
  end
  parts.join('&')
end

Public Instance Methods

match_http_querystring(expected) click to toggle source

Expects a HTTP URI or URI fragment to match the provided querystring.

expect('https://foo.com?abc=xyz').to match_http_querystring('abc=xyz')

The actual and expected values can be formatted a number of ways:

expect('abc=xyz').to match_http_querystring('abc=xyz')
expect('?abc=xyz').to match_http_querystring('abc=xyz')
expect(URI.parse('...')).to match_http_querystring('abc=xyz')

@param [String<HTTP Query>] expected @raise [ArgumentError] Raises an ArgumentError if expected is

not nil or a String.
# File lib/rspec/http_helpers.rb, line 22
def match_http_querystring(expected)
  HttpQuerystringMatcher.new(expected)
end