sinatra/sinatra-contrib/spec/multi_route_spec.rb

60 lines
1.2 KiB
Ruby
Raw Normal View History

2014-05-09 06:39:16 +00:00
require 'spec_helper'
2011-09-05 01:13:27 +00:00
describe Sinatra::MultiRoute do
it 'does not break normal routing' do
2011-09-05 01:13:27 +00:00
mock_app do
register Sinatra::MultiRoute
get('/') { 'normal' }
end
get('/').should be_ok
body.should be == 'normal'
end
2012-12-09 16:35:15 +00:00
it 'supports multiple routes' do
mock_app do
register Sinatra::MultiRoute
get('/foo', '/bar') { 'paths' }
end
2011-09-05 01:13:27 +00:00
get('/foo').should be_ok
body.should be == 'paths'
get('/bar').should be_ok
body.should be == 'paths'
end
it 'triggers conditions' do
count = 0
mock_app do
register Sinatra::MultiRoute
set(:some_condition) { |_| count += 1 }
get('/foo', '/bar', :some_condition => true) { 'paths' }
end
count.should be == 4
2011-09-05 01:13:27 +00:00
end
2012-12-09 16:35:15 +00:00
it 'supports multiple verbs' do
mock_app do
register Sinatra::MultiRoute
route('PUT', 'POST', '/') { 'verb' }
end
2011-09-05 01:13:27 +00:00
post('/').should be_ok
body.should be == 'verb'
put('/').should be_ok
body.should be == 'verb'
end
it 'takes symbols as verbs' do
mock_app do
register Sinatra::MultiRoute
route(:get, '/baz') { 'symbol as verb' }
end
2011-09-05 01:13:27 +00:00
get('/baz').should be_ok
body.should be == 'symbol as verb'
end
2012-12-09 16:35:15 +00:00
end