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

a small working example #65

Closed
wants to merge 1 commit into from
Closed
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
29 changes: 18 additions & 11 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,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