Previous `jspec init --freeze` call wrote over spec.core.js
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 4505a5c · Browse files · 1 file·+236 added−4 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+236 added−4 removed
- tests:+236 added−4 removed
Provenance
- Commit
cc56c63- Tree
7e3aaf4- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
4505a5c
1 file changed+236 added−4 removed
modified:spec/spec.core.js+236 added-4 removed
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971982345199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240describe 'Express' before_each Express.routes = [] end describe '.version' it 'should be properly formatted' Express.version.should.match /\d+\.\d+\.\d+/ end end describe '.parseParams()' it 'should parse a string of parameters' string = 'user[name]=tj&user[pass]=test&foo=some bar stuff&cookies=awesome' params = Express.parseParams(string) params.user.name.should.eql 'tj' params.user.pass.should.eql 'test' params.foo.should.eql 'some bar stuff' params.cookies.should.eql 'awesome' end end describe '.parseNestedParams()' it 'should parse nested params hash provided by node' params = { 'foo' : 'bar', 'user[name]' : 'tj', 'user[info][email]' : 'tj@vision-media.ca', 'user[info][city]' : 'Victoria' } nested = Express.parseNestedParams(params) nested.foo.should.eql 'bar' nested.user.name.should.eql 'tj' nested.user.info.email.should.eql 'tj@vision-media.ca' nested.user.info.city.should.eql 'Victoria' end end describe '.parseCookie()' it 'should parse cookie pairs' var cookie = 'expires=Fri, 31-Dec-2010 23:59:59 GMT; path=/; q=foo%3dbar; domain=example.net' parts = Express.parseCookie(cookie) parts.expires.should.eql 'Fri, 31-Dec-2010 23:59:59 GMT' parts.path.should.eql '/' parts.q.should.eql 'foo=bar' parts.domain.should.eql 'example.net' end end describe '.toArray()' it 'should return an array of arguments' Express.toArray(-{ return arguments }('foo', 'bar')).should.eql ['foo', 'bar'] end it 'should allow an offset' Express.toArray(-{ return arguments }('foo', 'bar'), 1).should.eql ['bar'] end end describe '.escape()' it 'should escape html' Express.escape('<>&""').should.eql '<>&""' end end describe '.escapeRegexp()' it 'should escape regexp special characters' Express.escapeRegexp('/users/(name)').should.eql '\\/users\\/\\(name\\)' end it 'should accept a string of space-delimited characters' Express.escapeRegexp('/foo/#bar?user[name]=tj', '/ [ ]').should.eql '\\/foo\\/#bar?user\\[name\\]=tj' end end describe '.contentsOf()' it 'should return the body of a function as a string' Express.contentsOf(function(){ return 'foo' }).should.include 'return', 'foo' end end describe '.header()' it 'should set / get headers' Express.header('Content-Type', 'text/html') Express.header('Content-Type').should.eql 'text/html' Express.header('content-type').should.eql 'text/html' end end describe '.arg()' it 'should return the given path segment' Express.request = mockRequest({ uri : { path : 'some/foo-bar/baz' }}) Express.arg(0).should.eql 'some' Express.arg(1).should.eql 'foo-bar' Express.arg(2).should.eql 'baz' end it 'should return null when segment does not exist' Express.arg(12).should.be_null end end describe '.status()' after_each Express.response.status = 200 end it 'should set response status code by number' Express.status(404) Express.response.status.should.eql 404 end it 'should set using the status string map' Express.status('Not Found') Express.response.status.should.eql 404 end it 'should be case insensitive' Express.status('forbidden') Express.response.status.should.eql 403 end end describe '.respond()' after_each Express.response.status = 200 end it 'should set response status and body' -{ Express.respond('Page or file cannot be found', 'Not Found') }.should.throw_error Express.response.status.should.eql 404 Express.response.body.should.eql 'Page or file cannot be found' end it 'should allow specific status to be passed' -{ Express.respond('File cannot be found', 404) }.should.throw_error Express.response.status.should.eql 404 Express.response.body.should.eql 'File cannot be found' end end describe '.hashToArray()' it 'should map hash key / value pairs to an array' headers = { 'Content-Type' : 'text/plain' } Express.hashToArray(headers).should.eql [['Content-Type', 'text/plain']] end end describe '.arrayToHash()' it 'should map an assoc array to an object' headers = [['Content-Type', 'text/plain']] Express.arrayToHash(headers).should.eql { 'content-type' : 'text/plain' } end end describe '.redirect()' it 'should redirect to the url specified' get('foo', function(){ redirect('http://google.com') }) response = get('foo') response.headers.location.should.eql 'http://google.com' response.status.should.eql 302 end end describe 'RedirectHelpers' before_each Express.response.headers = {} end describe '.home' it 'should redirect home' get('foo', function(){ redirect(home) }) get('foo').headers.location.should.eql '/' end it 'should not always set location' get('foo', function(){ 'bar' }) get('foo').headers.should.not.have_property 'location' end end describe '.back' it 'should redirect to the referrer' uri = 'http://vision-media.ca' get('foo', function(){ redirect(back) }) request = mockRequest({ headers : [['Referer', uri]] }) get('foo', { request: request }).headers.location.should.eql uri Express.back.should.eql uri end end end describe 'BodyDecoder' it 'should parse urlencoded bodies' request = mockRequest({ method: 'POST', headers : [['Content-Type', 'application/x-www-form-urlencoded']], body : 'user[name]=foo%20bar&status=1' }) post('admin', function(){ param('user').name + ' ' + param('status') }) post('admin', { request : request }).body.should.eql 'foo bar 1' end
describe 'YourLib' describe '.someMethod()' it 'should do something' true.should.be true it 'should parse JSON bodies' request = mockRequest({ method: 'POST', headers : [['Content-Type', 'application/json']], body : '{ foo : "bar" }' }) post('foo', function(){ param('foo') }) post('foo', { request : request }).body.should.eql 'bar' end end describe 'ContentLength' it 'should set the content length header' get('foo', function(){ 'foo bar' }) get('foo').headers['content-length'].should.eql 7 end end describe 'MethodOverride' it 'should override request method when _method param is present' request = mockRequest({ method: 'POST', headers : [['Content-Type', 'application/x-www-form-urlencoded']], body : '_method=delete' }) del('foo', function(){ 'Deleted' }) post('foo', { request : request}).body.should.eql 'Deleted' end end describe 'DefaultContentType' it 'should default to text/html' get('foo', function(){ 'bar' }) get('foo').headers['content-type'].should.eql 'text/html' end it 'should be overridable' get('foo', function(){ header('Content-Type', 'application/json'); 'bar' }) get('foo').headers['content-type'].should.eql 'application/json' end endendNo newline at end of fileNo newline at end of file