Skip to content

Instantly share code, notes, and snippets.

@sr
Forked from brynary/gist:69372
Created February 24, 2009 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sr/69374 to your computer and use it in GitHub Desktop.
Save sr/69374 to your computer and use it in GitHub Desktop.
module Rack
module Test
module Session
attr_reader :last_response
attr_reader :last_request
alias_method :response, :last_response
alias_method :request, :last_request
def initialize(app)
@app = app
end
# get "/", :foo => "bar"
# post "/", "foobar"
# get "/", :foo => "bar", :headers => { "User-Agent" => "Rack::Test" }
# get "/", :headers => { "HTTP_ACCEPT" => "text/plain" }
# get "/", :env => { "HTTP_ACCEPT" => "text/plain" } # same
# post "/", "foo bar", :env => { "rack.sessions" => { "foo" => "bar" }
#
# :headers is just a sugar for :env which can be used to modify the
# Rack env
def get(path, data=nil, headers=nil)
request!(path, data, headers)
end
def head
def post
def put
def delete
# The four above methods need to call one underlying impl...
# dispatch_request, process_request, .. ???
private
def request!(path, data=nil, headers=nil)
@request = make_request(path, data, headers)
@response = Rack::Response.new(@app.call(env))
end
def build_request(path, data, headers)
# data is either the input or an hash of params
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment