1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00
sinatra/test/app_test.rb

137 lines
2.5 KiB
Ruby
Raw Normal View History

2007-11-28 05:55:19 -05: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 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
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
specify "delegates HEAD requests to GET handlers" do
get '/invisible' do
"I am invisible to the world"
end
head_it '/invisible'
should.be.ok
body.should.not.equal "I am invisible to the world"
body.should.equal ''
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
# Some Ajax libraries downcase the _method parameter value. Make
# sure we can handle that.
specify "put'n with POST and lowercase _method param" do
put '/' do
'puted'
end
post_it '/', :_method => 'put'
body.should.equal 'puted'
end
# Ignore any _method parameters specified in GET requests or on the query string in POST requests.
specify "not put'n with GET" do
get '/' do
'getted'
end
get_it '/', :_method => 'put'
should.be.ok
body.should.equal 'getted'
end
specify "_method query string parameter ignored on POST" do
post '/' do
'posted'
end
put '/' do
'booo'
end
post_it "/?_method=PUT"
should.be.ok
body.should.equal 'posted'
end
2007-11-28 05:55:19 -05:00
end