spec.request.js
This file
Path
spec/spec.request.js
215 lines · 7.2 KiB · JavaScript
Last changed by
Merge branch 'integration'visionmediabefore adoption406a7f4
History of this fileTake it
More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 1–5why, one step back12describe 'Express'3 before_each4 reset()5 endAdded specs for requests with content-type of "application/x-www-form-urlencoded"visionmediabefore adoption5a85db1
line 6why, one step back6 Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 7–12why, one step back7 describe 'Request'8 describe '#status()'9 it 'should set the response status'10 get('/user', function(){ this.status(500) })11 get('/user').status.should.eql 50012 endMore refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
line 13why, one step back13 endMerge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 14–39why, one step back1415 describe '#header()'16 describe 'when given a field name and value'17 it 'should set the header'18 get('/user', function(){19 this.header('x-foo', 'bar')20 })21 get('/user').headers.should.have_property 'x-foo', 'bar'22 end 23 end2425 describe 'when given a field name'26 it 'should return a request header value'27 get('/user', function(){28 return this.header('host')29 })30 get('/user').body.should.eql 'localhost'31 end3233 it 'should be case-insensitive'34 get('/user', function(){35 return this.header('Host')36 })37 get('/user').body.should.eql 'localhost'38 end39 endMore refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 40–41why, one step back40 end41 Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 42–52why, one step back42 describe '#accepts()'43 describe 'when the Accept header is present'44 it 'should return true if the mime type is acceptable'45 get('/user', function(){ return this.accepts('jpeg').toString() })46 get('/user', { headers: { accept: 'image/jpeg' }}).body.should.eql 'true'47 end48 49 it 'should return false if the mime type is not present'50 get('/user', function(){ return this.accepts('html').toString() })51 get('/user', { headers: { accept: 'image/jpeg' }}).body.should.eql 'false'52 endMore refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 53–54why, one step back53 end54 Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 55–59why, one step back55 describe 'when the Accept header is not present'56 it 'should return true'57 get('/user', function(){ return this.accepts('jpeg').toString() })58 get('/user', { headers: { accept: null }}).body.should.eql 'true'59 endMore refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
line 60why, one step back60 endMerge branch 'integration'visionmediabefore adoption406a7f4
lines 61–83why, one step back61 62 describe 'should allow multiple arguments'63 it 'should return true if any mime type is present'64 get('/user', function(){ return this.accepts('jpeg', 'png').toString() })65 get('/user', { headers: { accept: 'image/gif,image/png' }}).body.should.eql 'true'66 end67 68 it 'should return false if none of the mime types are present'69 get('/user', function(){ return this.accepts('jpeg', 'png').toString() })70 get('/user', { headers: { accept: 'text/plain,text/html' }}).body.should.eql 'false'71 end72 end73 74 describe 'when a media type range was sent'75 it 'should return true if the group media type matches'76 get('/user', function(){ return this.accepts('html').toString() })77 get('/user', { headers: { accept: 'text/plain,text/*' }}).body.should.eql 'true'78 end79 it 'should return false if the group media type does not match'80 get('/user', function(){ return this.accepts('ogg').toString() })81 get('/user', { headers: { accept: 'text/plain,text/*' }}).body.should.eql 'false'82 end83 endMore refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 84–85why, one step back84 end85 Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 86–92why, one step back86 describe '#halt()'87 describe 'when given no arguments'88 it 'should respond with 404 Not Found'89 get('/user', function(){ this.halt() })90 get('/user').status.should.eql 40491 get('/user').body.should.include('Not Found')92 endMore refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
line 93why, one step back93 endMerge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 94–100why, one step back9495 describe 'when given a status code'96 it 'should respond with that status and its associated default body'97 get('/user', function(){ this.halt(400) })98 get('/user').status.should.eql 40099 get('/user').body.should.include('Bad Request')100 endMore refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
line 101why, one step back101 endMerge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 102–112why, one step back102103 describe 'when given a status code and body'104 it 'should respond with the status and its body'105 get('/user', function(){ this.halt(400, 'Oh noes!') })106 get('/user').status.should.eql 400107 get('/user').body.should.include('Oh noes!')108 end109 end110111 describe 'when given an invalid status code'112 it 'should throw an InvalidStatusCode exception'Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption3f9cbbb
line 113why, one step back113 // TODO: use throw_error when fixed...Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 114–121why, one step back114 get('/user', function(){ this.halt(123123) })115 try { get('/user') }116 catch (e) {117 e.should.be_an_instance_of ExpressError118 e.should.be_an_instance_of InvalidStatusCode119 }120 end121 endMore refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
line 122why, one step back122 endMerge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 123–130why, one step back123124 describe '#contentType()'125 it 'should set Content-Type header with mime type passed'126 get('/style.css', function(){127 this.contentType('css')128 return 'body { background: white; }'129 })130 get('/style.css').headers['content-type'].should.eql 'text/css'More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 131–132why, one step back131 end132 endMerge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933
lines 133–141why, one step back133 134 describe '#attachment()'135 it 'should set Content-Disposition to attachment'136 get('/report', function(){137 this.attachment()138 return 'foo'139 })140 get('/report').headers['content-disposition'].should.eql 'attachment'141 endMerge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
line 142why, one step back142Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933
lines 143–151why, one step back143 it 'should set attachment filename'144 get('/report', function(){145 this.attachment('report.pdf')146 return 'foo'147 })148 get('/report').headers['content-disposition'].should.eql 'attachment; filename="report.pdf"'149 end150 end151Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 152–197why, one step back152 describe '#param()'153 it 'should return a route placeholder value'154 get('/user/:id', function(){155 return 'user ' + this.param('id')156 })157 get('/user/12').body.should.eql 'user 12'158 end159160 it 'should return several route placeholder values'161 get('/user/:id/:operation', function(){162 return this.param('operation') + 'ing user ' + this.param('id') 163 })164 get('/user/12/edit').body.should.eql 'editing user 12'165 end166167 it 'should allow optional placeholders'168 get('/user/:id?', function(){169 return this.param('id') ? 'user ' + this.param('id') : 'users'170 })171 get('/user/12').body.should.eql 'user 12'172 get('/user').body.should.eql 'users'173 end174175 it 'should allow placeholders as part of a segment'176 get('/report.:format', function(){177 return 'report as ' + this.param('format')178 })179 get('/report.csv').body.should.eql 'report as csv'180 get('/report.pdf').body.should.eql 'report as pdf'181 end182183 it 'should allow optional placeholders in middle segments'184 get('/user/:id?/edit', function(){185 return this.param('id') ? 'editing ' + this.param('id') : 'editing your account'186 })187 get('/user/12/edit').body.should.eql 'editing 12'188 get('/user/edit').body.should.eql 'editing your account'189 end190191 it 'should work with several routes'192 get('/user/:id', function(){ return this.param('id') })193 get('/product/:name', function(){ return this.param('name') })194 get('/user/12').body.should.eql '12'195 get('/product/ipod').body.should.eql 'ipod'196 end197Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933
line 198why, one step back198 it 'should work with a query string'Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
line 199why, one step back199 get('/user', function(){Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8
line 200why, one step back200 return String(this.param('page') || 'First page')Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 201–202why, one step back201 })202 get('/user').body.should.eql 'First page'Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoptione125ae2
line 203why, one step back203 get('/user?page=2').body.should.eql '2'Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933
line 204why, one step back204 get('/user?foo[]=bar&page=5').body.should.eql '5'Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 205–213why, one step back205 end206207 it 'should work with splats'208 get('/:path/*.*', function(path, file, ext){209 return [path, file, ext].join(', ')210 })211 get('/public/app.js').body.should.eql 'public, app, js'212 end213 end More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 214–215why, one step back214 end215end