2007-11-28 05:55:19 -05:00
|
|
|
require File.dirname(__FILE__) + '/helper'
|
|
|
|
|
|
|
|
context "Sinatra" do
|
|
|
|
|
|
|
|
setup do
|
|
|
|
Sinatra.application = nil
|
|
|
|
end
|
|
|
|
|
2008-02-19 22:51:39 -05:00
|
|
|
specify "should handle result of nil" do
|
|
|
|
get '/' do
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
get_it '/'
|
|
|
|
should.be.ok
|
|
|
|
body.should == ''
|
|
|
|
end
|
|
|
|
|
2007-11-28 05:55:19 -05:00
|
|
|
specify "handles events" do
|
|
|
|
get '/:name' do
|
|
|
|
'Hello ' + params[:name]
|
|
|
|
end
|
|
|
|
|
|
|
|
get_it '/Blake'
|
|
|
|
|
|
|
|
should.be.ok
|
|
|
|
body.should.equal 'Hello Blake'
|
|
|
|
end
|
|
|
|
|
|
|
|
specify "follows redirects" do
|
|
|
|
get '/' do
|
|
|
|
redirect '/blake'
|
|
|
|
end
|
|
|
|
|
|
|
|
get '/blake' do
|
|
|
|
'Mizerany'
|
|
|
|
end
|
|
|
|
|
|
|
|
get_it '/'
|
|
|
|
should.be.redirection
|
|
|
|
body.should.equal ''
|
|
|
|
|
|
|
|
follow!
|
|
|
|
should.be.ok
|
|
|
|
body.should.equal 'Mizerany'
|
|
|
|
end
|
|
|
|
|
2008-02-21 02:46:29 -05:00
|
|
|
specify "renders a body with a redirect" do
|
|
|
|
Sinatra::EventContext.any_instance.expects(:foo).returns('blah')
|
|
|
|
get "/" do
|
|
|
|
redirect 'foo', :foo
|
|
|
|
end
|
|
|
|
get_it '/'
|
|
|
|
should.be.redirection
|
|
|
|
headers['Location'].should.equal 'foo'
|
|
|
|
body.should.equal 'blah'
|
|
|
|
end
|
|
|
|
|
2007-11-28 16:25:14 -05:00
|
|
|
specify "body sets content and ends event" do
|
|
|
|
|
|
|
|
Sinatra::EventContext.any_instance.expects(:foo).never
|
|
|
|
|
|
|
|
get '/set_body' do
|
2007-11-29 00:28:59 -05:00
|
|
|
stop 'Hello!'
|
|
|
|
stop 'World!'
|
2007-11-28 16:25:14 -05:00
|
|
|
foo
|
|
|
|
end
|
|
|
|
|
|
|
|
get_it '/set_body'
|
|
|
|
|
|
|
|
should.be.ok
|
|
|
|
body.should.equal 'Hello!'
|
|
|
|
|
|
|
|
end
|
2008-03-04 19:30:06 -05:00
|
|
|
|
|
|
|
specify "put'n with POST" do
|
|
|
|
put '/' do
|
|
|
|
'puted'
|
|
|
|
end
|
|
|
|
post_it '/', :_method => 'PUT'
|
|
|
|
assert_equal 'puted', body
|
|
|
|
end
|
|
|
|
|
|
|
|
specify "put'n wth PUT" do
|
|
|
|
put '/' do
|
|
|
|
'puted'
|
|
|
|
end
|
|
|
|
put_it '/'
|
|
|
|
assert_equal 'puted', body
|
|
|
|
end
|
|
|
|
|
2007-11-28 16:25:14 -05:00
|
|
|
|
2007-11-28 05:55:19 -05:00
|
|
|
end
|