From 074ac5f392dce51fc91189f1b71d3a831fecce98 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 29 Jun 2012 21:37:05 -0300 Subject: [PATCH] Do not execute @app.call twice in the tests --- test/test_app_status.rb | 44 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/test/test_app_status.rb b/test/test_app_status.rb index d086b322..aba2ebec 100644 --- a/test/test_app_status.rb +++ b/test/test_app_status.rb @@ -28,79 +28,57 @@ class TestAppStatus < Test::Unit::TestCase @app.auth_token = nil end - def lint(env) + def lint(uri) app = Rack::Lint.new @app - mock_env = Rack::MockRequest.env_for env['PATH_INFO'] + mock_env = Rack::MockRequest.env_for uri app.call mock_env end def test_bad_token @app.auth_token = "abcdef" - env = { 'PATH_INFO' => "/whatever" } - - status, _, _ = @app.call env + status, _, _ = lint('/whatever') assert_equal 403, status - lint(env) end def test_good_token @app.auth_token = "abcdef" - env = { - 'PATH_INFO' => "/whatever", - 'QUERY_STRING' => "token=abcdef" - } - - status, _, _ = @app.call env + status, _, _ = lint('/whatever?token=abcdef') assert_equal 404, status - lint(env) end def test_unsupported - env = { 'PATH_INFO' => "/not-real" } - - status, _, _ = @app.call env + status, _, _ = lint('/not-real') assert_equal 404, status - lint(env) end def test_stop - env = { 'PATH_INFO' => "/stop" } - - status, _ , body = @app.call env + status, _ , app = lint('/stop') assert_equal :stop, @server.status assert_equal 200, status - assert_equal ['{ "status": "ok" }'], body - lint(env) + assert_equal ['{ "status": "ok" }'], app.enum_for.to_a end def test_halt - env = { 'PATH_INFO' => "/halt" } - - status, _ , body = @app.call env + status, _ , app = lint('/halt') assert_equal :halt, @server.status assert_equal 200, status - assert_equal ['{ "status": "ok" }'], body - lint(env) + assert_equal ['{ "status": "ok" }'], app.enum_for.to_a end def test_stats - env = { 'PATH_INFO' => "/stats" } - @server.backlog = 1 @server.running = 9 - status, _ , body = @app.call env + status, _ , app = lint('/stats') assert_equal 200, status - assert_equal ['{ "backlog": 1, "running": 9 }'], body - lint(env) + assert_equal ['{ "backlog": 1, "running": 9 }'], app.enum_for.to_a end - end