class Object

Constants

RSPEC_CONFIGURER
RSPEC_NAMESPACE

Public Class Methods

new(args) click to toggle source
Calls superclass method
# File lib/webmock/http_lib_adapters/excon_adapter.rb, line 148
def self.new(args)
  super.tap do |instance|
    instance.data[:__construction_args] = args
  end
end

Public Instance Methods

build_request_signature(req, reuse_existing = false) click to toggle source
# File lib/webmock/http_lib_adapters/httpclient_adapter.rb, line 133
def build_request_signature(req, reuse_existing = false)
  uri = WebMock::Util::URI.heuristic_parse(req.header.request_uri.to_s)
  uri.query = WebMock::Util::QueryMapper.values_to_query(req.header.request_query) if req.header.request_query
  uri.port = req.header.request_uri.port
  uri = uri.omit(:userinfo)

  auth = www_auth.basic_auth
  auth.challenge(req.header.request_uri, nil)

  @request_filter.each do |filter|
    filter.filter_request(req)
  end

  headers = req.header.all.inject({}) do |hdrs, header|
    hdrs[header[0]] ||= []
    hdrs[header[0]] << header[1]
    hdrs
  end
  headers = headers_from_session(uri).merge(headers)

  if (auth_cred = auth.get(req)) && auth.scheme == 'Basic'
    userinfo = WebMock::Util::Headers.decode_userinfo_from_header(auth_cred)
    userinfo = WebMock::Util::URI.encode_unsafe_chars_in_userinfo(userinfo)
    headers.reject! {|k,v| k =~ /[Aa]uthorization/ && v =~ /^Basic / } #we added it to url userinfo
    uri.userinfo = userinfo
  end

  signature = WebMock::RequestSignature.new(
    req.header.request_method.downcase.to_sym,
    uri.to_s,
    :body => req.http_body.dump,
    :headers => headers
  )

  # reuse a previous identical signature object if we stored one for later use
  if reuse_existing && previous_signature = previous_signature_for(signature)
    return previous_signature
  end

  signature
end
build_webmock_response(httpclient_response) click to toggle source
# File lib/webmock/http_lib_adapters/httpclient_adapter.rb, line 108
def build_webmock_response(httpclient_response)
  webmock_response = WebMock::Response.new
  webmock_response.status = [httpclient_response.status, httpclient_response.reason]

  webmock_response.headers = {}.tap do |hash|
    httpclient_response.header.all.each do |(key, value)|
      if hash.has_key?(key)
        hash[key] = Array(hash[key]) + [value]
      else
        hash[key] = value
      end
    end
  end

  if  httpclient_response.content.respond_to?(:read)
    webmock_response.body = httpclient_response.content.read
    body = HTTP::Message::Body.new
    body.init_response(StringIO.new(webmock_response.body))
    httpclient_response.body = body
  else
    webmock_response.body = httpclient_response.content
  end
  webmock_response
end
headers_from_session(uri) click to toggle source

some of the headers sent by HTTPClient are derived from the client session

# File lib/webmock/http_lib_adapters/httpclient_adapter.rb, line 194
def headers_from_session(uri)
  session_headers = HTTP::Message::Headers.new
  @session_manager.send(:open, uri).send(:set_header, MessageMock.new(session_headers))
  session_headers.all.inject({}) do |hdrs, header|
    hdrs[header[0]] = header[1]
    hdrs
  end
end
previous_signature_for(signature) click to toggle source
# File lib/webmock/http_lib_adapters/httpclient_adapter.rb, line 185
def previous_signature_for(signature)
  return nil unless index = webmock_request_signatures.index(signature)
  webmock_request_signatures.delete_at(index)
end
teardown_with_webmock() click to toggle source
# File lib/webmock/minitest.rb, line 17
def teardown_with_webmock
  teardown_without_webmock
  WebMock.reset!
end
webmock_request_signatures() click to toggle source
# File lib/webmock/http_lib_adapters/httpclient_adapter.rb, line 181
def webmock_request_signatures
  @webmock_request_signatures ||= []
end
webmock_responses() click to toggle source
# File lib/webmock/http_lib_adapters/httpclient_adapter.rb, line 175
def webmock_responses
  @webmock_responses ||= Hash.new do |hash, request_signature|
    hash[request_signature] = WebMock::StubRegistry.instance.response_for_request(request_signature)
  end
end