Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor multi-route specs

This makes the relationship between the setup and the spec explicit,
clarifying which bit of setup is actually being tested.
  • Loading branch information...
commit 5a1d45e55dd6db3108cb7528d61ea2b246b9c57f 1 parent 204713d
@kytrinyx kytrinyx authored
Showing with 25 additions and 10 deletions.
  1. +25 −10 spec/multi_route_spec.rb
View
35 spec/multi_route_spec.rb
@@ -2,25 +2,23 @@
require_relative 'spec_helper'
describe Sinatra::MultiRoute do
- before do
- count = 0
+
+ it 'does not break normal routing' do
mock_app do
- set(:some_condition) { |_| count += 1 }
register Sinatra::MultiRoute
get('/') { 'normal' }
- get('/foo', '/bar', :some_condition => true) { 'paths' }
- route('PUT', 'POST', '/') { 'verb' }
- route(:get, '/baz') { 'symbol as verb' }
end
- @count = count
- end
- it 'does still allow normal routing' do
get('/').should be_ok
body.should be == 'normal'
end
it 'supports multiple routes' do
+ mock_app do
+ register Sinatra::MultiRoute
+ get('/foo', '/bar') { 'paths' }
+ end
+
get('/foo').should be_ok
body.should be == 'paths'
get('/bar').should be_ok
@@ -28,10 +26,22 @@
end
it 'triggers conditions' do
- @count.should be == 4
+ 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
end
it 'supports multiple verbs' do
+ mock_app do
+ register Sinatra::MultiRoute
+ route('PUT', 'POST', '/') { 'verb' }
+ end
+
post('/').should be_ok
body.should be == 'verb'
put('/').should be_ok
@@ -39,6 +49,11 @@
end
it 'takes symbols as verbs' do
+ mock_app do
+ register Sinatra::MultiRoute
+ route(:get, '/baz') { 'symbol as verb' }
+ end
+
get('/baz').should be_ok
body.should be == 'symbol as verb'
end
Please sign in to comment.
Something went wrong with that request. Please try again.