Skip to content

Repository files navigation

Rack::Test

Code: https://github.com/rack-test/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.

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

Examples

require"test/unit"require"rack/test"classHomepageTest < Test::Unit::TestCaseincludeRack::Test::Methodsdefappapp=lambda{ |env| [200,{'Content-Type'=>'text/plain'},['All responses are OK']]}builder=Rack::Builder.newbuilder.runappenddeftest_response_is_okget"/"assertlast_response.ok?assert_equallast_response.body,"All responses are OK"enddeftest_response_is_ok_for_other_pathsget"/other_paths"assertlast_response.ok?assert_equallast_response.body,"All responses are OK"endend

If you want to test one app in isolation, you just return that app as shown above. But if you want to test the entire app stack, including middlewares, cascades etc. you need to parse the app defined in config.ru.

OUTER_APP=Rack::Builder.parse_file("config.ru").firstclassTestApp < Test::Unit::TestCaseincludeRack::Test::MethodsdefappOUTER_APPenddeftest_rootget"/"assertlast_response.ok?endend

Install

To install the latest release as a gem:

gem install rack-test

Or via Bundler:

gem "rack-test", require: "rack/test"

Authors

  • Contributions from Bryan Helmkamp, Simon Rozet, Pat Nakajima and others
  • Much of the original code was extracted from Merb 1.0's request helper

License

rack-test is released under the MIT License.

Contribution

Contributions are welcome. Please make sure to:

  • Use a regular forking workflow
  • Write tests for the new or changed behaviour
  • Provide an explanation/motivation in your commit message / PR message
  • Ensure History.txt is updated

Releasing

  • Ensure History.txt is up-to-date
  • Bump VERSION in lib/rack/test/version.rb
  • bundle exec thor :release

About

Rack::Test is a layer on top of Rack's MockRequest similar to Merb's RequestHelper

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages