1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00
sinatra/sinatra-contrib/spec/multi_route_spec.rb
2016-06-21 15:12:09 -03:00

59 lines
1.2 KiB
Ruby

require 'spec_helper'
describe Sinatra::MultiRoute do
it 'does not break normal routing' do
mock_app do
register Sinatra::MultiRoute
get('/') { 'normal' }
end
expect(get('/')).to be_ok
expect(body).to eq('normal')
end
it 'supports multiple routes' do
mock_app do
register Sinatra::MultiRoute
get('/foo', '/bar') { 'paths' }
end
expect(get('/foo')).to be_ok
expect(body).to eq('paths')
expect(get('/bar')).to be_ok
expect(body).to eq('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
expect(count).to eq(4)
end
it 'supports multiple verbs' do
mock_app do
register Sinatra::MultiRoute
route('PUT', 'POST', '/') { 'verb' }
end
expect(post('/')).to be_ok
expect(body).to eq('verb')
expect(put('/')).to be_ok
expect(body).to eq('verb')
end
it 'takes symbols as verbs' do
mock_app do
register Sinatra::MultiRoute
route(:get, '/baz') { 'symbol as verb' }
end
expect(get('/baz')).to be_ok
expect(body).to eq('symbol as verb')
end
end