Sha256: cd5fa4704de9e867f5d39147401615630c86526b6f411555296cfd844011d248

Contents?: true

Size: 1.01 KB

Versions: 12

Compression:

Stored size: 1.01 KB

Contents

require "ostruct"

module HttpGemSpecHelper
  def http_request(method, uri, options = {})
    response = HTTP.request(method, normalize_uri(uri), options)

    OpenStruct.new({
      :body       => response.body.to_s,
      :headers    => normalize_headers(response.headers.to_h),
      :status     => response.status.to_s,
      :message    => response.reason
    })
  end

  def client_timeout_exception_class
    Errno::ETIMEDOUT
  end

  def connection_refused_exception_class
    Errno::ECONNREFUSED
  end

  def http_library
    :http_gem
  end

  def normalize_uri(uri)
    Addressable::URI.heuristic_parse(uri).normalize.to_s
  end

  def normalize_headers(headers)
    headers = Hash[headers.map { |k, v| [k, Array(v).join(", ")] }]
    WebMock::Util::Headers.normalize_headers headers
  end

  def stub_simple_request(host, status = 200, headers = {}, body = nil)
    stub_request(:any, host).to_return({
      :status   => status,
      :headers  => headers.merge({ "Host" => host }),
      :body     => body
    })
  end
end

Version data entries

12 entries across 10 versions & 3 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/webmock-1.20.4/spec/acceptance/http_gem/http_gem_spec_helper.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/webmock-1.20.4/spec/acceptance/http_gem/http_gem_spec_helper.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/webmock-1.20.4/spec/acceptance/http_gem/http_gem_spec_helper.rb
webmock-1.20.4 spec/acceptance/http_gem/http_gem_spec_helper.rb
webmock-1.20.3 spec/acceptance/http_gem/http_gem_spec_helper.rb
webmock-1.20.2 spec/acceptance/http_gem/http_gem_spec_helper.rb
webmock-1.20.1 spec/acceptance/http_gem/http_gem_spec_helper.rb
webmock-1.20.0 spec/acceptance/http_gem/http_gem_spec_helper.rb
webmock-1.19.0 spec/acceptance/http_gem/http_gem_spec_helper.rb
whos_dated_who-0.1.0 vendor/bundle/gems/webmock-1.18.0/spec/acceptance/http_gem/http_gem_spec_helper.rb
whos_dated_who-0.0.1 vendor/bundle/gems/webmock-1.18.0/spec/acceptance/http_gem/http_gem_spec_helper.rb
webmock-1.18.0 spec/acceptance/http_gem/http_gem_spec_helper.rb