spec.routing.js
This file
Path
spec/spec.routing.js
235 lines · 6.6 KiB · JavaScript
Last changed by
Added "helpful 404" support pagevisionmediabefore adoption897c590
History of this fileTake it
Renaming some spec filesvisionmediabefore adoption340cd1d
lines 1–95why, one step back12describe 'Express'3 before_each4 reset()5 end6 7 describe 'route'8 describe 'with callback function'9 it 'should respond with a body string'10 get('/user', function(){11 return 'test'12 })13 get('/user').body.should.eql 'test'14 end15 end16 17 describe 'with options and callback function'18 it 'should respond with a body string'19 get('/user', {}, function(){20 return 'test with options'21 })22 get('/user').body.should.eql 'test with options'23 end24 end25 26 describe 'with a trailing slash in request path'27 it 'should still match'28 get('/user', {}, function(){29 return 'test with options'30 })31 get('/user/').body.should.eql 'test with options'32 end33 end34 35 describe 'with a trailing slash in route path'36 it 'should still match'37 get('/user/', {}, function(){38 return 'test with options'39 })40 get('/user').body.should.eql 'test with options'41 end42 end43 44 describe 'with a trailing whitespace in request path'45 it 'should still match'46 get('/user', {}, function(){47 return 'test with options'48 })49 get('/user/ ').body.should.eql 'test with options'50 end51 end52 53 describe 'with a trailing whitespace in route path'54 it 'should still match'55 get('/user/ ', {}, function(){56 return 'test with options'57 })58 get('/user').body.should.eql 'test with options'59 end60 end61 62 describe 'with several similar routes'63 it 'should match them properly'64 get('/foo', function(){65 return 'bar'66 })67 get('/foos', function(){68 return 'baz'69 })70 get('/foo').body.should.eql 'bar'71 get('/foos').body.should.eql 'baz'72 end73 end74 75 describe 'with several identical routes'76 it 'should match the first route'77 get('/foo', function(){78 return 'bar'79 })80 get('/foo', function(){81 return 'baz'82 })83 get('/foo').body.should.eql 'bar'84 end85 end86 87 describe 'with no response body'88 it 'should throw a InvalidResponseBody'89 get('/user', function(){90 Express.server.respond()91 })92 -{ get('/user') }.should.throw_error(/InvalidResponseBody: get "\/user" did not respond with a body string/)93 end94 end95 Added failing regression specs for route param segmentsvisionmediabefore adoption04c0645
lines 96–105why, one step back96 describe 'with a placeholder'97 it 'should still match'98 get('/user/:id', function(){ return 'yay' })99 get('/user/12').body.should.eql 'yay'100 end101 102 it 'should not match with an additional path segment'103 get('/user/:id', function(){ return 'yay' })104 get('/user/12/edit').body.should.eql 'Not Found'105 endAdded param passing specsvisionmediabefore adoptionaf0493b
lines 106–112why, one step back106 107 it 'should pass it to the route function'108 get('/user/:id', function(id){109 return id110 })111 get('/user/12').body.should.eql '12'112 endAdded failing regression specs for route param segmentsvisionmediabefore adoption04c0645
lines 113–119why, one step back113 end114 115 describe 'with several placeholders'116 it 'should still match'117 get('/user/:id/:op', function(){ return 'yay' })118 get('/user/12/edit').body.should.eql 'yay'119 endAdded param passing specsvisionmediabefore adoptionaf0493b
lines 120–126why, one step back120 121 it 'should pass them to the route function'122 get('/user/:id/:op', function(id, op){123 return op + 'ing user ' + id124 })125 get('/user/12/edit').body.should.eql 'editing user 12'126 endAdded failing regression specs for route param segmentsvisionmediabefore adoption04c0645
lines 127–134why, one step back127 end128 129 describe 'with an optional placeholder'130 it 'should match with a value'131 get('/user/:id?', function(){ return 'yay' })132 get('/user/1').body.should.eql 'yay'133 end134 Added param passing specsvisionmediabefore adoptionaf0493b
lines 135–142why, one step back135 it 'should pass it to the route function'136 get('/user/:id?', function(id){137 return id || 'You'138 })139 get('/user/12').body.should.eql '12'140 get('/user').body.should.eql 'You'141 end142 Added failing regression specs for route param segmentsvisionmediabefore adoption04c0645
lines 143–150why, one step back143 it 'should match without a value'144 get('/user/:id?', function(){ return 'yay' })145 get('/user').body.should.eql 'yay'146 end147 148 it 'should not match with an additional path segment'149 get('/user/:id?', function(){ return 'yay' })150 get('/user/12/edit').body.should.eql 'Not Found'Added param passing specsvisionmediabefore adoptionaf0493b
lines 151–167why, one step back151 end152 end153 154 describe 'with partial placeholder'155 it 'should still match'156 get('/report.:format', function(){157 return 'yay'158 })159 get('/report.csv').body.should.eql 'yay'160 get('/report.pdf').body.should.eql 'yay'161 end162 163 it 'should not match without value'164 get('/report.:format', function(){165 return 'yay'166 })167 get('/report.').body.should.eql 'Not Found'Added failing regression specs for route param segmentsvisionmediabefore adoption04c0645
lines 168–170why, one step back168 end169 end170 Renaming some spec filesvisionmediabefore adoption340cd1d
line 171why, one step back171 describe 'with an unmatchable request path'Started "helpful 404" supportvisionmediabefore adoption6642c4c
lines 172–174why, one step back172 describe 'with "helpful 404" enabled'173 it 'should show the help html'174 enable('helpful 404')Added "helpful 404" support pagevisionmediabefore adoption897c590
line 175why, one step back175 get('/something').status.should.eql 404Started "helpful 404" supportvisionmediabefore adoption6642c4c
lines 176–185why, one step back176 get('/something').body.should.include('<h1>Express</h1>')177 get('/something').body.should.include('<h2><em>404</em> Not Found</h2>')178 end179 end180 181 describe 'with "helpful 404" disabled'182 it 'should respond with 404 Not Found'183 get('/something').status.should.eql 404184 get('/something').body.should.eql 'Not Found'185 endRenaming some spec filesvisionmediabefore adoption340cd1d
lines 186–188why, one step back186 end187 end188 Added "show exceptions" setting and specsvisionmediabefore adoptiondad297e
lines 189–202why, one step back189 describe 'with an exception thrown'190 describe 'with "show exceptions" enabled'191 it 'should show the exception html'192 enable('show exceptions')193 get('/user', function(){194 throw new Error('Access Denied')195 })196 get('/user').status.should.eql 500197 get('/user').body.should.include('<h1>Express</h1>')198 get('/user').body.should.include('<h2><em>500</em> Error: Access Denied</h2>')199 end200 end201 202 describe 'with "show exceptions" disabled'Added "throw exceptions" optionsvisionmediabefore adoptionb505c96
line 203why, one step back203 disable('show exceptions')Added "show exceptions" setting and specsvisionmediabefore adoptiondad297e
lines 204–209why, one step back204 it 'should show the regular body'205 get('/user', function(){206 throw new Error('Access Denied')207 })208 get('/user').status.should.eql 500209 get('/user').body.should.include('Internal Server Error')Added "throw exceptions" optionsvisionmediabefore adoptionb505c96
lines 210–229why, one step back210 end211 end212 213 describe 'with "throw exceptions" enabled'214 it 'should propegate to the global scope'215 enable('throw exceptions')216 get('/user', function(){217 throw new Error('Access Denied')218 })219 -{ get('/user') }.should.throw_error220 end221 end222 223 describe 'with "throw exceptions" disabled'224 it 'should not propegate to the global scope'225 disable('throw exceptions')226 get('/user', function(){227 throw new Error('Access Denied')228 })229 -{ get('/user') }.should.not.throw_errorAdded "show exceptions" setting and specsvisionmediabefore adoptiondad297e
lines 230–233why, one step back230 end231 end232 end233 Renaming some spec filesvisionmediabefore adoption340cd1d
lines 234–235why, one step back234 end235end