spec.request.js
This file
Path
spec/spec.request.js
144 lines · 4.4 KiB · JavaScript
Last changed by
Fixing specs due to Request changevisionmediabefore adoption2d3d6da
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 endFixing specs due to Request changevisionmediabefore adoption2d3d6da
line 6why, one step back6More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 7–8why, one step back7 describe 'status()'8 it 'should set the response status'Fixing specs due to Request changevisionmediabefore adoption2d3d6da
line 9why, one step back9 get('/user', function(){ this.status(500) })More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 10–17why, one step back10 get('/user').status.should.eql 50011 end12 end13 14 describe 'header()'15 describe 'when given a field name and value'16 it 'should set the header'17 get('/user', function(){Fixing specs due to Request changevisionmediabefore adoption2d3d6da
line 18why, one step back18 this.header('x-foo', 'bar')More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 19–26why, one step back19 })20 get('/user').headers.should.have_property 'x-foo', 'bar'21 end 22 end23 24 describe 'when given a field name'25 it 'should return a request header value'26 get('/user', function(){Fixing specs due to Request changevisionmediabefore adoption2d3d6da
line 27why, one step back27 return this.header('host')More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 28–33why, one step back28 })29 get('/user').body.should.eql 'localhost'30 end31 32 it 'should be case-insensitive'33 get('/user', function(){Fixing specs due to Request changevisionmediabefore adoption2d3d6da
line 34why, one step back34 return this.header('Host')More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 35–43why, one step back35 })36 get('/user').body.should.eql 'localhost'37 end38 end39 end40 41 describe 'halt()'42 describe 'when given no arguments'43 it 'should respond with 404 Not Found'Fixing specs due to Request changevisionmediabefore adoption2d3d6da
line 44why, one step back44 get('/user', function(){ this.halt() })More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 45–51why, one step back45 get('/user').status.should.eql 40446 get('/user').body.should.include('Not Found')47 end48 end49 50 describe 'when given a status code'51 it 'should respond with that status and its associated default body'Fixing specs due to Request changevisionmediabefore adoption2d3d6da
line 52why, one step back52 get('/user', function(){ this.halt(400) })More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 53–59why, one step back53 get('/user').status.should.eql 40054 get('/user').body.should.include('Bad Request')55 end56 end57 58 describe 'when given a status code and body'59 it 'should respond with the status and its body'Fixing specs due to Request changevisionmediabefore adoption2d3d6da
line 60why, one step back60 get('/user', function(){ this.halt(400, 'Oh noes!') })More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 61–68why, one step back61 get('/user').status.should.eql 40062 get('/user').body.should.include('Oh noes!')63 end64 end65 66 describe 'when given an invalid status code'67 it 'should throw an InvalidStatusCode exception'68 // TODO: throw_error(InvalidStatusCode, ...) when jspec is fixedFixing specs due to Request changevisionmediabefore adoption2d3d6da
line 69why, one step back69 get('/user', function(){ this.halt(123123) })More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 70–82why, one step back70 -{ get('/user') }.should.throw_error(/InvalidStatusCode: 123123 is an invalid HTTP response code/)71 try { get('/user') }72 catch (e) {73 e.should.be_an_instance_of ExpressError74 e.should.be_an_instance_of InvalidStatusCode75 }76 end77 end78 end79 80 describe 'contentType()'81 it 'should set Content-Type header with mime type passed'82 get('/style.css', function(){Fixing specs due to Request changevisionmediabefore adoption2d3d6da
line 83why, one step back83 this.contentType('css')More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 84–92why, one step back84 return 'body { background: white; }'85 })86 get('/style.css').headers['content-type'].should.eql 'text/css'87 end88 end89 90 describe 'param()'91 it 'should return a route placeholder value'92 get('/user/:id', function(){Fixing specs due to Request changevisionmediabefore adoption2d3d6da
line 93why, one step back93 return 'user ' + this.param('id')More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 94–99why, one step back94 })95 get('/user/12').body.should.eql 'user 12'96 end97 98 it 'should return several route placeholder values'99 get('/user/:id/:operation', function(){Fixing specs due to Request changevisionmediabefore adoption2d3d6da
line 100why, one step back100 return this.param('operation') + 'ing user ' + this.param('id') More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 101–106why, one step back101 })102 get('/user/12/edit').body.should.eql 'editing user 12'103 end104 105 it 'should allow optional placeholders'106 get('/user/:id?', function(){Fixing specs due to Request changevisionmediabefore adoption2d3d6da
line 107why, one step back107 return this.param('id') ? 'user ' + this.param('id') : 'users'More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 108–114why, one step back108 })109 get('/user/12').body.should.eql 'user 12'110 get('/user').body.should.eql 'users'111 end112 113 it 'should allow placeholders as part of a segment'114 get('/report.:format', function(){Fixing specs due to Request changevisionmediabefore adoption2d3d6da
line 115why, one step back115 return 'report as ' + this.param('format')More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 116–122why, one step back116 })117 get('/report.csv').body.should.eql 'report as csv'118 get('/report.pdf').body.should.eql 'report as pdf'119 end120 121 it 'should allow optional placeholders in middle segments'122 get('/user/:id?/edit', function(){Fixing specs due to Request changevisionmediabefore adoption2d3d6da
line 123why, one step back123 return this.param('id') ? 'editing ' + this.param('id') : 'editing your account'More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 124–129why, one step back124 })125 get('/user/12/edit').body.should.eql 'editing 12'126 get('/user/edit').body.should.eql 'editing your account'127 end128 129 it 'should work with several routes'Fixing specs due to Request changevisionmediabefore adoption2d3d6da
lines 130–131why, one step back130 get('/user/:id', function(){ return this.param('id') })131 get('/product/:name', function(){ return this.param('name') })More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 132–137why, one step back132 get('/user/12').body.should.eql '12'133 get('/product/ipod').body.should.eql 'ipod'134 end135 136 it 'should access request.uri.params'137 get('/user', function(){Fixing specs due to Request changevisionmediabefore adoption2d3d6da
line 138why, one step back138 return this.param('page') || 'First page'More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e
lines 139–144why, one step back139 })140 get('/user').body.should.eql 'First page'141 get('/user', { uri: { params: { page: '2' }}}).body.should.eql '2'142 end143 end144end