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

60 lines
1.2 KiB
Ruby
Raw Permalink Normal View History

2014-05-09 02:39:16 -04:00
require 'spec_helper'
2011-09-04 21:13:27 -04:00
RSpec.describe Sinatra::MultiRoute do
it 'does not break normal routing' do
2011-09-04 21:13:27 -04:00
mock_app do
register Sinatra::MultiRoute
get('/') { 'normal' }
end
2016-05-10 10:08:54 -04:00
expect(get('/')).to be_ok
expect(body).to eq('normal')
2011-09-04 21:13:27 -04:00
end
2012-12-09 11:35:15 -05:00
it 'supports multiple routes' do
mock_app do
register Sinatra::MultiRoute
get('/foo', '/bar') { 'paths' }
end
2016-05-10 10:08:54 -04:00
expect(get('/foo')).to be_ok
expect(body).to eq('paths')
expect(get('/bar')).to be_ok
expect(body).to eq('paths')
2011-09-04 21:13:27 -04:00
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
2016-05-10 10:08:54 -04:00
expect(count).to eq(4)
2011-09-04 21:13:27 -04:00
end
2012-12-09 11:35:15 -05:00
it 'supports multiple verbs' do
mock_app do
register Sinatra::MultiRoute
route('PUT', 'POST', '/') { 'verb' }
end
2016-05-10 10:08:54 -04:00
expect(post('/')).to be_ok
expect(body).to eq('verb')
expect(put('/')).to be_ok
expect(body).to eq('verb')
2011-09-04 21:13:27 -04:00
end
it 'takes symbols as verbs' do
mock_app do
register Sinatra::MultiRoute
route(:get, '/baz') { 'symbol as verb' }
end
2016-05-10 10:08:54 -04:00
expect(get('/baz')).to be_ok
expect(body).to eq('symbol as verb')
2011-09-04 21:13:27 -04:00
end
2012-12-09 11:35:15 -05:00
end