require File.dirname(__FILE__) + '/helper'
describe 'Result Handling' do
it "sets response.body when result is a String" do
mock_app {
get '/' do
'Hello World'
end
}
get '/'
assert ok?
assert_equal 'Hello World', body
it "sets response.body when result is an Array of Strings" do
['Hello', 'World']
assert_equal 'HelloWorld', body
it "sets response.body when result responds to #each" do
res = lambda { 'Hello World' }
def res.each ; yield call ; end
res
it "sets response.body to [] when result is nil" do
nil
assert_equal '', body
it "sets status, headers, and body when result is a Rack response tuple" do
[205, {'Content-Type' => 'foo/bar'}, 'Hello World']
assert_equal 205, status
assert_equal 'foo/bar', response['Content-Type']
it "sets status and body when result is a two-tuple" do
[409, 'formula of']
assert_equal 409, status
assert_equal 'formula of', body
it "sets status when result is a Fixnum status code" do
get('/') { 205 }