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 fileTake it
12describe 'Express'Added redirect(home) and settings.basepath [#8]visionmediabefore adoption8e523c6
lines 3–6why, one step back3 before_each4 Express.routes = []5 end6 Setting up specsvisionmediabefore adoption0d81d0b
lines 7–11why, one step back7 describe '.version'8 it 'should be properly formatted'9 Express.version.should.match /\d+\.\d+\.\d+/10 end11 endAdded spec for Express.contentsOf()visionmediabefore adoptionafde985
line 12why, one step back12 Added POST urlencoded body parsingvisionmediabefore adoption7807f42
lines 13–23why, one step back13 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 back24 describe '.parseNestedParams()'25 it 'should parse nested params hash provided by node'Started parseNestedParams()visionmediabefore adoptione7f11d5
line 26why, one step back26 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 back27 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 back32 end33 end34 Added parseCookie()visionmediabefore adoption5be8088
line 35why, one step back35 describe '.parseCookie()'Miscvisionmediabefore adoption6d0bf20
line 36why, one step back36 it 'should parse cookie pairs'Misc module progressvisionmediabefore adoption15839de
line 37why, one step back37 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 back38 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 back43 end44 end45 Added argsArray()visionmediabefore adoption4a0706f
lines 46–55why, one step back46 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 back56 describe '.escape()'57 it 'should escape html'58 Express.escape('<>&""').should.eql '<>&""'59 end60 end61 Added escapeRegexp()visionmediabefore adoption24bca5d
lines 62–65why, one step back62 describe '.escapeRegexp()'63 it 'should escape regexp special characters'64 Express.escapeRegexp('/users/(name)').should.eql '\\/users\\/\\(name\\)'65 endAdded chars param to escapeRegexp()visionmediabefore adoption46a0892
lines 66–69why, one step back66 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 endAdded escapeRegexp()visionmediabefore adoption24bca5d
lines 70–71why, one step back70 end71 Added spec for Express.contentsOf()visionmediabefore adoptionafde985
lines 72–76why, one step back72 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 endAdded Express.header()visionmediabefore adoption3b3be54
lines 77–81why, one step back77 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 back82 Express.header('content-type').should.eql 'text/html'Added Express.header()visionmediabefore adoption3b3be54
lines 83–84why, one step back83 end84 endAdded Express.status() and specsvisionmediabefore adoptionaa01cc2
line 85why, one step back85 Added Express.arg()visionmediabefore adoptionbcbf2c7
lines 86–92why, one step back86 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 endMore specs for arg()visionmediabefore adoption895f75f
lines 93–96why, one step back93 94 it 'should return null when segment does not exist'95 Express.arg(12).should.be_null96 endAdded Express.arg()visionmediabefore adoptionbcbf2c7
lines 97–98why, one step back97 end98 Added Express.status() and specsvisionmediabefore adoptionaa01cc2
lines 99–118why, one step back99 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 endAdded Express.hashToArray()visionmediabefore adoption3dfe6c0
line 119why, one step back119 Added Express.respond()visionmediabefore adoption2b3fadf
lines 120–124why, one step back120 describe '.respond()'121 after_each122 Express.response.status = 200123 end124 Added Express.Breakvisionmediabefore adoption52241a1
lines 125–126why, one step back125 it 'should set response status and body'126 -{ Express.respond('Page or file cannot be found', 'Not Found') }.should.throw_errorAdded Express.respond()visionmediabefore adoption2b3fadf
line 127why, one step back127 Express.response.status.should.eql 404Added Express.Breakvisionmediabefore adoption52241a1
line 128why, one step back128 Express.response.body.should.eql 'Page or file cannot be found'Added Express.respond()visionmediabefore adoption2b3fadf
lines 129–131why, one step back129 end130 131 it 'should allow specific status to be passed'Added Express.Breakvisionmediabefore adoption52241a1
line 132why, one step back132 -{ Express.respond('File cannot be found', 404) }.should.throw_errorAdded Express.respond()visionmediabefore adoption2b3fadf
line 133why, one step back133 Express.response.status.should.eql 404Added Express.Breakvisionmediabefore adoption52241a1
line 134why, one step back134 Express.response.body.should.eql 'File cannot be found'Added Express.respond()visionmediabefore adoption2b3fadf
lines 135–137why, one step back135 end136 end137 Added Express.hashToArray()visionmediabefore adoption3dfe6c0
lines 138–143why, one step back138 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 endAdded Express.arrayToHash()visionmediabefore adoptiona091bdd
lines 144–147why, one step back144 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 back148 Express.arrayToHash(headers).should.eql { 'content-type' : 'text/plain' }Header fields case insensitivevisionmediabefore adoption6dc1715
lines 149–157why, one step back149 end150 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 302Added redirect(home) and settings.basepath [#8]visionmediabefore adoption8e523c6
lines 158–160why, one step back158 end159 end160 Added specs for .backvisionmediabefore adoption50b5fa8
line 161why, one step back161 describe 'RedirectHelpers'Fixed some specsvisionmediabefore adoption433b347
lines 162–165why, one step back162 before_each163 Express.response.headers = {}164 end165 Added specs for .backvisionmediabefore adoption50b5fa8
lines 166–170why, one step back166 describe '.home'167 it 'should redirect home'168 get('foo', function(){ redirect(home) })169 get('foo').headers.location.should.eql '/'170 endAdded more RedirectHelper specsvisionmediabefore adoptiona7a4454
lines 171–175why, one step back171 172 it 'should not always set location'173 get('foo', function(){ 'bar' })174 get('foo').headers.should.not.have_property 'location'175 endAdded specs for .backvisionmediabefore adoption50b5fa8
lines 176–178why, one step back176 end177 178 describe '.back'Miscvisionmediabefore adoption4598445
line 179why, one step back179 it 'should redirect to the referrer'Added more RedirectHelper specsvisionmediabefore adoptiona7a4454
line 180why, one step back180 uri = 'http://vision-media.ca'Fixed some specsvisionmediabefore adoption433b347
line 181why, one step back181 get('foo', function(){ redirect(back) })fixed overriding of path by mock requestcsausdevbefore adoption9fb91c6
lines 182–183why, one step back182 request = mockRequest({ headers : [['Referer', uri]] })183 get('foo', { request: request }).headers.location.should.eql uriAdded more RedirectHelper specsvisionmediabefore adoptiona7a4454
line 184why, one step back184 Express.back.should.eql uriAdded specs for .backvisionmediabefore adoption50b5fa8
line 185why, one step back185 endAdded hook()visionmediabefore adoptioncfb3018
lines 186–187why, one step back186 end187 endAdded BodyDecoder specvisionmediabefore adoption461337a
lines 188–190why, one step back188 189 describe 'BodyDecoder'190 it 'should parse urlencoded bodies'all tests pass nowcsausdevbefore adoptionf1f8429
lines 191–192why, one step back191 request = mockRequest({192 method: 'POST',Added BodyDecoder specvisionmediabefore adoption461337a
lines 193–195why, one step back193 headers : [['Content-Type', 'application/x-www-form-urlencoded']],194 body : 'user[name]=foo%20bar&status=1'195 })Specsvisionmediabefore adoptionedbdcb3
lines 196–197why, one step back196 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 back198 endAdded JSON body decoding specvisionmediabefore adoptionb1b8bf4
lines 199–200why, one step back199200 it 'should parse JSON bodies'all tests pass nowcsausdevbefore adoptionf1f8429
lines 201–202why, one step back201 request = mockRequest({202 method: 'POST',Added JSON body decoding specvisionmediabefore adoptionb1b8bf4
lines 203–208why, one step back203 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 endAdded BodyDecoder specvisionmediabefore adoption461337a
line 209why, one step back209 endStarted core module specsvisionmediabefore adoption655c456
lines 210–212why, one step back210 211 describe 'ContentLength'212 it 'should set the content length header'Added ContentLength specvisionmediabefore adoptionf8e18cf
lines 213–214why, one step back213 get('foo', function(){ 'foo bar' })214 get('foo').headers['content-length'].should.eql 7Started core module specsvisionmediabefore adoption655c456
lines 215–219why, one step back215 end216 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 back220 request = mockRequest({221 method: 'POST',Specsvisionmediabefore adoptionedbdcb3
lines 222–224why, one step back222 headers : [['Content-Type', 'application/x-www-form-urlencoded']],223 body : '_method=delete'224 })Added MethodOverride specvisionmediabefore adoptionc5f0d7d
line 225why, one step back225 del('foo', function(){ 'Deleted' })all tests pass nowcsausdevbefore adoptionf1f8429
line 226why, one step back226 post('foo', { request : request}).body.should.eql 'Deleted'Started core module specsvisionmediabefore adoption655c456
lines 227–231why, one step back227 end228 end229 230 describe 'DefaultContentType'231 it 'should default to text/html'Added DefaultContentType specsvisionmediabefore adoptionef572f4
lines 232–233why, one step back232 get('foo', function(){ 'bar' })233 get('foo').headers['content-type'].should.eql 'text/html'Started core module specsvisionmediabefore adoption655c456
lines 234–236why, one step back234 end235 236 it 'should be overridable'Added DefaultContentType specsvisionmediabefore adoptionef572f4
lines 237–238why, one step back237 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 back239 end240 end241 242end