sinatra/test/app_test.rb

94 lines
1.5 KiB
Ruby
Raw Normal View History

2007-11-28 10:55:19 +00:00
require File.dirname(__FILE__) + '/helper'
context "Sinatra" do
setup do
Sinatra.application = nil
end
specify "should handle result of nil" do
get '/' do
nil
end
get_it '/'
should.be.ok
body.should == ''
end
2007-11-28 10:55:19 +00: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 07:46:29 +00: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 21:25:14 +00:00
specify "body sets content and ends event" do
Sinatra::EventContext.any_instance.expects(:foo).never
get '/set_body' do
stop 'Hello!'
stop 'World!'
2007-11-28 21:25:14 +00:00
foo
end
get_it '/set_body'
should.be.ok
body.should.equal 'Hello!'
end
2008-03-05 00:30:06 +00: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 21:25:14 +00:00
2007-11-28 10:55:19 +00:00
end