spec.core.js
This file
Path
spec/spec.core.js
240 lines · 7.2 KiB · JavaScript
Last changed by
Previous `jspec init --freeze` call wrote over spec.core.jsvisionmediabefore adoptioncc56c63
History of this fileTake it
The walk stopped after 200 commits: lines older than 9128dc1 point at it.
Previous `jspec init --freeze` call wrote over spec.core.jsvisionmediabefore adoptioncc56c63
lines 1–197why, one step back1describe 'Express'2 before_each3 Express.routes = []4 end5 6 describe '.version'7 it 'should be properly formatted'8 Express.version.should.match /\d+\.\d+\.\d+/9 end10 end11 12 describe '.parseParams()'13 it 'should parse a string of parameters'14 string = 'user[name]=tj&user[pass]=test&foo=some bar stuff&cookies=awesome'15 params = Express.parseParams(string)16 params.user.name.should.eql 'tj'17 params.user.pass.should.eql 'test'18 params.foo.should.eql 'some bar stuff'19 params.cookies.should.eql 'awesome'20 end21 end22 23 describe '.parseNestedParams()'24 it 'should parse nested params hash provided by node'25 params = { 'foo' : 'bar', 'user[name]' : 'tj', 'user[info][email]' : 'tj@vision-media.ca', 'user[info][city]' : 'Victoria' }26 nested = Express.parseNestedParams(params)27 nested.foo.should.eql 'bar'28 nested.user.name.should.eql 'tj'29 nested.user.info.email.should.eql 'tj@vision-media.ca'30 nested.user.info.city.should.eql 'Victoria'31 end32 end33 34 describe '.parseCookie()'35 it 'should parse cookie pairs'36 var cookie = 'expires=Fri, 31-Dec-2010 23:59:59 GMT; path=/; q=foo%3dbar; domain=example.net'37 parts = Express.parseCookie(cookie)38 parts.expires.should.eql 'Fri, 31-Dec-2010 23:59:59 GMT'39 parts.path.should.eql '/'40 parts.q.should.eql 'foo=bar'41 parts.domain.should.eql 'example.net'42 end43 end44 45 describe '.toArray()'46 it 'should return an array of arguments'47 Express.toArray(-{ return arguments }('foo', 'bar')).should.eql ['foo', 'bar']48 end49 50 it 'should allow an offset'51 Express.toArray(-{ return arguments }('foo', 'bar'), 1).should.eql ['bar']52 end53 end54 55 describe '.escape()'56 it 'should escape html'57 Express.escape('<>&""').should.eql '<>&""'58 end59 end60 61 describe '.escapeRegexp()'62 it 'should escape regexp special characters'63 Express.escapeRegexp('/users/(name)').should.eql '\\/users\\/\\(name\\)'64 end65 66 it 'should accept a string of space-delimited characters'67 Express.escapeRegexp('/foo/#bar?user[name]=tj', '/ [ ]').should.eql '\\/foo\\/#bar?user\\[name\\]=tj'68 end69 end70 71 describe '.contentsOf()'72 it 'should return the body of a function as a string'73 Express.contentsOf(function(){ return 'foo' }).should.include 'return', 'foo'74 end75 end76 77 describe '.header()'78 it 'should set / get headers'79 Express.header('Content-Type', 'text/html')80 Express.header('Content-Type').should.eql 'text/html'81 Express.header('content-type').should.eql 'text/html'82 end83 end84 85 describe '.arg()'86 it 'should return the given path segment'87 Express.request = mockRequest({ uri : { path : 'some/foo-bar/baz' }})88 Express.arg(0).should.eql 'some'89 Express.arg(1).should.eql 'foo-bar'90 Express.arg(2).should.eql 'baz'91 end92 93 it 'should return null when segment does not exist'94 Express.arg(12).should.be_null95 end96 end97 98 describe '.status()'99 after_each100 Express.response.status = 200101 end102 103 it 'should set response status code by number'104 Express.status(404)105 Express.response.status.should.eql 404106 end107 108 it 'should set using the status string map'109 Express.status('Not Found')110 Express.response.status.should.eql 404111 end112 113 it 'should be case insensitive'114 Express.status('forbidden')115 Express.response.status.should.eql 403116 end117 end118 119 describe '.respond()'120 after_each121 Express.response.status = 200122 end123 124 it 'should set response status and body'125 -{ Express.respond('Page or file cannot be found', 'Not Found') }.should.throw_error126 Express.response.status.should.eql 404127 Express.response.body.should.eql 'Page or file cannot be found'128 end129 130 it 'should allow specific status to be passed'131 -{ Express.respond('File cannot be found', 404) }.should.throw_error132 Express.response.status.should.eql 404133 Express.response.body.should.eql 'File cannot be found'134 end135 end136 137 describe '.hashToArray()'138 it 'should map hash key / value pairs to an array'139 headers = { 'Content-Type' : 'text/plain' }140 Express.hashToArray(headers).should.eql [['Content-Type', 'text/plain']]141 end142 end143 144 describe '.arrayToHash()'145 it 'should map an assoc array to an object'146 headers = [['Content-Type', 'text/plain']]147 Express.arrayToHash(headers).should.eql { 'content-type' : 'text/plain' }148 end149 end150 151 describe '.redirect()'152 it 'should redirect to the url specified'153 get('foo', function(){ redirect('http://google.com') })154 response = get('foo')155 response.headers.location.should.eql 'http://google.com'156 response.status.should.eql 302157 end158 end159 160 describe 'RedirectHelpers'161 before_each162 Express.response.headers = {}163 end164 165 describe '.home'166 it 'should redirect home'167 get('foo', function(){ redirect(home) })168 get('foo').headers.location.should.eql '/'169 end170 171 it 'should not always set location'172 get('foo', function(){ 'bar' })173 get('foo').headers.should.not.have_property 'location'174 end175 end176 177 describe '.back'178 it 'should redirect to the referrer'179 uri = 'http://vision-media.ca'180 get('foo', function(){ redirect(back) })181 request = mockRequest({ headers : [['Referer', uri]] })182 get('foo', { request: request }).headers.location.should.eql uri183 Express.back.should.eql uri184 end185 end186 end187 188 describe 'BodyDecoder'189 it 'should parse urlencoded bodies'190 request = mockRequest({191 method: 'POST',192 headers : [['Content-Type', 'application/x-www-form-urlencoded']],193 body : 'user[name]=foo%20bar&status=1'194 })195 post('admin', function(){ param('user').name + ' ' + param('status') })196 post('admin', { request : request }).body.should.eql 'foo bar 1'197 endMoved specsvisionmediabefore adoption9128dc1
line 198why, one step back198Previous `jspec init --freeze` call wrote over spec.core.jsvisionmediabefore adoptioncc56c63
lines 199–237why, one step back199 it 'should parse JSON bodies'200 request = mockRequest({201 method: 'POST',202 headers : [['Content-Type', 'application/json']],203 body : '{ foo : "bar" }'204 })205 post('foo', function(){ param('foo') })206 post('foo', { request : request }).body.should.eql 'bar'207 end208 end209 210 describe 'ContentLength'211 it 'should set the content length header'212 get('foo', function(){ 'foo bar' })213 get('foo').headers['content-length'].should.eql 7214 end215 end216 217 describe 'MethodOverride'218 it 'should override request method when _method param is present'219 request = mockRequest({220 method: 'POST',221 headers : [['Content-Type', 'application/x-www-form-urlencoded']],222 body : '_method=delete'223 })224 del('foo', function(){ 'Deleted' })225 post('foo', { request : request}).body.should.eql 'Deleted'226 end227 end228 229 describe 'DefaultContentType'230 it 'should default to text/html'231 get('foo', function(){ 'bar' })232 get('foo').headers['content-type'].should.eql 'text/html'233 end234 235 it 'should be overridable'236 get('foo', function(){ header('Content-Type', 'application/json'); 'bar' })237 get('foo').headers['content-type'].should.eql 'application/json'Moved specsvisionmediabefore adoption9128dc1
lines 238–240why, one step back238 end239 end240end