Sha256: 6f814fc3c318d6169b25019e34146f16bf8915756286f67b978346a17b9b38b7

Contents?: true

Size: 1.09 KB

Versions: 10

Compression:

Stored size: 1.09 KB

Contents

require 'ostruct'

module TyphoeusHydraSpecHelper
  class FakeTyphoeusHydraError < StandardError; end


  def http_request(method, uri, options = {}, &block)
    uri.gsub!(" ", "%20") #typhoeus doesn't like spaces in the uri
    response = Typhoeus::Request.run(uri,
      {
        :method  => method,
        :body    => options[:body],
        :headers => options[:headers],
        :timeout => 15000 # milliseconds
      }
    )
    raise FakeTyphoeusHydraError.new if response.code.to_s == "0"
    OpenStruct.new({
      :body => response.body,
      :headers => WebMock::Util::Headers.normalize_headers(join_array_values(response.headers_hash)),
      :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
    FakeTyphoeusHydraError
  end

  def connection_refused_exception_class
    FakeTyphoeusHydraError
  end

  def http_library
    :typhoeus
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
webmock-1.7.10 spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
webmock-1.7.8 spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
webmock-1.7.7 spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
webmock-1.7.6 spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb
webmock-1.7.5 spec/typhoeus_hydra_spec_helper.rb
webmock-1.7.4 spec/typhoeus_hydra_spec_helper.rb
webmock-1.7.3 spec/typhoeus_hydra_spec_helper.rb
webmock-1.7.2 spec/typhoeus_hydra_spec_helper.rb
webmock-1.7.1 spec/typhoeus_hydra_spec_helper.rb
webmock-1.7.0 spec/typhoeus_hydra_spec_helper.rb