spec.core.js
This file
Path
spec/spec.core.js
218 lines · 6.5 KiB · JavaScript
Last changed by
Specsvisionmediabefore adoptionedbdcb3
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–148why, one step back144 145 describe '.arrayToHash()'146 it 'should map an assoc array to an object'147 headers = [['Content-Type', 'text/plain']]148 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–164why, one step back158 end159 end160 161 describe '.home'162 it 'should redirect home'163 get('foo', function(){ redirect(home) })164 get('foo').headers.location.should.eql '/'Added hook()visionmediabefore adoptioncfb3018
lines 165–166why, one step back165 end166 endAdded BodyDecoder specvisionmediabefore adoption461337a
lines 167–173why, one step back167 168 describe 'BodyDecoder'169 it 'should parse urlencoded bodies'170 request = mockRequest({ 171 headers : [['Content-Type', 'application/x-www-form-urlencoded']],172 body : 'user[name]=foo%20bar&status=1'173 })Specsvisionmediabefore adoptionedbdcb3
lines 174–175why, one step back174 post('admin', function(){ param('user').name + ' ' + param('status') })175 post('admin', { request : request }).body.should.eql 'foo bar 1'Added BodyDecoder specvisionmediabefore adoption461337a
line 176why, one step back176 endAdded JSON body decoding specvisionmediabefore adoptionb1b8bf4
lines 177–185why, one step back177178 it 'should parse JSON bodies'179 request = mockRequest({ 180 headers : [['Content-Type', 'application/json']],181 body : '{ foo : "bar" }'182 })183 post('foo', function(){ param('foo') })184 post('foo', { request : request }).body.should.eql 'bar'185 endAdded BodyDecoder specvisionmediabefore adoption461337a
line 186why, one step back186 endStarted core module specsvisionmediabefore adoption655c456
lines 187–189why, one step back187 188 describe 'ContentLength'189 it 'should set the content length header'Added ContentLength specvisionmediabefore adoptionf8e18cf
lines 190–191why, one step back190 get('foo', function(){ 'foo bar' })191 get('foo').headers['content-length'].should.eql 7Started core module specsvisionmediabefore adoption655c456
lines 192–196why, one step back192 end193 end194 195 describe 'MethodOverride'196 it 'should override request method when _method param is present'Specsvisionmediabefore adoptionedbdcb3
lines 197–200why, one step back197 request = mockRequest({ 198 headers : [['Content-Type', 'application/x-www-form-urlencoded']],199 body : '_method=delete'200 })Added MethodOverride specvisionmediabefore adoptionc5f0d7d
line 201why, one step back201 del('foo', function(){ 'Deleted' })Misc spec refactoringvisionmediabefore adoption808f194
line 202why, one step back202 post('foo', { request : { body : '_method=delete' }}).body.should.eql 'Deleted'Started core module specsvisionmediabefore adoption655c456
lines 203–207why, one step back203 end204 end205 206 describe 'DefaultContentType'207 it 'should default to text/html'Added DefaultContentType specsvisionmediabefore adoptionef572f4
lines 208–209why, one step back208 get('foo', function(){ 'bar' })209 get('foo').headers['content-type'].should.eql 'text/html'Started core module specsvisionmediabefore adoption655c456
lines 210–212why, one step back210 end211 212 it 'should be overridable'Added DefaultContentType specsvisionmediabefore adoptionef572f4
lines 213–214why, one step back213 get('foo', function(){ header('Content-Type', 'application/json'); 'bar' })214 get('foo').headers['content-type'].should.eql 'application/json'Started core module specsvisionmediabefore adoption655c456
lines 215–217why, one step back215 end216 end217 218end