Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Rack::Test is a layer on top of Rack's MockRequest similar to Merb's RequestHelper
Ruby
branch: master

This branch is 1 commit ahead, 90 commits behind brynary:master

Add the ability to test a config.ru and allow not defining app

default to looking for ../config.ru if app not defined
latest commit dd53246278
@timocratic authored

README.rdoc

Rack::Test

Description

Rack::Test is a small, simple testing API for Rack apps. It can be used on its own or as a reusable starting point for Web frameworks and testing libraries to build on. Most of its initial functionality is an extraction of Merb 1.0's request helpers feature.

Features

  • Maintains a cookie jar across requests

  • Easily follow redirects when desired

  • Set request headers to be used by all subsequent requests

  • Small footprint. Approximately 200 LOC

Example

require "rack/test"

class HomepageTest < Test::Unit::TestCase
  include Rack::Test::Methods

  def app
    MyApp.new
  end

  def test_redirect_logged_in_users_to_dashboard
    authorize "bryan", "secret"
    get "/"
    follow_redirect!

    assert_equal "http://example.org/redirected", last_request.url
    assert last_response.ok?
  end

end

Testing a config.ru

You can also use Rack::Test without an explicit app method. In this case it will check for a CONFIG_RU constant and if that is missing look for a config.ru one level up from the test file

require "rack/test"

class HomepageTest < Test::Unit::TestCase
  include Rack::Test::Methods

  #Only needed if it varies from this
  #CONFIG_RU = File.dirname(__FILE__) + '/../config.ru'

  def test_redirect_logged_in_users_to_dashboard
    authorize "bryan", "secret"
    get "/"
    follow_redirect!

    assert_equal "http://example.org/redirected", last_request.url
    assert last_response.ok?
  end

end

Install

To install the latest release as a gem:

sudo gem install rack-test

Authors

  • Maintained by Bryan Helmkamp

  • Contributions from Simon Rozet and Pat Nakajima

  • Much of the original code was extracted from Merb 1.0's request helper

License

Copyright © 2008-2009 Bryan Helmkamp, Engine Yard Inc. See MIT-LICENSE.txt in this directory.

Something went wrong with that request. Please try again.