Sha256: 5a0ed0c0d1b7e27efc9959119b838df52ca0e970747be14917bbde2db21c5794

Contents?: true

Size: 953 Bytes

Versions: 14

Compression:

Stored size: 953 Bytes

Contents

require 'ostruct'

module ExconSpecHelper

  def http_request(method, uri, options = {}, &block)
    Excon.defaults[:ssl_verify_peer] = false
    uri      = Addressable::URI.heuristic_parse(uri)
    uri      = uri.omit(:userinfo).to_s.gsub(' ', '%20')

    options  = options.merge(:method => method, :nonblock => false) # Dup and merge
    response = Excon.new(uri).request(options, &block)

    headers  = WebMock::Util::Headers.normalize_headers(response.headers)
    headers  = headers.inject({}) do |res, (name, value)|
      res[name] = value.is_a?(Array) ? value.flatten.join(', ') : value
      res
    end

    OpenStruct.new \
      :body => response.body,
      :headers => headers,
      :status  => response.status.to_s,
      :message => ""
  end

  def client_timeout_exception_class
    Excon::Errors::Timeout
  end

  def connection_refused_exception_class
    Excon::Errors::SocketError
  end

  def http_library
    :excon
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
webmock-1.16.1 spec/acceptance/excon/excon_spec_helper.rb
webmock-1.16.0 spec/acceptance/excon/excon_spec_helper.rb
webmock-1.15.2 spec/acceptance/excon/excon_spec_helper.rb
webmock-1.15.0 spec/acceptance/excon/excon_spec_helper.rb
webmock-1.14.0 spec/acceptance/excon/excon_spec_helper.rb
webmock-1.13.0 spec/acceptance/excon/excon_spec_helper.rb
webmock-1.12.3 spec/acceptance/excon/excon_spec_helper.rb
webmock-1.12.2 spec/acceptance/excon/excon_spec_helper.rb
webmock-1.12.1 spec/acceptance/excon/excon_spec_helper.rb
webmock-1.12.0 spec/acceptance/excon/excon_spec_helper.rb
webmock-1.11.0 spec/acceptance/excon/excon_spec_helper.rb
webmock-1.10.2 spec/acceptance/excon/excon_spec_helper.rb
webmock-1.10.1 spec/acceptance/excon/excon_spec_helper.rb
webmock-1.10.0 spec/acceptance/excon/excon_spec_helper.rb