spec.request.js
This file
Path
spec/spec.request.js
192 lines · 6.1 KiB · JavaScript
Last changed by
Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8
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
lines 60–62why, one step back60 end61 end62 Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 63–69why, one step back63 describe '#halt()'64 describe 'when given no arguments'65 it 'should respond with 404 Not Found'66 get('/user', function(){ this.halt() })67 get('/user').status.should.eql 40468 get('/user').body.should.include('Not Found')69 endMore refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
line 70why, one step back70 endMerge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 71–77why, one step back7172 describe 'when given a status code'73 it 'should respond with that status and its associated default body'74 get('/user', function(){ this.halt(400) })75 get('/user').status.should.eql 40076 get('/user').body.should.include('Bad Request')77 endMore refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
line 78why, one step back78 endMerge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 79–89why, one step back7980 describe 'when given a status code and body'81 it 'should respond with the status and its body'82 get('/user', function(){ this.halt(400, 'Oh noes!') })83 get('/user').status.should.eql 40084 get('/user').body.should.include('Oh noes!')85 end86 end8788 describe 'when given an invalid status code'89 it 'should throw an InvalidStatusCode exception'Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption3f9cbbb
line 90why, one step back90 // TODO: use throw_error when fixed...Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 91–98why, one step back91 get('/user', function(){ this.halt(123123) })92 try { get('/user') }93 catch (e) {94 e.should.be_an_instance_of ExpressError95 e.should.be_an_instance_of InvalidStatusCode96 }97 end98 endMore refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
line 99why, one step back99 endMerge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 100–107why, one step back100101 describe '#contentType()'102 it 'should set Content-Type header with mime type passed'103 get('/style.css', function(){104 this.contentType('css')105 return 'body { background: white; }'106 })107 get('/style.css').headers['content-type'].should.eql 'text/css'More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 108–109why, one step back108 end109 endMerge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933
lines 110–118why, one step back110 111 describe '#attachment()'112 it 'should set Content-Disposition to attachment'113 get('/report', function(){114 this.attachment()115 return 'foo'116 })117 get('/report').headers['content-disposition'].should.eql 'attachment'118 endMerge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
line 119why, one step back119Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933
lines 120–128why, one step back120 it 'should set attachment filename'121 get('/report', function(){122 this.attachment('report.pdf')123 return 'foo'124 })125 get('/report').headers['content-disposition'].should.eql 'attachment; filename="report.pdf"'126 end127 end128Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 129–174why, one step back129 describe '#param()'130 it 'should return a route placeholder value'131 get('/user/:id', function(){132 return 'user ' + this.param('id')133 })134 get('/user/12').body.should.eql 'user 12'135 end136137 it 'should return several route placeholder values'138 get('/user/:id/:operation', function(){139 return this.param('operation') + 'ing user ' + this.param('id') 140 })141 get('/user/12/edit').body.should.eql 'editing user 12'142 end143144 it 'should allow optional placeholders'145 get('/user/:id?', function(){146 return this.param('id') ? 'user ' + this.param('id') : 'users'147 })148 get('/user/12').body.should.eql 'user 12'149 get('/user').body.should.eql 'users'150 end151152 it 'should allow placeholders as part of a segment'153 get('/report.:format', function(){154 return 'report as ' + this.param('format')155 })156 get('/report.csv').body.should.eql 'report as csv'157 get('/report.pdf').body.should.eql 'report as pdf'158 end159160 it 'should allow optional placeholders in middle segments'161 get('/user/:id?/edit', function(){162 return this.param('id') ? 'editing ' + this.param('id') : 'editing your account'163 })164 get('/user/12/edit').body.should.eql 'editing 12'165 get('/user/edit').body.should.eql 'editing your account'166 end167168 it 'should work with several routes'169 get('/user/:id', function(){ return this.param('id') })170 get('/product/:name', function(){ return this.param('name') })171 get('/user/12').body.should.eql '12'172 get('/product/ipod').body.should.eql 'ipod'173 end174Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933
line 175why, one step back175 it 'should work with a query string'Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
line 176why, one step back176 get('/user', function(){Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8
line 177why, one step back177 return String(this.param('page') || 'First page')Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 178–179why, one step back178 })179 get('/user').body.should.eql 'First page'Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoptione125ae2
line 180why, one step back180 get('/user?page=2').body.should.eql '2'Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933
line 181why, one step back181 get('/user?foo[]=bar&page=5').body.should.eql '5'Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption99e3130
lines 182–190why, one step back182 end183184 it 'should work with splats'185 get('/:path/*.*', function(path, file, ext){186 return [path, file, ext].join(', ')187 })188 get('/public/app.js').body.should.eql 'public, app, js'189 end190 end More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 191–192why, one step back191 end192end