Skip to content
Myr

spec.core.js

This file

Path

spec/spec.core.js

242 lines · 7.2 KiB · JavaScript

Last changed by

all tests pass nowcsausdevbefore adoptionf1f8429

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

line 85why, one step back
85

Added Express.arg()visionmediabefore adoptionbcbf2c7

lines 86–92why, one step back
86 describe '.arg()'
87 it 'should return the given path segment'88 Express.request = mockRequest({ uri : { path : 'some/foo-bar/baz' }})89 Express.arg(0).should.eql 'some'90 Express.arg(1).should.eql 'foo-bar'91 Express.arg(2).should.eql 'baz'92 end

More specs for arg()visionmediabefore adoption895f75f

lines 93–96why, one step back
93
94 it 'should return null when segment does not exist'95 Express.arg(12).should.be_null96 end

Added Express.arg()visionmediabefore adoptionbcbf2c7

lines 97–98why, one step back
97 end
98

Added Express.status() and specsvisionmediabefore adoptionaa01cc2

lines 99–118why, one step back
99 describe '.status()'
100 after_each101 Express.response.status = 200102 end103 104 it 'should set response status code by number'105 Express.status(404)106 Express.response.status.should.eql 404107 end108 109 it 'should set using the status string map'110 Express.status('Not Found')111 Express.response.status.should.eql 404112 end113 114 it 'should be case insensitive'115 Express.status('forbidden')116 Express.response.status.should.eql 403117 end118 end

Added Express.hashToArray()visionmediabefore adoption3dfe6c0

line 119why, one step back
119

Added Express.respond()visionmediabefore adoption2b3fadf

lines 120–124why, one step back
120 describe '.respond()'
121 after_each122 Express.response.status = 200123 end124

Added Express.Breakvisionmediabefore adoption52241a1

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

Added Express.respond()visionmediabefore adoption2b3fadf

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

Added Express.Breakvisionmediabefore adoption52241a1

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

Added Express.respond()visionmediabefore adoption2b3fadf

lines 129–131why, one step back
129 end
130 131 it 'should allow specific status to be passed'

Added Express.Breakvisionmediabefore adoption52241a1

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

Added Express.respond()visionmediabefore adoption2b3fadf

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

Added Express.Breakvisionmediabefore adoption52241a1

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

Added Express.respond()visionmediabefore adoption2b3fadf

lines 135–137why, one step back
135 end
136 end137

Added Express.hashToArray()visionmediabefore adoption3dfe6c0

lines 138–143why, one step back
138 describe '.hashToArray()'
139 it 'should map hash key / value pairs to an array'140 headers = { 'Content-Type' : 'text/plain' }141 Express.hashToArray(headers).should.eql [['Content-Type', 'text/plain']]142 end143 end

Added Express.arrayToHash()visionmediabefore adoptiona091bdd

lines 144–147why, one step back
144
145 describe '.arrayToHash()'146 it 'should map an assoc array to an object'147 headers = [['Content-Type', 'text/plain']]

fixed overriding of path by mock requestcsausdevbefore adoption9fb91c6

line 148why, one step back
148 Express.arrayToHash(headers).should.eql { 'content-type' : 'text/plain' }

Header fields case insensitivevisionmediabefore adoption6dc1715

lines 149–157why, one step back
149 end
150 end151 152 describe '.redirect()'153 it 'should redirect to the url specified'154 get('foo', function(){ redirect('http://google.com') })155 response = get('foo')156 response.headers.location.should.eql 'http://google.com'157 response.status.should.eql 302

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

lines 158–160why, one step back
158 end
159 end160

Added specs for .backvisionmediabefore adoption50b5fa8

line 161why, one step back
161 describe 'RedirectHelpers'

Fixed some specsvisionmediabefore adoption433b347

lines 162–165why, one step back
162 before_each
163 Express.response.headers = {}164 end165

Added specs for .backvisionmediabefore adoption50b5fa8

lines 166–170why, one step back
166 describe '.home'
167 it 'should redirect home'168 get('foo', function(){ redirect(home) })169 get('foo').headers.location.should.eql '/'170 end

Added more RedirectHelper specsvisionmediabefore adoptiona7a4454

lines 171–175why, one step back
171
172 it 'should not always set location'173 get('foo', function(){ 'bar' })174 get('foo').headers.should.not.have_property 'location'175 end

Added specs for .backvisionmediabefore adoption50b5fa8

lines 176–178why, one step back
176 end
177 178 describe '.back'

Miscvisionmediabefore adoption4598445

line 179why, one step back
179 it 'should redirect to the referrer'

