
Security News
ESLint Adds Official Support for Linting HTML
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Code: https://github.com/rack/rack-test
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.
These examples use test/unit
but it's equally possible to use rack-test
with
other testing frameworks such as minitest
or rspec
.
require "test/unit"
require "rack/test"
require "json"
class HomepageTest < Test::Unit::TestCase
include Rack::Test::Methods
def app
lambda { |env| [200, {'content-type' => 'text/plain'}, ['All responses are OK']] }
end
def test_response_is_ok
# Optionally set headers used for all requests in this spec:
#header 'accept-charset', 'utf-8'
# First argument is treated as the path
get '/'
assert last_response.ok?
assert_equal 'All responses are OK', last_response.body
end
def delete_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')
end
def post_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')
end
end
rack-test
will test the app returned by the app
method. If you are loading middleware
in a config.ru
file, and want to test that, you should load the Rack app created from
the config.ru
file:
OUTER_APP = Rack::Builder.parse_file("config.ru").first
class TestApp < Test::Unit::TestCase
include Rack::Test::Methods
def app
OUTER_APP
end
def test_root
get "/"
assert last_response.ok?
end
end
To install the latest release as a gem:
gem install rack-test
Or add to your Gemfile
:
gem 'rack-test'
Contributions are welcome. Please make sure to:
History.md
is updatedrack-test
is released under the MIT License.
History.md
is up-to-date, including correct version and dategit 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
FAQs
Unknown package
We found that rack-test demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.