sinatra/test/mapped_error_test.rb

62 lines
808 B
Ruby
Raw Normal View History

2008-02-24 01:00:04 +00:00
require File.dirname(__FILE__) + '/helper'
class FooError < RuntimeError; end
context "Mapped errors" do
setup do
2008-02-24 01:00:04 +00:00
Sinatra.application = nil
end
2008-02-24 01:00:04 +00:00
specify "are rescued and run in context" do
2008-02-24 01:00:04 +00:00
error FooError do
'MAPPED ERROR!'
end
2008-02-24 01:00:04 +00:00
get '/' do
raise FooError.new
end
2008-02-24 01:00:04 +00:00
get_it '/'
2008-02-24 01:00:04 +00:00
should.be.server_error
body.should.equal 'MAPPED ERROR!'
2008-02-24 01:00:04 +00:00
end
specify "renders empty if no each method on result" do
2008-02-24 01:00:04 +00:00
error FooError do
nil
end
2008-02-24 01:00:04 +00:00
get '/' do
raise FooError.new
end
2008-02-24 01:00:04 +00:00
get_it '/'
2008-02-24 01:00:04 +00:00
should.be.server_error
body.should.be.empty
2008-02-24 01:00:04 +00:00
end
specify "doesn't override status if set" do
2008-02-24 01:00:04 +00:00
error FooError do
status(200)
end
2008-02-24 01:00:04 +00:00
get '/' do
raise FooError.new
end
2008-02-24 01:00:04 +00:00
get_it '/'
2008-02-24 01:00:04 +00:00
should.be.ok
2008-02-24 01:00:04 +00:00
end
2008-02-24 01:00:04 +00:00
end