Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Rack::Test is a small, simple testing API for Rack apps.

License

NotificationsYou must be signed in to change notification settings

gmalette/rack-test

 
 

Repository files navigation

Gem Version

Code:https://github.com/rack/rack-test

Description

Rack::Test is a small, simple testing API for Rack apps. It can be used on itsown or as a reusable starting point for Web frameworks and testing librariesto build on.

Features

  • Allows for submitting requests and testing responses
  • Maintains a cookie jar across requests
  • Supports request headers used for subsequent requests
  • Follow redirects when requested

Examples

These examples usetest/unit but it's equally possible to userack-test withother testing frameworks such asminitest orrspec.

require"test/unit"require"rack/test"require"json"classHomepageTest <Test::Unit::TestCaseincludeRack::Test::Methodsdefapplambda{ |env|[200,{'content-type'=>'text/plain'},['All responses are OK']]}enddeftest_response_is_ok# Optionally set headers used for all requests in this spec:#header 'accept-charset', 'utf-8'# First argument is treated as the pathget'/'assertlast_response.ok?assert_equal'All responses are OK',last_response.bodyenddefdelete_with_url_params_and_body# First argument can have a query string## Second argument is used as the parameters for the request, which will be# included in the request body for non-GET requests.delete'/?foo=bar',JSON.generate('baz'=>'zot')enddefpost_with_json# Third argument is the rack environment to use for the request.  The following# entries in the submitted rack environment are treated specially (in addition# to options supported by `Rack::MockRequest#env_for`:## :cookie : Set a cookie for the current session before submitting the request.## :query_params : Set parameters for the query string (as opposed to the body).#                 Value should be a hash of parameters.## :xhr : Set HTTP_X_REQUESTED_WITH env key to XMLHttpRequest.post(uri,JSON.generate('baz'=>'zot'),'CONTENT_TYPE'=>'application/json')endend

rack-test will test the app returned by theapp method. If you are loading middlewarein aconfig.ru file, and want to test that, you should load the Rack app created fromtheconfig.ru file:

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 add to yourGemfile:

gem 'rack-test'

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
  • EnsureHistory.md is updated

Authors

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

License

rack-test is released under theMIT License.

Supported platforms

  • Ruby 2.0+
  • JRuby 9.1+

Releasing

  • Bump VERSION in lib/rack/test/version.rb
  • EnsureHistory.md is up-to-date, including correct version and date
  • git commit . -m 'Release $VERSION'
  • git push
  • git tag -a -m 'Tag the $VERSION release' $VERSION
  • git push --tags
  • gem build rack-test.gemspec
  • gem push rack-test-$VERSION.gem
  • Add a discussion post for the release

About

Rack::Test is a small, simple testing API for Rack apps.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby99.9%
  • Logos0.1%

[8]ページ先頭

©2009-2025 Movatter.jp