Skip to content
Myr

Fixing specs due to Request change

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by visionmedia · committed by visionmedia · parent 271e982 · Browse files · 5 files+29 added−95 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+29 added−95 removed

  • tests:+20 added−86 removed
  • other:+9 added−9 removed

5 files+29 added−95 removed

modified:lib/express/exceptions.js-9 removed
modified:lib/express/request.js+9 added
52 unmodified lines
53 this.message = status + ' is an invalid HTTP response code'54 }55})5657// --- InvalidResponseBody5859InvalidResponseBody = ExpressError.extend({60 name: 'InvalidResponseBody',61 init: function(request) {62 this.message = request.method + ' ' + JSON.encode(request.uri.path) + ' did not respond with a body string'63 }64})6566// --- Helpers6768/**69 * Normalize the given _path_.
175 unmodified lines
modified:spec/spec.node.js+1 added
modified:spec/spec.request.js+18 added-85 removed
1 unmodified line
2describe 'Express'3 before_each4 reset()5 end6 7 describe 'parseParams()'8 it 'should parse simple query string key / value pairs'9 parseParams('foo=bar').should.eql { foo: 'bar' }10 parseParams('foo=bar&baz=1').should.eql { foo: 'bar', baz: '1' }11 end12 13 it 'should parse named nested params'14 var user = { user: { name: 'tj', email: 'tj@vision-media.ca' }}15 parseParams('user[name]=tj&user[email]=tj@vision-media.ca').should.eql user16 end17 18 it 'should parse several levels of nesting'19 var user = { user: { name: 'tj', email: { primary: 'tj@vision-media.ca' }}}20 parseParams('user[name]=tj&user[email][primary]=tj@vision-media.ca').should.eql user21 end22 23 it 'should convert + to literal space'24 parseParams('foo=bar+baz++that').should.eql { foo: 'bar baz that' }25 parseParams('user[name]=tj+holowaychuk').should.eql { user: { name: 'tj holowaychuk' }}26 end27 28 it 'should decode hex literals'29 parseParams('foo=bar%20baz%20%20that').should.eql { foo: 'bar baz that' }30 parseParams('user[name]=tj%20holowaychuk').should.eql { user: { name: 'tj holowaychuk' }}31 end32 end33 34 describe 'toArray()'35 describe 'when given an array'36 it 'should return the array'37 toArray([1,2,3]).should.eql [1,2,3]38 end39 end40 41 describe 'when given an object with indexed values and length'42 it 'should return an array'43 var args = -{ return arguments }('foo', 'bar')44 toArray(args).should.eql ['foo', 'bar']45 end46 end47 end48 49 describe 'escape()'50 it 'should escape html'51 escape('<p>this & that').should.eql '&lt;p&gt;this &amp; that'52 end53 end54 55 describe 'extname()'56 it 'should return the a files extension'57 extname('image.png').should.eql 'png'58 extname('image.large.png').should.eql 'png'59 extname('/path/to/image.large.png').should.eql 'png'60 end61 62 it 'should return null when not found'63 extname('path').should.be_null64 extname('/just/a/path').should.be_null65 end66 end67 68 describe 'dirname()'69 it 'should return the directory path'70 dirname('/path/to/images/foo.bar.png').should.eql '/path/to/images'71 end72 end73 67 describe 'status()'8 it 'should set the response status'76 get('/user', function(){ status(500) })9 get('/user', function(){ this.status(500) })10 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(){85 header('x-foo', 'bar')18 this.header('x-foo', 'bar')19 })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(){94 return header('host')27 return this.header('host')28 })29 get('/user').body.should.eql 'localhost'30 end31 32 it 'should be case-insensitive'33 get('/user', function(){101 return header('Host')34 return this.header('Host')35 })36 get('/user').body.should.eql 'localhost'37 end38 end
1 unmodified line
40 41 describe 'halt()'42 describe 'when given no arguments'43 it 'should respond with 404 Not Found'111 get('/user', function(){ halt() })44 get('/user', function(){ this.halt() })45 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'119   get('/user', function(){ halt(400) })52   get('/user', function(){ this.halt(400) })53   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'127 get('/user', function(){ halt(400, 'Oh noes!') })60 get('/user', function(){ this.halt(400, 'Oh noes!') })61 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 fixed136 get('/user', function(){ halt(123123) })69 get('/user', function(){ this.halt(123123) })70 -{ 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 ExpressError
5 unmodified lines
79 80 describe 'contentType()'81 it 'should set Content-Type header with mime type passed'82 get('/style.css', function(){150 contentType('css')83 this.contentType('css')84 return 'body { background: white; }'85 })86 get('/style.css').headers['content-type'].should.eql 'text/css'87 end
1 unmodified line
89 90 describe 'param()'91 it 'should return a route placeholder value'92 get('/user/:id', function(){160 return 'user ' + param('id')93 return 'user ' + this.param('id')94 })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(){167 return param('operation') + 'ing user ' + param('id') 100 return this.param('operation') + 'ing user ' + this.param('id') 101 })102 get('/user/12/edit').body.should.eql 'editing user 12'103 end104 105 it 'should allow optional placeholders'106 get('/user/:id?', function(){174 return param('id') ? 'user ' + param('id') : 'users'107 return this.param('id') ? 'user ' + this.param('id') : 'users'108 })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(){182 return 'report as ' + param('format')115 return 'report as ' + this.param('format')116 })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(){190 return param('id') ? 'editing ' + param('id') : 'editing your account'123 return this.param('id') ? 'editing ' + this.param('id') : 'editing your account'124 })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'197 get('/user/:id', function(){ return param('id') })198 get('/product/:name', function(){ return param('name') })130 get('/user/:id', function(){ return this.param('id') })131 get('/product/:name', function(){ return this.param('name') })132 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(){205 return param('page') || 'First page'138 return this.param('page') || 'First page'139 })140 get('/user').body.should.eql 'First page'141 get('/user', { uri: { params: { page: '2' }}}).body.should.eql '2'142 end
2 unmodified lines
modified:spec/spec.routing.js+1 added-1 removed
85 unmodified lines
86 87 describe 'with no response body'88 it 'should throw a InvalidResponseBody'89 get('/user', function(){90 Express.server.respond()90 this.respond()91 })92 -{ get('/user') }.should.throw_error(/InvalidResponseBody: get "\/user" did not respond with a body string/)93 end94 end
141 unmodified lines