1
0
Fork 0

[#25] Moved quick keyword validation into shared MemberBuilderValidator test module

closure/master
Mike Gerwitz 2011-10-23 01:11:09 -04:00
parent a91cb01998
commit 6fc3d05166
2 changed files with 60 additions and 49 deletions

View File

@ -22,66 +22,24 @@
* @package test * @package test
*/ */
var shared = require( __dirname + '/inc-common' );
require( 'common' ).testCase( require( 'common' ).testCase(
{ {
caseSetUp: function() caseSetUp: function()
{ {
var _self = this; var _self = this;
/**
* Tests to ensure that a method with the given keywords fails
* validation with an error message partially matching the provided
* identifier
*
* To test overrides, specify keywords for 'prev'. To test for success
* instead of failure, set identifier to null.
*/
this.quickKeywordMethodTest = function( keywords, identifier, prev ) this.quickKeywordMethodTest = function( keywords, identifier, prev )
{ {
var keyword_obj = {}, shared.quickKeywordTest.call( this,
prev_obj = {}, 'validateMethod', keywords, identifier, prev
prev_data = {}, );
name = 'fooBar';
// convert our convenient array into a keyword obj
for ( var i = 0, len = keywords.length; i < len; i++ )
{
keyword_obj[ keywords[ i ] ] = true;
}
// if prev keywords were given, do the same thing with those to
// generate our keyword obj
if ( prev !== undefined )
{
for ( var i = 0, len = prev.length; i < len; i++ )
{
prev_obj[ prev[ i ] ] = true;
}
// define a dummy previous method value
prev_data = { member: function() {} };
}
var testfunc = function()
{
_self.sut.validateMethod(
name, function() {}, keyword_obj, prev_data, prev_obj
);
};
if ( identifier )
{
_self.quickFailureTest( name, identifier, testfunc );
}
else
{
_self.assertDoesNotThrow( testfunc, Error );
}
}; };
this.quickFailureTest = require( __dirname + '/inc-common' ) this.quickFailureTest = shared.quickFailureTest;
.quickFailureTest;
this.quickVisChangeTest = function( start, override, failtest ) this.quickVisChangeTest = function( start, override, failtest )

View File

@ -67,3 +67,56 @@ exports.quickFailureTest = function( name, identifier, action )
_self.fail( "Expected failure" ); _self.fail( "Expected failure" );
}; };
/**
* Tests to ensure that a member with the given keywords fails validation with
* an error message partially matching the provided identifier
*
* To test overrides, specify keywords for 'prev'. To test for success instead
* of failure, set identifier to null.
*/
exports.quickKeywordTest = function( type, keywords, identifier, prev )
{
var keyword_obj = {},
prev_obj = {},
prev_data = {},
name = 'fooBar',
_self = this;
// convert our convenient array into a keyword obj
for ( var i = 0, len = keywords.length; i < len; i++ )
{
keyword_obj[ keywords[ i ] ] = true;
}
// if prev keywords were given, do the same thing with those to
// generate our keyword obj
if ( prev !== undefined )
{
for ( var i = 0, len = prev.length; i < len; i++ )
{
prev_obj[ prev[ i ] ] = true;
}
// define a dummy previous method value
prev_data = { member: function() {} };
}
var testfunc = function()
{
_self.sut[ type ](
name, function() {}, keyword_obj, prev_data, prev_obj
);
};
if ( identifier )
{
_self.quickFailureTest( name, identifier, testfunc );
}
else
{
_self.assertDoesNotThrow( testfunc, Error );
}
};