Added more RedirectHelper specsvisionmediabefore adoptiona7a4454

line 180why, one step back
180 uri = 'http://vision-media.ca'

Fixed some specsvisionmediabefore adoption433b347

line 181why, one step back
181 get('foo', function(){ redirect(back) })

fixed overriding of path by mock requestcsausdevbefore adoption9fb91c6

lines 182–183why, one step back
182 request = mockRequest({ headers : [['Referer', uri]] })
183 get('foo', { request: request }).headers.location.should.eql uri

Added more RedirectHelper specsvisionmediabefore adoptiona7a4454

line 184why, one step back
184 Express.back.should.eql uri

Added specs for .backvisionmediabefore adoption50b5fa8

line 185why, one step back
185 end

Added hook()visionmediabefore adoptioncfb3018

lines 186–187why, one step back
186 end
187 end

Added BodyDecoder specvisionmediabefore adoption461337a

lines 188–190why, one step back
188
189 describe 'BodyDecoder'190 it 'should parse urlencoded bodies'

all tests pass nowcsausdevbefore adoptionf1f8429

lines 191–192why, one step back
191 request = mockRequest({
192 method: 'POST',

Added BodyDecoder specvisionmediabefore adoption461337a

lines 193–195why, one step back
193 headers : [['Content-Type', 'application/x-www-form-urlencoded']],
194 body : 'user[name]=foo%20bar&status=1'195 })

Specsvisionmediabefore adoptionedbdcb3

lines 196–197why, one step back
196 post('admin', function(){ param('user').name + ' ' + param('status') })
197 post('admin', { request : request }).body.should.eql 'foo bar 1'

Added BodyDecoder specvisionmediabefore adoption461337a

line 198why, one step back
198 end

Added JSON body decoding specvisionmediabefore adoptionb1b8bf4

lines 199–200why, one step back
199
200 it 'should parse JSON bodies'

all tests pass nowcsausdevbefore adoptionf1f8429

lines 201–202why, one step back
201 request = mockRequest({
202 method: 'POST',

Added JSON body decoding specvisionmediabefore adoptionb1b8bf4

lines 203–208why, one step back
203 headers : [['Content-Type', 'application/json']],
204 body : '{ foo : "bar" }'205 })206 post('foo', function(){ param('foo') })207 post('foo', { request : request }).body.should.eql 'bar'208 end

Added BodyDecoder specvisionmediabefore adoption461337a

line 209why, one step back
209 end

Started core module specsvisionmediabefore adoption655c456

lines 210–212why, one step back
210
211 describe 'ContentLength'212 it 'should set the content length header'

Added ContentLength specvisionmediabefore adoptionf8e18cf

lines 213–214why, one step back
213 get('foo', function(){ 'foo bar' })
214 get('foo').headers['content-length'].should.eql 7

Started core module specsvisionmediabefore adoption655c456

lines 215–219why, one step back
215 end
216 end217 218 describe 'MethodOverride'219 it 'should override request method when _method param is present'

all tests pass nowcsausdevbefore adoptionf1f8429

lines 220–221why, one step back
220 request = mockRequest({
221 method: 'POST',

Specsvisionmediabefore adoptionedbdcb3

lines 222–224why, one step back
222 headers : [['Content-Type', 'application/x-www-form-urlencoded']],
223 body : '_method=delete'224 })

Added MethodOverride specvisionmediabefore adoptionc5f0d7d

line 225why, one step back
225 del('foo', function(){ 'Deleted' })

all tests pass nowcsausdevbefore adoptionf1f8429

line 226why, one step back
226 post('foo', { request : request}).body.should.eql 'Deleted'

Started core module specsvisionmediabefore adoption655c456

lines 227–231why, one step back
227 end
228 end229 230 describe 'DefaultContentType'231 it 'should default to text/html'

Added DefaultContentType specsvisionmediabefore adoptionef572f4

lines 232–233why, one step back
232 get('foo', function(){ 'bar' })
233 get('foo').headers['content-type'].should.eql 'text/html'

Started core module specsvisionmediabefore adoption655c456

lines 234–236why, one step back
234 end
235 236 it 'should be overridable'

Added DefaultContentType specsvisionmediabefore adoptionef572f4

lines 237–238why, one step back
237 get('foo', function(){ header('Content-Type', 'application/json'); 'bar' })
238 get('foo').headers['content-type'].should.eql 'application/json'

Started core module specsvisionmediabefore adoption655c456

lines 239–241why, one step back
239 end
240 end241

Initial commitvisionmediabefore adoption9998490

line 242
242end