Remotely patched JSpec
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 489b88c · Browse files · 3 files·+18 added−252 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+18 added−252 removed
- tests:+18 added−252 removed
Provenance
- Commit
8156f85- Tree
b8bb18d- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
489b88c
3 files changed+18 added−252 removed
modified:spec/lib/jspec.js+3 added-8 removed
202 unmodified lines203 print("")204 }205 })206 207- var promise = new process.Promise208- results.stats.failures == 0 ?209- promise.emitSuccess("", "") :210- promise.emitError(results.stats.failures, "")207+ quit(results.stats.failures)208 },209 210 /**211 * Console formatter.1391 unmodified lines1603 1604 load : function(file, callback) {1605 if (any(hook('loading', file), haveStopped)) return1606 if ('readFile' in main)1610- return readFile(file, callback)1607+ return readFile(file)1608 else if (this.hasXhr()) {1609 var request = this.xhr()1610 request.open('GET', file, false)1611 request.send(null)15 unmodified lines1627 */1628 1629 exec : function(file) {1630 if (any(hook('executing', file), haveStopped)) return this1634- this.load(file, function(contents){1635- eval('with (JSpec){' + JSpec.preprocess(contents) + '}')1636- })1631+ eval('with (JSpec){' + this.preprocess(this.load(file)) + '}')1632 return this1633 }1634 }1635 141 unmodified linesmodified:spec/spec.core.js+5 added-239 removed
123456789234567121314151617181920218222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
describe 'Express' before_each Express.routes = [] end describe '.version' it 'should be properly formatted' Express.version.should.match(/^\d+\.\d+\.\d+$/)describe 'YourLib' describe '.someMethod()' it 'should do something' true.should.be true 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' endend 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
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 end endmodified:spec/spec.node.js+10 added-5 removed
3 unmodified lines4567891011128913141516171218192021222317182425262712 unmodified lines3 unmodified linesrequire("jspec")require("express")require("express.mocks")
var posix = require('posix')
quit = process.exitprint = puts
readFile = function(path, callback) { var promise = require('posix').cat(path, "utf8")readFile = function(path) { var promise = posix.cat(path, "utf8") var result = '' promise.addErrback(function(){ throw "failed to read file `" + path + "'" }) promise.addCallback(function(contents){ callback(contents) result = contents }) promise.wait() return result}
print = puts
if (process.ARGV[2]) JSpec.exec('spec/spec.' + process.ARGV[2] + '.js') else JSpec12 unmodified lines