Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Replace date stubbing with library

  • Loading branch information...
commit a9ca5e164b5a8a48011b96200eb8ff3b24660f24 1 parent 831e15d
@benjreinhart benjreinhart authored
View
1  package.json
@@ -27,6 +27,7 @@
"chai": "~1.9"
, "co": "~3.0"
, "commonjs-everywhere": "~0.9"
+ , "frozen": "*"
, "globber": "~0.1"
, "jison": "~0.4"
, "mocha": "~1.18"
View
9 test/components/search/parser_test.js
@@ -2,16 +2,15 @@ require(require('path').join('..', '..', '..', 'core', 'globals'));
var expect = require('chai').expect
, parser = requireRoot('components/search/parser')
- , DateStubs = requireRoot('test/support/date_stubs')
- , stubDate = DateStubs.stubDate
- , unstubDate = DateStubs.unstubDate;
+ , freeze = require('frozen').freeze
+ , melt = require('frozen').melt;
describe('SearchParser', function(){
before(function(){
- stubDate(new Date('2014-04-10'));
+ freeze(new Date('2014-04-10'));
});
- after(unstubDate);
+ after(melt);
describe('`show[s]` command', function(){
describe('qualifiers', function() {
View
11 test/core/lib/utils/date_test.js
@@ -1,12 +1,13 @@
require(require('path').join('..', '..', '..', '..', 'core', 'globals'));
var expect = require('chai').expect
- , DateStubs = requireRoot('test/support/date_stubs')
- , stubDate = DateStubs.stubDate
- , unstubDate = DateStubs.unstubDate
+ , freeze = require('frozen').freeze
+ , melt = require('frozen').melt
, DateUtils = requireRoot('core/lib/utils/date');
describe('DateUtils', function(){
+ afterEach(melt);
+
describe('.isCanonicalDate', function(){
var isCanonicalDate = DateUtils.isCanonicalDate;
@@ -21,11 +22,9 @@ describe('DateUtils', function(){
describe('.canonicalDate', function(){
var canonicalDate = DateUtils.canonicalDate;
- afterEach(unstubDate);
-
context('without an argument', function(){
it('formats the current date as YYYY-MM-DD', function(){
- stubDate(new Date('2013-10-31'));
+ freeze(new Date('2013-10-31'));
expect(canonicalDate()).to.equal('2013-10-31');
});
});
View
42 test/support/date_stubs.js
@@ -1,42 +0,0 @@
-var canonicalDate = requireRoot('core/lib/utils/date').canonicalDate
- , originalDateConstructor = global.Date;
-
-exports.stubDate = function(date){
- global.Date = function(){
- if (!arguments.length)
- return copy(date);
-
- if (arguments[0].toString().length !== 4)
- return new originalDateConstructor(arguments[0]);
-
- return new originalDateConstructor(
- arguments[0],
- arguments[1] || 0,
- arguments[2] || 1,
- arguments[3] || 1,
- arguments[4] || 1,
- arguments[5] || 1,
- arguments[6] || 1
- );
- }
-
- Date.now = function(){
- return originalDateConstructor.parse(canonicalDate(date));
- }
-}
-
-exports.unstubDate = function(){
- global.Date = originalDateConstructor;
-};
-
-function copy(date){
- return new originalDateConstructor(
- date.getFullYear(),
- date.getMonth(),
- date.getDate(),
- date.getHours(),
- date.getMinutes(),
- date.getSeconds(),
- date.getMilliseconds()
- );
-}
Please sign in to comment.
Something went wrong with that request. Please try again.