Skip to content
Myr

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 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

Fixing specs due to Request changevisionmediabefore adoption2d3d6da

line 6why, one step back
6

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

lines 7–8why, one step back
7 describe 'status()'
8 it 'should set the response status'

Fixing specs due to Request changevisionmediabefore adoption2d3d6da

line 9why, one step back
9 get('/user', function(){ this.status(500) })

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

lines 10–17why, one step back
10 get('/user').status.should.eql 500
11 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 back
18 this.header('x-foo', 'bar')

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

lines 19–26why, one step back
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(){

Fixing specs due to Request changevisionmediabefore adoption2d3d6da

line 27why, one step back
27 return this.header('host')

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

lines 28–33why, one step back
28 })
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 back
34 return this.header('Host')

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

lines 35–43why, one step back
35 })
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 back
44 get('/user', function(){ this.halt() })

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

lines 45–51why, one step back
45 get('/user').status.should.eql 404
46 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 back
52   get('/user', function(){ this.halt(400) })

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

lines 53–59why, one step back
53   get('/user').status.should.eql 400
54   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 back
60 get('/user', function(){ this.halt(400, 'Oh noes!') })

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

lines 61–68why, one step back
61 get('/user').status.should.eql 400
62 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 fixed

Fixing specs due to Request changevisionmediabefore adoption2d3d6da

line 69why, one step back
69 get('/user', function(){ this.halt(123123) })

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

lines 70–82why, one step back
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 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 back
83 this.contentType('css')

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

lines 84–92why, one step back
84 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 back
93 return 'user ' + this.param('id')

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

lines 94–99why, one step back
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(){

Fixing specs due to Request changevisionmediabefore adoption2d3d6da

line 100why, one step back
100 return this.param('operation') + 'ing user ' + this.param('id')

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

lines 101–106why, one step back
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(){

Fixing specs due to Request changevisionmediabefore adoption2d3d6da

line 107why, one step back
107 return this.param('id') ? 'user ' + this.param('id') : 'users'

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

lines 108–114why, one step back
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(){

Fixing specs due to Request changevisionmediabefore adoption2d3d6da

line 115why, one step back
115 return 'report as ' + this.param('format')

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

lines 116–122why, one step back
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(){

Fixing specs due to Request changevisionmediabefore adoption2d3d6da

line 123why, one step back
123 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 back
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'

Fixing specs due to Request changevisionmediabefore adoption2d3d6da

lines 130–131why, one step back
130 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 back
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(){

Fixing specs due to Request changevisionmediabefore adoption2d3d6da

line 138why, one step back
138 return this.param('page') || 'First page'

More refactoring to allow everything to be request-specificvisionmediabefore adoption34c412e

lines 139–144why, one step back
139 })
140 get('/user').body.should.eql 'First page'141 get('/user', { uri: { params: { page: '2' }}}).body.should.eql '2'142 end143 end144end