Sha256: 10d0d96a90c13f59de2fae7ac872d62dc6d3df089a4aacf89ab0c361ae24c3db

Contents?: true

Size: 1.17 KB

Versions: 20

Compression:

Stored size: 1.17 KB

Contents

require 'httpi'
require 'httpi/response'

module HTTPI
  module Adapters
    # This is an adapter for testing the Rack applications with HTTPI-capable
    # clients.
    class Rack
      class << self
        attr_accessor :mounted_apps
      end

      self.mounted_apps = {}

      def self.mount(host, application)
        self.mounted_apps[host] = application
      end

      def initialize(request=nil)
      end

      def method_missing(method, *args)
        if %w{get post head put delete}.include?(method.to_s)
          request, = args

          app = self.class.mounted_apps[request.url.host]
          mock_req = ::Rack::MockRequest.new(app)

          env = {}
          request.headers.each do |header, value|
            env["HTTP_#{header.gsub('-', '_').upcase}"] = value
          end

          mock_resp = mock_req.request(method.to_s.upcase, request.url.to_s,
                { :fatal => true, :input => request.body.to_s }.merge(env))

          HTTPI::Response.new(mock_resp.status, mock_resp.headers, mock_resp.body)
        else
          super
        end
      end
    end
  end

  Adapter::ADAPTERS[:rack] = { :class => Adapters::Rack, :require => 'rack/mock' }
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
wash_out-0.5.6 spec/support/httpi-rack.rb
wash_out-0.5.4 spec/support/httpi-rack.rb
wash_out-0.5.3 spec/support/httpi-rack.rb
nogara-wash_out-0.5.2 spec/support/httpi-rack.rb
wash_out-0.5.2 spec/support/httpi-rack.rb
wash_out-0.4.2 spec/support/httpi-rack.rb
wash_out-0.4.1 spec/support/httpi-rack.rb
wash_out-0.4.0 spec/support/httpi-rack.rb
wash_out-0.3.6 spec/support/httpi-rack.rb
wash_out-0.3.5 spec/support/httpi-rack.rb
wash_out-0.3.4 spec/support/httpi-rack.rb
wash_out-0.3.3 spec/support/httpi-rack.rb
wash_out-0.3.2 spec/support/httpi-rack.rb
wash_out-0.3.1 spec/support/httpi-rack.rb
wash_out-0.3.0 spec/support/httpi-rack.rb
wash_out-0.2.6 spec/support/httpi-rack.rb
wash_out-0.2.5 spec/support/httpi-rack.rb
wash_out-0.2.4 spec/support/httpi-rack.rb
wash_out-0.2.3 spec/support/httpi-rack.rb
wash_out-0.2.2 spec/support/httpi-rack.rb