Sha256: 212aef71ba5cdacee37274ca4056148385a5ab9485c59018ddd76e46dff7e4dc

Contents?: true

Size: 1.43 KB

Versions: 69

Compression:

Stored size: 1.43 KB

Contents

require 'ostruct'

module TyphoeusHydraSpecHelper
  class FakeTyphoeusHydraTimeoutError < StandardError; end
  class FakeTyphoeusHydraConnectError < StandardError; end


  def http_request(method, uri, options = {}, &block)
    uri = uri.gsub(" ", "%20") #typhoeus doesn't like spaces in the uri
    request_options =  {
      method: method,
      body: options[:body],
      headers: options[:headers],
      timeout: 25000
    }
    if options[:basic_auth]
      request_options[:userpwd] = options[:basic_auth].join(':')
    end
    request = Typhoeus::Request.new(uri, request_options)

    hydra = Typhoeus::Hydra.new
    hydra.queue(request)
    hydra.run

    response = request.response
    raise FakeTyphoeusHydraConnectError.new if response.return_code == :couldnt_connect
    raise FakeTyphoeusHydraTimeoutError.new if response.timed_out?
    OpenStruct.new({
      body: response.body,
      headers: WebMock::Util::Headers.normalize_headers(join_array_values(response.headers)),
      status: response.code.to_s,
      message: response.status_message
    })
  end

  def join_array_values(hash)
    joined = {}
    if hash
     hash.each do |k,v|
       v = v.join(", ") if v.is_a?(Array)
       joined[k] = v
     end
    end
    joined
  end


  def client_timeout_exception_class
    FakeTyphoeusHydraTimeoutError
  end

  def connection_refused_exception_class
    FakeTyphoeusHydraConnectError
  end

  def http_library
    :typhoeus
  end

end

Version data entries

69 entries across 69 versions & 5 rubygems

Version Path
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/webmock-3.18.1/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
webmock-3.18.1 spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
webmock-3.18.0 spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
webmock-3.15.2 spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
webmock-3.16.2 spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
webmock-3.16.1 spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
webmock-3.15.1 spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
webmock-3.17.1 spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
webmock-3.17.0 spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
webmock-3.14.0 spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb