Sha256: cf6fe1400fa17ee9f17b85d5024f51d11605191bbde207cef99a0cf2619e7d81

Contents?: true

Size: 931 Bytes

Versions: 9

Compression:

Stored size: 931 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(' ', '+')

    options  = options.merge(:method => method) # 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

9 entries across 9 versions & 2 rubygems

Version Path
simple-client-0.0.3 vendor/bundle/ruby/1.9.1/gems/webmock-1.8.8/spec/acceptance/excon/excon_spec_helper.rb
webmock-1.8.10 spec/acceptance/excon/excon_spec_helper.rb
webmock-1.8.9 spec/acceptance/excon/excon_spec_helper.rb
simple-client-0.0.2 vendor/bundle/ruby/1.8/gems/webmock-1.8.8/spec/acceptance/excon/excon_spec_helper.rb
webmock-1.8.8 spec/acceptance/excon/excon_spec_helper.rb
webmock-1.8.7 spec/acceptance/excon/excon_spec_helper.rb
webmock-1.8.6 spec/acceptance/excon/excon_spec_helper.rb
webmock-1.8.5 spec/acceptance/excon/excon_spec_helper.rb
webmock-1.8.4 spec/acceptance/excon/excon_spec_helper.rb