Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bulk pr for readme updates #174

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

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.
to build on.

== Features

Expand All @@ -18,27 +17,34 @@ request helpers feature.

== Examples

require "test/unit"
require "rack/test"

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

def app
MyApp.new
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['All responses are OK']] }
builder = Rack::Builder.new
builder.run app
end

def test_redirect_logged_in_users_to_dashboard
authorize "bryan", "secret"

def test_response_is_ok
get "/"
follow_redirect!

assert_equal "http://example.org/redirected", last_request.url

assert last_response.ok?
assert_equal last_response.body, "All responses are OK"
end


def test_response_is_ok_for_other_paths
get "/other_paths"

assert last_response.ok?
assert_equal last_response.body, "All responses are OK"
end

end


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").first
Expand Down Expand Up @@ -75,7 +81,7 @@ Or via Bundler:

== License

Copyright (c) 2008-2009 Bryan Helmkamp, Engine Yard Inc.
Copyright (c) 2008-2013 Bryan Helmkamp
See MIT-LICENSE.txt in this directory.

== Releasing
Expand Down