Skip to content

Commit

Permalink
Move test-util, refactor tests to use getTypeExamples
Browse files Browse the repository at this point in the history
  • Loading branch information
robatron committed Jul 31, 2014
1 parent 9907206 commit d9ba355
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion test/add-subtask-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var _ = require( 'lodash' );
var should = require( 'should' );
var sinon = require( 'sinon' );
var pequire = require( 'proxyquire' );
var tutil = require( './test-util' );
var tutil = require( './lib/test-util' );

var HAPPY_PROXY_DEPS = {
path: { dirname: _.noop },
Expand Down
12 changes: 5 additions & 7 deletions test/get-subfiles-spec.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
var _ = require( 'lodash' );
var should = require( 'should' );
var sinon = require( 'sinon' );
var pequire = require( 'proxyquire' );
var tutil = require( './lib/test-util' );

var MODULE_PATH = '../lib/get-subfiles';

describe( 'get-subfiles', function () {

it( 'requires an array of file paths', function () {
var getSubfiles = require( MODULE_PATH );
var INVALID_VALUES = [ '', 0, 1, true, false, {}, { a: 'foo' }, null, undefined ];

// Assert we get an error for invalid values
INVALID_VALUES.forEach( function ( testValue ) {
getSubfiles.bind( null, testValue ).should.throw(
'An array of file paths is required.'
);
tutil.getTypeExamples( _.isArray ).forEach( function ( testValue ) {
getSubfiles.bind( null, testValue )
.should.throw( 'An array of file paths is required.' );
} );

// Assert we don't get an error for valid values
Expand Down
10 changes: 7 additions & 3 deletions test/test-util.js → test/lib/test-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ var _ = require( 'lodash' );
module.exports.getTypeExamples = function ( excludeFunc ) {

// Examples of each
var ALL_TYPES = [
var ALL_TYPE_EXAMPLES = [
'', 'a', 0, 1, false, true, {}, { a: 1 }, [], [ 'a' ], null, undefined
];

// If no exclusions, return all type examples
if ( _.isUndefined( excludeFunc ) || !_.isFunction( excludeFunc ) ) {
return ALL_TYPES;
return ALL_TYPE_EXAMPLES;
}

// Otherwise, remove the specified exclude type from the type examples
return _.remove( ALL_TYPES, function ( el ) { return !excludeFunc( el ) } );
var typeExamples = _.remove( ALL_TYPE_EXAMPLES, function ( el ) {
return !excludeFunc( el )
} );

return typeExamples
}
6 changes: 3 additions & 3 deletions test/load-subfile-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var _ = require( 'lodash' );
var should = require( 'should' );
var sinon = require( 'sinon' );
var pequire = require( 'proxyquire' ).noCallThru();
var tutil = require( './lib/test-util' );

var HAPPY_PROXY_DEPS = {
gulp: {
Expand Down Expand Up @@ -30,15 +31,14 @@ describe( 'load-subfile', function () {

it( 'errors if the task registry is not an object', function () {
var loadSubfile = getLoad();
var INVALID_VALUES = [ '', 0, 1, true, false, [], null, undefined ];
INVALID_VALUES.forEach( function ( testTasksParam ) {
tutil.getTypeExamples( _.isPlainObject ).forEach( function ( testTasksParam ) {
loadSubfile.bind( null, null, testTasksParam ).should.throw( '`task` must be an object' );
} );
} );

xit( 'loads the specified file', function () {
var pdeps = { 'abs-path': _.noop };
var loadSubfile = getLoad( pdeps );
loadSubfile( { absolutePath: 'abs-path' }, {} )
loadSubfile( { absolutePath: 'abs-path' }, {} );
} );
} );

0 comments on commit d9ba355

Please sign in to comment.