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
3mix-castronaut-0.5.0.2 vendor/rack/test/testrequest.rb
kastner-rack-0.3.171 test/testrequest.rb
masover-castronaut-0.4.4.4 vendor/rack/test/testrequest.rb
masover-castronaut-0.4.4.5 vendor/rack/test/testrequest.rb
masover-castronaut-0.5.0.1 vendor/rack/test/testrequest.rb
relevance-castronaut-0.2.0 vendor/rack/test/testrequest.rb
relevance-castronaut-0.2.5 vendor/rack/test/testrequest.rb
relevance-castronaut-0.3.0 vendor/rack/test/testrequest.rb
relevance-castronaut-0.3.5 vendor/rack/test/testrequest.rb
relevance-castronaut-0.3.6 vendor/rack/test/testrequest.rb
relevance-castronaut-0.4.1 vendor/rack/test/testrequest.rb
relevance-castronaut-0.4.2 vendor/rack/test/testrequest.rb
relevance-castronaut-0.4.3 vendor/rack/test/testrequest.rb
relevance-castronaut-0.4.4 vendor/rack/test/testrequest.rb
relevance-castronaut-0.4.5 vendor/rack/test/testrequest.rb
relevance-castronaut-0.4.6 vendor/rack/test/testrequest.rb
relevance-castronaut-0.5.0 vendor/rack/test/testrequest.rb
relevance-castronaut-0.5.1 vendor/rack/test/testrequest.rb
relevance-castronaut-0.5.2 vendor/rack/test/testrequest.rb
relevance-castronaut-0.5.3 vendor/rack/test/testrequest.rb