Class Rack::Test::Session
In: lib/rack/test.rb
Parent: Object

This class represents a series of requests issued to a Rack app, sharing a single cookie jar

Rack::Test::Session‘s methods are most often called through Rack::Test::Methods, which will automatically build a session when it‘s first used.

Methods

authorize   basic_authorize   delete   digest_authorize   follow_redirect!   get   head   header   new   options   patch   post   put   request  

Included Modules

Rack::Test::Utils

Public Class methods

Creates a Rack::Test::Session for a given Rack app or Rack::MockSession.

Note: Generally, you won‘t need to initialize a Rack::Test::Session directly. Instead, you should include Rack::Test::Methods into your testing context. (See README.rdoc for an example)

Public Instance methods

authorize(username, password)

Alias for basic_authorize

Set the username and password for HTTP Basic authorization, to be included in subsequent requests in the HTTP_AUTHORIZATION header.

Example:

  basic_authorize "bryan", "secret"

Issue a DELETE request for the given URI. See get

Example:

  delete "/"

Set the username and password for HTTP Digest authorization, to be included in subsequent requests in the HTTP_AUTHORIZATION header.

Example:

  digest_authorize "bryan", "secret"

Rack::Test will not follow any redirects automatically. This method will follow the redirect returned (including setting the Referer header on the new request) in the last response. If the last response was not a redirect, an error will be raised.

Issue a GET request for the given URI with the given params and Rack environment. Stores the issues request object in last_request and the app‘s response in last_response. Yield last_response to a block if given.

Example:

  get "/"

Issue a HEAD request for the given URI. See get

Example:

  head "/"

Set a header to be included on all subsequent requests through the session. Use a value of nil to remove a previously configured header.

In accordance with the Rack spec, headers will be included in the Rack environment hash in HTTP_USER_AGENT form.

Example:

  header "User-Agent", "Firefox"

Issue an OPTIONS request for the given URI. See get

Example:

  options "/"

Issue a PATCH request for the given URI. See get

Example:

  patch "/"

Issue a POST request for the given URI. See get

Example:

  post "/signup", "name" => "Bryan"

Issue a PUT request for the given URI. See get

Example:

  put "/"

Issue a request to the Rack app for the given URI and optional Rack environment. Stores the issues request object in last_request and the app‘s response in last_response. Yield last_response to a block if given.

Example:

  request "/"

[Validate]