Permalink
Browse files

Migrate functions test to buster.

  • Loading branch information...
cliffano committed Feb 13, 2013
1 parent f993ced commit 9da7d03780298a6bb100150b437ccffa49002b6f
Showing with 79 additions and 122 deletions.
  1. +79 −122 test/functions.js
View
@@ -1,137 +1,94 @@
-/*
var bag = require('bagofholding'),
- sandbox = require('sandboxed-module'),
- should = require('should'),
- checks, mocks,
- functions;
-
-describe('functions', function () {
-
- function create(checks, mocks) {
- return sandbox.require('../lib/functions', {
- requires: mocks ? mocks.requires : {},
- globals: {
- Date: function () {
- return new Date(2000, 9, 10); // NOTE: 0-based month, so 10 Oct 2000
- }
- }
+ functions = require('../lib/functions');
+
+buster.testCase('functions - date', {
+ setUp: function () {
+ this.useFakeTimers(new Date(2000, 9, 10).getTime());
+ },
+ 'should return formatted date when format is specified': function (done) {
+ var funcs = functions('somepage', {}, {});
+ funcs.date('yyyymmdd', function (data) {
+ assert.equals(data, '20001010');
+ done();
});
- }
-
- beforeEach(function () {
- checks = {};
- mocks = {};
- });
-
- describe('date', function () {
-
- it('should return formatted date when format is specified', function (done) {
- functions = (create(checks, mocks))('somepage', {}, {});
- functions.date('yyyymmdd', function (data) {
- checks.data = data;
- done();
- });
- checks.data.should.equal('20001010');
+ },
+ 'should return date with default format when format is not specified': function (done) {
+ var funcs = functions('somepage', {}, {});
+ funcs.date(undefined, function (data) {
+ assert.equals(data, '2000-10-10T00:00:00');
+ done();
});
+ }
+});
- it('should return date with default format when format is not specified', function (done) {
- functions = (create(checks, mocks))('somepage', {}, {});
- functions.date(undefined, function (data) {
- checks.data = data;
- done();
- });
- checks.data.should.equal('2000-10-10T00:00:00');
- });
- });
-
- describe('include', function () {
-
- it('should return partial template when partial exists', function (done) {
- functions = (create(checks, mocks))('somepage', {}, {});
- functions.include('somepartial', function (data) {
- checks.data = data;
- done();
- });
- checks.data.should.equal('[error] partial somepartial does not exist');
+buster.testCase('functions - include', {
+ 'should return partial template when partial exists': function (done) {
+ var funcs = functions('somepage', {}, {});
+ funcs.include('somepartial', function (data) {
+ assert.equals(data, '[error] partial somepartial does not exist');
+ done();
});
-
- it('should return error message when partial does not exist', function (done) {
- functions = (create(checks, mocks))('somepage', {}, { partials: { somepartial: 'foobar' } });
- functions.include('somepartial', function (data) {
- checks.data = data;
- done();
- });
- checks.data.should.equal('foobar');
+ },
+ 'should return error message when partial does not exist': function (done) {
+ var funcs = functions('somepage', {}, { partials: { somepartial: 'foobar' } });
+ funcs.include('somepartial', function (data) {
+ assert.equals(data, 'foobar');
+ done();
});
- });
-
- describe('relative', function () {
+ }
+});
- it('should return path when page is at the project root directory', function (done) {
- functions = (create(checks, mocks))('homepage.html', {}, {});
- functions.relative('somepage.html', function (data) {
- checks.data = data;
- done();
- });
- checks.data.should.equal('somepage.html');
+buster.testCase('functions - relative', {
+ 'should return path when page is at the project root directory': function (done) {
+ var funcs = functions('homepage.html', {}, {});
+ funcs.relative('somepage.html', function (data) {
+ assert.equals(data, 'somepage.html');
+ done();
});
-
- it('should return a single upper directory when page is at a project subdirectory', function (done) {
- functions = (create(checks, mocks))('foo/homepage.html', {}, {});
- functions.relative('somepage.html', function (data) {
- checks.data = data;
- done();
- });
- checks.data.should.equal('../somepage.html');
+ },
+ 'should return a single upper directory when page is at a project subdirectory': function (done) {
+ var funcs = functions('foo/homepage.html', {}, {});
+ funcs.relative('somepage.html', function (data) {
+ assert.equals(data, '../somepage.html');
+ done();
});
-
- it('should return multiple upper directories when page is at several directories deep below project directory', function (done) {
- functions = (create(checks, mocks))('foo/bar/homepage.html', {}, {});
- functions.relative('somepage.html', function (data) {
- checks.data = data;
- done();
- });
- checks.data.should.equal('../../somepage.html');
+ },
+ 'should return multiple upper directories when page is at several directories deep below project directory': function (done) {
+ var funcs = functions('foo/bar/homepage.html', {}, {});
+ funcs.relative('somepage.html', function (data) {
+ assert.equals(data, '../../somepage.html');
+ done();
});
-
- it('should return multiple upper directories when page and path are both at several directories deep below project directory', function (done) {
- functions = (create(checks, mocks))('foo/bar/homepage.html', {}, {});
- functions.relative('abc/xyz/somepage.html', function (data) {
- checks.data = data;
- done();
- });
- checks.data.should.equal('../../abc/xyz/somepage.html');
+ },
+ 'should return multiple upper directories when page and path are both at several directories deep below project directory': function (done) {
+ var funcs = functions('foo/bar/homepage.html', {}, {});
+ funcs.relative('abc/xyz/somepage.html', function (data) {
+ assert.equals(data, '../../abc/xyz/somepage.html');
+ done();
});
- });
-
- describe('title', function () {
+ }
+});
- it('should return title when file exists in sitemap and it has a title', function (done) {
- functions = (create(checks, mocks))('somepage.html', {}, { sitemap: { 'somepage.html': { title: 'foobar' } } });
- functions.title(function (data) {
- checks.data = data;
- done();
- });
- checks.data.should.equal('foobar');
+buster.testCase('functions - title', {
+ 'should return title when file exists in sitemap and it has a title': function (done) {
+ var funcs = functions('somepage.html', {}, { sitemap: { 'somepage.html': { title: 'foobar' } } });
+ funcs.title(function (data) {
+ assert.equals(data, 'foobar');
+ done();
});
-
- it('should return undefined when file exists in sitemap but it does not have a title', function (done) {
- functions = (create(checks, mocks))('somepage.html', {}, { sitemap: { 'somepage.html': {} } });
- functions.title(function (data) {
- checks.data = data;
- done();
- });
- should.not.exist(checks.data);
+ },
+ 'should return undefined when file exists in sitemap but it does not have a title': function (done) {
+ var funcs = functions('somepage.html', {}, { sitemap: { 'somepage.html': {} } });
+ funcs.title(function (data) {
+ assert.equals(data, undefined);
+ done();
});
-
- it('should return error message when file does not exist in sitemap', function (done) {
- functions = (create(checks, mocks))('somepage.html', {}, {});
- functions.title(function (data) {
- checks.data = data;
- done();
- });
- checks.data.should.equal('[error] page somepage.html does not have any sitemap title');
+ },
+ 'should return error message when file does not exist in sitemap': function (done) {
+ var funcs = functions('somepage.html', {}, {});
+ funcs.title(function (data) {
+ assert.equals(data, '[error] page somepage.html does not have any sitemap title');
+ done();
});
- });
-});
-*/
+ }
+});

0 comments on commit 9da7d03

Please sign in to comment.