Sha256: d5eb685fbbeb5804f9c76630ae07cf897d44467996795507d6d7c63c7f3df55e

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

require "ostruct"

module HttpRbSpecHelper
  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_rb
  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

3 entries across 3 versions & 2 rubygems

Version Path
logstash-filter-zabbix-0.1.2 vendor/bundle/jruby/1.9/gems/webmock-1.21.0/spec/acceptance/http_rb/http_rb_spec_helper.rb
logstash-filter-zabbix-0.1.1 vendor/bundle/jruby/1.9/gems/webmock-1.21.0/spec/acceptance/http_rb/http_rb_spec_helper.rb
webmock-1.21.0 spec/acceptance/http_rb/http_rb_spec_helper.rb