2011-05-11 03:44:02 -04:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
2008-12-13 16:06:02 -05:00
|
|
|
|
2009-03-26 11:42:13 -04:00
|
|
|
class ResultTest < Test::Unit::TestCase
|
2008-12-13 16:06:02 -05:00
|
|
|
it "sets response.body when result is a String" do
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app { get('/') { 'Hello World' } }
|
2008-12-13 16:06:02 -05:00
|
|
|
|
|
|
|
get '/'
|
2009-01-14 17:00:26 -05:00
|
|
|
assert ok?
|
|
|
|
assert_equal 'Hello World', body
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets response.body when result is an Array of Strings" do
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app { get('/') { ['Hello', 'World'] } }
|
2008-12-13 16:06:02 -05:00
|
|
|
|
|
|
|
get '/'
|
2009-01-14 17:00:26 -05:00
|
|
|
assert ok?
|
|
|
|
assert_equal 'HelloWorld', body
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets response.body when result responds to #each" do
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app do
|
|
|
|
get('/') do
|
2008-12-13 16:06:02 -05:00
|
|
|
res = lambda { 'Hello World' }
|
|
|
|
def res.each ; yield call ; end
|
2012-05-21 17:21:59 -04:00
|
|
|
return res
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|
2012-05-21 17:21:59 -04:00
|
|
|
end
|
2008-12-13 16:06:02 -05:00
|
|
|
|
|
|
|
get '/'
|
2009-01-14 17:00:26 -05:00
|
|
|
assert ok?
|
|
|
|
assert_equal 'Hello World', body
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets response.body to [] when result is nil" do
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app { get( '/') { nil } }
|
2008-12-13 16:06:02 -05:00
|
|
|
|
|
|
|
get '/'
|
2009-01-14 17:00:26 -05:00
|
|
|
assert ok?
|
|
|
|
assert_equal '', body
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets status, headers, and body when result is a Rack response tuple" do
|
|
|
|
mock_app {
|
2012-05-21 17:21:59 -04:00
|
|
|
get('/') { [203, {'Content-Type' => 'foo/bar'}, 'Hello World'] }
|
2008-12-13 16:06:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
get '/'
|
2011-08-17 08:02:05 -04:00
|
|
|
assert_equal 203, status
|
2009-01-14 17:00:26 -05:00
|
|
|
assert_equal 'foo/bar', response['Content-Type']
|
|
|
|
assert_equal 'Hello World', body
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|
|
|
|
|
2008-12-21 05:11:25 -05:00
|
|
|
it "sets status and body when result is a two-tuple" do
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app { get('/') { [409, 'formula of'] } }
|
2008-12-21 05:11:25 -05:00
|
|
|
|
|
|
|
get '/'
|
2009-01-14 17:00:26 -05:00
|
|
|
assert_equal 409, status
|
|
|
|
assert_equal 'formula of', body
|
2008-12-21 05:11:25 -05:00
|
|
|
end
|
|
|
|
|
2011-06-04 12:24:42 -04:00
|
|
|
it "raises a ArgumentError when result is a non two or three tuple Array" do
|
2009-01-19 20:58:26 -05:00
|
|
|
mock_app {
|
2012-05-21 17:21:59 -04:00
|
|
|
get('/') { [409, 'formula of', 'something else', 'even more'] }
|
2009-01-19 20:58:26 -05:00
|
|
|
}
|
|
|
|
|
2011-06-04 12:24:42 -04:00
|
|
|
assert_raise(ArgumentError) { get '/' }
|
2009-01-19 20:58:26 -05:00
|
|
|
end
|
|
|
|
|
2008-12-13 16:06:02 -05:00
|
|
|
it "sets status when result is a Fixnum status code" do
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app { get('/') { 205 } }
|
2008-12-13 16:06:02 -05:00
|
|
|
|
|
|
|
get '/'
|
2009-01-14 17:00:26 -05:00
|
|
|
assert_equal 205, status
|
|
|
|
assert_equal '', body
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|
|
|
|
end
|