1 require File.dirname(__FILE__) + '/helper'
3 context "Dispatching" do
5 include Sinatra::Test::Methods
8 Sinatra.config[:raise_errors] = false
10 Sinatra.config[:raise_errors] = true
15 Sinatra.setup_default_events!
18 specify "should return the correct block" do
23 result = Sinatra.determine_route(:get, '/')
24 result.block.should.be r.block
27 specify "should return custom 404" do
28 Sinatra.routes[404] = r = Proc.new { 'custom 404' }
30 result = Sinatra.determine_route(:get, '/')
34 specify "should return standard 404" do
36 status.should.equal 404
37 body.should.equal '<h1>Not Found</h1>'
40 specify "should give custom 500 if error when called" do
41 Sinatra.routes[500] = r = Proc.new { 'custom 500' }
51 body.should.equal 'custom 500'
54 specify "should give standard 500 if error when called" do
63 body.should.match(/^asdf/)
66 specify "should run in a context" do
67 Sinatra::EventContext.any_instance.expects(:foo).returns 'in foo'
74 body.should.equal 'in foo'
77 specify "has access to the request" do
85 body.should.equal '/blake'
89 specify "has DSLified methods for response" do
97 body.should.equal "uh oh"
98 status.should.equal 555
103 context "An Event in test mode" do
105 include Sinatra::Test::Methods
109 Sinatra.setup_default_events!
112 specify "should raise errors to top" do
117 lambda { get_it '/' }.should.raise(RuntimeError)