Permalink
Browse files

tests: replace should with assert

  • Loading branch information...
1 parent 12fae43 commit 2939deed4eddc7d0f05811b626cc7d5cf1ba3176 @dougwilson dougwilson committed Sep 8, 2014
Showing with 162 additions and 118 deletions.
  1. +4 −5 package.json
  2. +33 −22 test/charset.js
  3. +36 −26 test/encoding.js
  4. +32 −22 test/language.js
  5. +57 −43 test/type.js
View
@@ -11,8 +11,7 @@
},
"devDependencies": {
"istanbul": "~0.3.0",
- "mocha": "1",
- "should": "4"
+ "mocha": "1"
},
"files": [
"LICENSE",
@@ -23,9 +22,9 @@
"node": ">= 0.8.0"
},
"scripts": {
- "test": "mocha --require should --reporter dot test/",
- "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require should --reporter dot test/",
- "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require should --reporter spec test/"
+ "test": "mocha --reporter spec --bail test/",
+ "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot test/",
+ "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec test/"
},
"keywords": [
"content",
View
@@ -1,31 +1,30 @@
-function accepts(charset) {
- return require('../')({
- headers: {
- 'accept-charset': charset
- }
- })
-}
+
+var accepts = require('..')
+var assert = require('assert')
describe('accepts.charsets()', function(){
describe('with no arguments', function(){
describe('when Accept-Charset is populated', function(){
it('should return accepted types', function(){
- var accept = accepts('utf-8, iso-8859-1;q=0.2, utf-7;q=0.5');
- accept.charsets().should.eql(['utf-8', 'utf-7', 'iso-8859-1']);
+ var req = createRequest('utf-8, iso-8859-1;q=0.2, utf-7;q=0.5')
+ var accept = accepts(req)
+ assert.deepEqual(accept.charsets(), ['utf-8', 'utf-7', 'iso-8859-1'])
})
})
describe('when Accept-Charset is not in request', function(){
it('should return *', function(){
- var accept = accepts();
- accept.charsets().should.eql(['*']);
+ var req = createRequest()
+ var accept = accepts(req)
+ assert.deepEqual(accept.charsets(), ['*'])
})
})
describe('when Accept-Charset is empty', function(){
it('should return an empty array', function(){
- var accept = accepts('');
- accept.charsets().should.eql([]);
+ var req = createRequest('')
+ var accept = accepts(req)
+ assert.deepEqual(accept.charsets(), [])
})
})
})
@@ -34,31 +33,43 @@ describe('accepts.charsets()', function(){
describe('when Accept-Charset is populated', function(){
describe('if any types match', function(){
it('should return the best fit', function(){
- var accept = accepts('utf-8, iso-8859-1;q=0.2, utf-7;q=0.5');
- accept.charsets('utf-7', 'utf-8').should.equal('utf-8');
+ var req = createRequest('utf-8, iso-8859-1;q=0.2, utf-7;q=0.5')
+ var accept = accepts(req)
+ assert.equal(accept.charsets('utf-7', 'utf-8'), 'utf-8')
})
})
describe('if no types match', function(){
it('should return false', function(){
- var accept = accepts('utf-8, iso-8859-1;q=0.2, utf-7;q=0.5');
- accept.charsets('utf-16').should.be.false;
+ var req = createRequest('utf-8, iso-8859-1;q=0.2, utf-7;q=0.5')
+ var accept = accepts(req)
+ assert.strictEqual(accept.charsets('utf-16'), false)
})
})
})
describe('when Accept-Charset is not populated', function(){
it('should return the first type', function(){
- var accept = accepts();
- accept.charsets('utf-7', 'utf-8').should.equal('utf-7');
+ var req = createRequest()
+ var accept = accepts(req)
+ assert.equal(accept.charsets('utf-7', 'utf-8'), 'utf-7')
})
})
})
describe('with an array', function(){
it('should return the best fit', function(){
- var accept = accepts('utf-8, iso-8859-1;q=0.2, utf-7;q=0.5');
- accept.charsets(['utf-7', 'utf-8']).should.equal('utf-8');
+ var req = createRequest('utf-8, iso-8859-1;q=0.2, utf-7;q=0.5')
+ var accept = accepts(req)
+ assert.equal(accept.charsets(['utf-7', 'utf-8']), 'utf-8')
})
})
-})
+})
+
+function createRequest(charset) {
+ return {
+ headers: {
+ 'accept-charset': charset
+ }
+ }
+}
View
@@ -1,65 +1,75 @@
-function accepts(encoding) {
- return require('../')({
- headers: {
- 'accept-encoding': encoding
- }
- })
-}
+var accepts = require('..')
+var assert = require('assert')
describe('accepts.encodings()', function(){
describe('with no arguments', function(){
describe('when Accept-Encoding is populated', function(){
it('should return accepted types', function(){
- var accept = accepts('gzip, compress;q=0.2');
- accept.encodings().should.eql(['gzip', 'compress', 'identity']);
- accept.encodings('gzip', 'compress').should.equal('gzip');
+ var req = createRequest('gzip, compress;q=0.2')
+ var accept = accepts(req)
+ assert.deepEqual(accept.encodings(), ['gzip', 'compress', 'identity'])
+ assert.equal(accept.encodings('gzip', 'compress'), 'gzip')
})
})
describe('when Accept-Encoding is not in request', function(){
it('should return identity', function(){
- var accept = accepts();
- accept.encodings().should.eql(['identity']);
- accept.encodings('gzip', 'deflate', 'identity').should.equal('identity');
+ var req = createRequest()
+ var accept = accepts(req)
+ assert.deepEqual(accept.encodings(), ['identity'])
+ assert.equal(accept.encodings('gzip', 'deflate', 'identity'), 'identity')
})
describe('when identity is not included', function(){
it('should return false', function(){
- var accept = accepts();
- accept.encodings('gzip', 'deflate').should.equal(false);
+ var req = createRequest()
+ var accept = accepts(req)
+ assert.strictEqual(accept.encodings('gzip', 'deflate'), false)
})
})
})
describe('when Accept-Encoding is empty', function(){
it('should return identity', function(){
- var accept = accepts('');
- accept.encodings().should.eql(['identity']);
- accept.encodings('gzip', 'deflate', 'identity').should.equal('identity');
+ var req = createRequest('')
+ var accept = accepts(req)
+ assert.deepEqual(accept.encodings(), ['identity'])
+ assert.equal(accept.encodings('gzip', 'deflate', 'identity'), 'identity')
})
describe('when identity is not included', function(){
it('should return false', function(){
- var accept = accepts('');
- accept.encodings('gzip', 'deflate').should.equal(false);
+ var req = createRequest('')
+ var accept = accepts(req)
+ assert.strictEqual(accept.encodings('gzip', 'deflate'), false)
})
})
})
})
describe('with multiple arguments', function(){
it('should return the best fit', function(){
- var accept = accepts('gzip, compress;q=0.2');
- accept.encodings('compress', 'gzip').should.eql('gzip');
- accept.encodings('gzip', 'compress').should.eql('gzip');
+ var req = createRequest('gzip, compress;q=0.2')
+ var accept = accepts(req)
+ assert.equal(accept.encodings('compress', 'gzip'), 'gzip')
+ assert.equal(accept.encodings('gzip', 'compress'), 'gzip')
})
})
describe('with an array', function(){
it('should return the best fit', function(){
- var accept = accepts('gzip, compress;q=0.2');
- accept.encodings(['compress', 'gzip']).should.eql('gzip');
+ var req = createRequest('gzip, compress;q=0.2')
+ var accept = accepts(req)
+ assert.equal(accept.encodings(['compress', 'gzip']), 'gzip')
})
})
-})
+})
+
+function createRequest(encoding) {
+ return {
+ headers: {
+ 'accept-encoding': encoding
+ }
+ }
+}
View
@@ -1,32 +1,30 @@
-function accepts(language) {
- return require('../')({
- headers: {
- 'accept-language': language
- }
- })
-}
+var accepts = require('..')
+var assert = require('assert')
describe('accepts.languages()', function(){
describe('with no arguments', function(){
describe('when Accept-Language is populated', function(){
it('should return accepted types', function(){
- var accept = accepts('en;q=0.8, es, pt');
- accept.languages().should.eql(['es', 'pt', 'en']);
+ var req = createRequest('en;q=0.8, es, pt')
+ var accept = accepts(req)
+ assert.deepEqual(accept.languages(), ['es', 'pt', 'en'])
})
})
describe('when Accept-Language is not in request', function(){
it('should return *', function(){
- var accept = accepts();
- accept.languages().should.eql(['*']);
+ var req = createRequest()
+ var accept = accepts(req)
+ assert.deepEqual(accept.languages(), ['*'])
})
})
describe('when Accept-Language is empty', function(){
it('should return an empty array', function(){
- var accept = accepts('');
- accept.languages().should.eql([]);
+ var req = createRequest('')
+ var accept = accepts(req)
+ assert.deepEqual(accept.languages(), [])
})
})
})
@@ -35,31 +33,43 @@ describe('accepts.languages()', function(){
describe('when Accept-Language is populated', function(){
describe('if any types types match', function(){
it('should return the best fit', function(){
- var accept = accepts('en;q=0.8, es, pt');
- accept.languages('es', 'en').should.equal('es');
+ var req = createRequest('en;q=0.8, es, pt')
+ var accept = accepts(req)
+ assert.equal(accept.languages('es', 'en'), 'es')
})
})
describe('if no types match', function(){
it('should return false', function(){
- var accept = accepts('en;q=0.8, es, pt');
- accept.languages('fr', 'au').should.be.false;
+ var req = createRequest('en;q=0.8, es, pt')
+ var accept = accepts(req)
+ assert.strictEqual(accept.languages('fr', 'au'), false)
})
})
})
describe('when Accept-Language is not populated', function(){
it('should return the first type', function(){
- var accept = accepts();
- accept.languages('es', 'en').should.equal('es');
+ var req = createRequest()
+ var accept = accepts(req)
+ assert.equal(accept.languages('es', 'en'), 'es')
})
})
})
describe('with an array', function(){
it('should return the best fit', function(){
- var accept = accepts('en;q=0.8, es, pt');
- accept.languages(['es', 'en']).should.equal('es');
+ var req = createRequest('en;q=0.8, es, pt')
+ var accept = accepts(req)
+ assert.equal(accept.languages(['es', 'en']), 'es')
})
})
-})
+})
+
+function createRequest(language) {
+ return {
+ headers: {
+ 'accept-language': language
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 2939dee

Please sign in to comment.