Skip to content
Myr

spec.core.js

This file

Path

spec/spec.core.js

165 lines · 4.9 KiB · JavaScript

Last changed by

Mock request specvisionmediabefore adoption9cc5593

History of this file

Take it

Initial commitvisionmediabefore adoption9998490

lines 1–2
1
2describe 'Express'

Added redirect(home) and settings.basepath [#8]visionmediabefore adoption8e523c6

lines 3–6why, one step back
3 before_each
4 Express.routes = []5 end6

Setting up specsvisionmediabefore adoption0d81d0b

lines 7–11why, one step back
7 describe '.version'
8 it 'should be properly formatted'9 Express.version.should.match /\d+\.\d+\.\d+/10 end11 end

Added spec for Express.contentsOf()visionmediabefore adoptionafde985

line 12why, one step back
12

Added POST urlencoded body parsingvisionmediabefore adoption7807f42

lines 13–23why, one step back
13 describe '.parseParams()'
14 it 'should parse a string of parameters'15 string = 'user[name]=tj&user[pass]=test&foo=some bar stuff&cookies=awesome'16 params = Express.parseParams(string)17 params.user.name.should.eql 'tj'18 params.user.pass.should.eql 'test'19 params.foo.should.eql 'some bar stuff'20 params.cookies.should.eql 'awesome'21 end22 end23

Added spec for parseNestedParams()visionmediabefore adoption7be9f44

lines 24–25why, one step back
24 describe '.parseNestedParams()'
25 it 'should parse nested params hash provided by node'

Started parseNestedParams()visionmediabefore adoptione7f11d5

line 26why, one step back
26 params = { 'foo' : 'bar', 'user[name]' : 'tj', 'user[info][email]' : 'tj@vision-media.ca', 'user[info][city]' : 'Victoria' }

Fixed specsvisionmediabefore adoptiona989232

lines 27–31why, one step back
27 nested = Express.parseNestedParams(params)
28 nested.foo.should.eql 'bar'29 nested.user.name.should.eql 'tj'30 nested.user.info.email.should.eql 'tj@vision-media.ca'31 nested.user.info.city.should.eql 'Victoria'

Added spec for parseNestedParams()visionmediabefore adoption7be9f44

lines 32–34why, one step back
32 end
33 end34

Added parseCookie()visionmediabefore adoption5be8088

line 35why, one step back
35 describe '.parseCookie()'

Miscvisionmediabefore adoption6d0bf20

line 36why, one step back
36 it 'should parse cookie pairs'

Misc module progressvisionmediabefore adoption15839de

line 37why, one step back
37 var cookie = 'expires=Fri, 31-Dec-2010 23:59:59 GMT; path=/; q=foo%3dbar; domain=example.net'

unescaping cookie valuesvisionmediabefore adoption9532e7f

lines 38–42why, one step back
38 parts = Express.parseCookie(cookie)
39 parts.expires.should.eql 'Fri, 31-Dec-2010 23:59:59 GMT'40 parts.path.should.eql '/'41 parts.q.should.eql 'foo=bar'42 parts.domain.should.eql 'example.net'

Added parseCookie()visionmediabefore adoption5be8088

lines 43–45why, one step back
43 end
44 end45

Added argsArray()visionmediabefore adoption4a0706f

lines 46–55why, one step back
46 describe '.argsArray()'
47 it 'should return an array of arguments'48 Express.argsArray(-{ return arguments }('foo', 'bar')).should.eql ['foo', 'bar']49 end50 51 it 'should allow an offset'52 Express.argsArray(-{ return arguments }('foo', 'bar'), 1).should.eql ['bar']53 end54 end55

Added escape()visionmediabefore adoptione4350c6

lines 56–61why, one step back
56 describe '.escape()'
57 it 'should escape html'58 Express.escape('<>&""').should.eql '&lt;&gt;&amp;&quot;&quot;'59 end60 end61

Added escapeRegexp()visionmediabefore adoption24bca5d

lines 62–65why, one step back
62 describe '.escapeRegexp()'
63 it 'should escape regexp special characters'64 Express.escapeRegexp('/users/(name)').should.eql '\\/users\\/\\(name\\)'65 end

Added chars param to escapeRegexp()visionmediabefore adoption46a0892

lines 66–69why, one step back
66
67 it 'should accept a string of space-delimited characters'68 Express.escapeRegexp('/foo/#bar?user[name]=tj', '/ [ ]').should.eql '\\/foo\\/#bar?user\\[name\\]=tj'69 end

Added escapeRegexp()visionmediabefore adoption24bca5d

lines 70–71why, one step back
70 end
71

Added spec for Express.contentsOf()visionmediabefore adoptionafde985

lines 72–76why, one step back
72 describe '.contentsOf()'
73 it 'should return the body of a function as a string'74 Express.contentsOf(function(){ return 'foo' }).should.include 'return', 'foo'75 end76 end

Added Express.header()visionmediabefore adoption3b3be54

lines 77–81why, one step back
77
78 describe '.header()'79 it 'should set / get headers'80 Express.header('Content-Type', 'text/html')81 Express.header('Content-Type').should.eql 'text/html'

Added POST urlencoded body parsingvisionmediabefore adoption7807f42

line 82why, one step back
82 Express.header('content-type').should.eql 'text/html'

Added Express.header()visionmediabefore adoption3b3be54

lines 83–84why, one step back
83 end
84 end

Added Express.status() and specsvisionmediabefore adoptionaa01cc2

lines 85–105why, one step back
85
86 describe '.status()'87 after_each88 Express.response.status = 20089 end90 91 it 'should set response status code by number'92 Express.status(404)93 Express.response.status.should.eql 40494 end95 96 it 'should set using the status string map'97 Express.status('Not Found')98 Express.response.status.should.eql 40499 end100 101 it 'should be case insensitive'102 Express.status('forbidden')103 Express.response.status.should.eql 403104 end105 end

Added Express.hashToArray()visionmediabefore adoption3dfe6c0

line 106why, one step back
106

Added Express.respond()visionmediabefore adoption2b3fadf

lines 107–111why, one step back
107 describe '.respond()'
108 after_each109 Express.response.status = 200110 end111

Added Express.Breakvisionmediabefore adoption52241a1

lines 112–113why, one step back
112 it 'should set response status and body'
113 -{ Express.respond('Page or file cannot be found', 'Not Found') }.should.throw_error

Added Express.respond()visionmediabefore adoption2b3fadf

line 114why, one step back
114 Express.response.status.should.eql 404

Added Express.Breakvisionmediabefore adoption52241a1

line 115why, one step back
115 Express.response.body.should.eql 'Page or file cannot be found'

Added Express.respond()visionmediabefore adoption2b3fadf

lines 116–118why, one step back
116 end
117 118 it 'should allow specific status to be passed'

Added Express.Breakvisionmediabefore adoption52241a1

line 119why, one step back
119 -{ Express.respond('File cannot be found', 404) }.should.throw_error

Added Express.respond()visionmediabefore adoption2b3fadf

line 120why, one step back
120 Express.response.status.should.eql 404

Added Express.Breakvisionmediabefore adoption52241a1

line 121why, one step back
121 Express.response.body.should.eql 'File cannot be found'

Added Express.respond()visionmediabefore adoption2b3fadf

lines 122–124why, one step back
122 end
123 end124

Added Express.hashToArray()visionmediabefore adoption3dfe6c0

lines 125–130why, one step back
125 describe '.hashToArray()'
126 it 'should map hash key / value pairs to an array'127 headers = { 'Content-Type' : 'text/plain' }128 Express.hashToArray(headers).should.eql [['Content-Type', 'text/plain']]129 end130 end

Added Express.arrayToHash()visionmediabefore adoptiona091bdd

lines 131–135why, one step back
131
132 describe '.arrayToHash()'133 it 'should map an assoc array to an object'134 headers = [['Content-Type', 'text/plain']]135 Express.arrayToHash(headers).should.eql { 'Content-Type' : 'text/plain' }

Header fields case insensitivevisionmediabefore adoption6dc1715

lines 136–144why, one step back
136 end
137 end138 139 describe '.redirect()'140 it 'should redirect to the url specified'141 get('foo', function(){ redirect('http://google.com') })142 response = get('foo')143 response.headers.location.should.eql 'http://google.com'144 response.status.should.eql 302

Added redirect(home) and settings.basepath [#8]visionmediabefore adoption8e523c6

lines 145–151why, one step back
145 end
146 end147 148 describe '.home'149 it 'should redirect home'150 get('foo', function(){ redirect(home) })151 get('foo').headers.location.should.eql '/'

Added hook()visionmediabefore adoptioncfb3018

lines 152–153why, one step back
152 end
153 end

Added BodyDecoder specvisionmediabefore adoption461337a

lines 154–161why, one step back
154
155 describe 'BodyDecoder'156 it 'should parse urlencoded bodies'157 request = mockRequest({ 158 headers : [['Content-Type', 'application/x-www-form-urlencoded']],159 body : 'user[name]=foo%20bar&status=1'160 })161 post('foo', function(){ param('user').name + ' ' + param('status') })

Mock request specvisionmediabefore adoption9cc5593

line 162why, one step back
162 post('foo', { request : request }).body.should.eql 'foo bar 1'

Added BodyDecoder specvisionmediabefore adoption461337a

lines 163–164why, one step back
163 end
164 end

Initial commitvisionmediabefore adoption9998490

line 165
165end