Sha256: 8cb0f5e19de08b29a360345b77d0a7e76a790257d4d934b9e13f9046aeca9d2f

Contents?: true

Size: 1.25 KB

Versions: 28

Compression:

Stored size: 1.25 KB

Contents

require 'yaml'
require 'net/http'

class TestRequest
  def call(env)
    status = env["QUERY_STRING"] =~ /secret/ ? 403 : 200
    env["test.postdata"] = env["rack.input"].read
    body = env.to_yaml
    size = body.respond_to?(:bytesize) ? body.bytesize : body.size
    [status, {"Content-Type" => "text/yaml", "Content-Length" => size.to_s}, [body]]
  end

  module Helpers
    attr_reader :status, :response

    def GET(path, header={})
      Net::HTTP.start(@host, @port) { |http|
        user = header.delete(:user)
        passwd = header.delete(:passwd)

        get = Net::HTTP::Get.new(path, header)
        get.basic_auth user, passwd  if user && passwd
        http.request(get) { |response|
          @status = response.code.to_i
          @response = YAML.load(response.body)
        }
      }
    end

    def POST(path, formdata={}, header={})
      Net::HTTP.start(@host, @port) { |http|
        user = header.delete(:user)
        passwd = header.delete(:passwd)

        post = Net::HTTP::Post.new(path, header)
        post.form_data = formdata
        post.basic_auth user, passwd  if user && passwd
        http.request(post) { |response|
          @status = response.code.to_i
          @response = YAML.load(response.body)
        }
      }
    end
  end
end

Version data entries

28 entries across 28 versions & 6 rubygems

Version Path
relevance-castronaut-0.5.4 vendor/rack/test/testrequest.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/test/testrequest.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/test/testrequest.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/test/testrequest.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/test/testrequest.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/test/testrequest.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/rack-0.4.0/test/testrequest.rb
rack-0.4.0 test/testrequest.rb