Skip to content
Myr

spec.request.js

This file

Path

spec/spec.request.js

174 lines · 5.7 KiB · JavaScript

Last changed by

Added Request#attachment()visionmediabefore adoption29a14c9

History of this file

Take it

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

lines 1–5why, one step back
1
2describe 'Express'3 before_each4 reset()5 end

Added specs for requests with content-type of "application/x-www-form-urlencoded"visionmediabefore adoption5a85db1

line 6why, one step back
6

Misc spec refactoringvisionmediabefore adoption399e91d

line 7why, one step back
7 describe 'Request'

Misc spec refactoringvisionmediabefore adoptionbfb6cec

line 8why, one step back
8 describe '#status()'

Misc spec refactoringvisionmediabefore adoption399e91d

lines 9–12why, one step back
9 it 'should set the response status'
10 get('/user', function(){ this.status(500) })11 get('/user').status.should.eql 50012 end

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

line 13why, one step back
13 end

Misc spec refactoringvisionmediabefore adoption399e91d

line 14why, one step back
14

Misc spec refactoringvisionmediabefore adoptionbfb6cec

line 15why, one step back
15 describe '#header()'

Misc spec refactoringvisionmediabefore adoption399e91d

lines 16–40why, one step back
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 end40 end

Request#accepts() returns true when Accept is not presentvisionmediabefore adoptionbbd3d75

lines 41–61why, one step back
41
42 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 end53 end54 55 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 end60 end61 end

Added Request#attachment()visionmediabefore adoption29a14c9

line 62why, one step back
62

Misc spec refactoringvisionmediabefore adoptionbfb6cec

line 63why, one step back
63 describe '#halt()'

Misc spec refactoringvisionmediabefore adoption399e91d

lines 64–101why, one step back
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 end70 end7172 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 end78 end7980 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'90 // TODO: throw_error(InvalidStatusCode, ...) when jspec is fixed91 get('/user', function(){ this.halt(123123) })92 -{ get('/user') }.should.throw_error(/InvalidStatusCode: 123123 is an invalid HTTP response code/)93 try { get('/user') }94 catch (e) {95 e.should.be_an_instance_of ExpressError96 e.should.be_an_instance_of InvalidStatusCode97 }98 end99 end100 end101

Misc spec refactoringvisionmediabefore adoptionbfb6cec

line 102why, one step back
102 describe '#contentType()'

Misc spec refactoringvisionmediabefore adoption399e91d

lines 103–106why, one step back
103 it 'should set Content-Type header with mime type passed'
104 get('/style.css', function(){105 this.contentType('css')106 return 'body { background: white; }'

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

line 107why, one step back
107 })

Misc spec refactoringvisionmediabefore adoption399e91d

lines 108–109why, one step back
108 get('/style.css').headers['content-type'].should.eql 'text/css'
109 end

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

line 110why, one step back
110 end

Misc spec refactoringvisionmediabefore adoption399e91d

line 111why, one step back
111

Misc spec refactoringvisionmediabefore adoptionbfb6cec

line 112why, one step back
112 describe '#param()'

Misc spec refactoringvisionmediabefore adoption399e91d

lines 113–115why, one step back
113 it 'should return a route placeholder value'
114 get('/user/:id', function(){115 return 'user ' + this.param('id')

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

line 116why, one step back
116 })

Misc spec refactoringvisionmediabefore adoption399e91d

line 117why, one step back
117 get('/user/12').body.should.eql 'user 12'

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

line 118why, one step back
118 end

Misc spec refactoringvisionmediabefore adoption399e91d

lines 119–122why, one step back
119
120 it 'should return several route placeholder values'121 get('/user/:id/:operation', function(){122 return this.param('operation') + 'ing user ' + this.param('id')

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

line 123why, one step back
123 })

Misc spec refactoringvisionmediabefore adoption399e91d

line 124why, one step back
124 get('/user/12/edit').body.should.eql 'editing user 12'

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

line 125why, one step back
125 end

Misc spec refactoringvisionmediabefore adoption399e91d

lines 126–132why, one step back
126
127 it 'should allow optional placeholders'128 get('/user/:id?', function(){129 return this.param('id') ? 'user ' + this.param('id') : 'users'130 })131 get('/user/12').body.should.eql 'user 12'132 get('/user').body.should.eql 'users'

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

line 133why, one step back
133 end

Misc spec refactoringvisionmediabefore adoption399e91d

lines 134–140why, one step back
134
135 it 'should allow placeholders as part of a segment'136 get('/report.:format', function(){137 return 'report as ' + this.param('format')138 })139 get('/report.csv').body.should.eql 'report as csv'140 get('/report.pdf').body.should.eql 'report as pdf'

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

line 141why, one step back
141 end

Misc spec refactoringvisionmediabefore adoption399e91d

lines 142–148why, one step back
142
143 it 'should allow optional placeholders in middle segments'144 get('/user/:id?/edit', function(){145 return this.param('id') ? 'editing ' + this.param('id') : 'editing your account'146 })147 get('/user/12/edit').body.should.eql 'editing 12'148 get('/user/edit').body.should.eql 'editing your account'

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

line 149why, one step back
149 end

Misc spec refactoringvisionmediabefore adoption399e91d

lines 150–155why, one step back
150
151 it 'should work with several routes'152 get('/user/:id', function(){ return this.param('id') })153 get('/product/:name', function(){ return this.param('name') })154 get('/user/12').body.should.eql '12'155 get('/product/ipod').body.should.eql 'ipod'

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

line 156why, one step back
156 end

Misc spec refactoringvisionmediabefore adoption399e91d

lines 157–172why, one step back
157
158 it 'should access request.uri.params'159 get('/user', function(){160 return this.param('page') || 'First page'161 })162 get('/user').body.should.eql 'First page'163 get('/user', { uri: { params: { page: '2' }}}).body.should.eql '2'164 end165166 it 'should work with splats'167 get('/:path/*.*', function(path, file, ext){168 return [path, file, ext].join(', ')169 })170 get('/public/app.js').body.should.eql 'public, app, js'171 end172 end

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

lines 173–174why, one step back
173 end
174end