From fda002d252fab6aae748c6ad956d24839f926da4 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Thu, 3 Nov 2011 23:20:45 -0400 Subject: [PATCH] [#25] Added tests to ensure proper data is passed to validateMethod() --- test/MemberBuilder/MethodTest.js | 105 +++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/test/MemberBuilder/MethodTest.js b/test/MemberBuilder/MethodTest.js index d27a1a8..d025f51 100644 --- a/test/MemberBuilder/MethodTest.js +++ b/test/MemberBuilder/MethodTest.js @@ -24,6 +24,55 @@ require( 'common' ).testCase( { + caseSetUp: function() + { + var _self = this; + + this.testArgs = function( args, name, value, keywords ) + { + var pub = _self.members[ 'public' ], + + // prev data + pval_expect = null, + pkeywords_expect = null, + pval_given = null, + pkeywords_given = null + ; + + if ( pub[ name ] ) + { + pval_expect = pub[ name ]; + pkeywords_expect = pval_expect.___$$keywords$$; // XXX + + pval_given = args[ 3 ].member; + pkeywords_given = args[ 4 ]; + } + + _self.assertEqual( name, args[ 0 ], + 'Incorrect name passed to method validator' + ); + + _self.assertStrictEqual( value, args[ 1 ], + 'Incorrect value passed to method validator' + ); + + _self.assertStrictEqual( keywords, args[ 2 ], + 'Incorrect keywords passed to method validator' + ); + + _self.assertStrictEqual( pval_expect, pval_given, + 'Previous data should contain prev value if overriding, ' + + 'otherwise null' + ); + + _self.assertStrictEqual( pkeywords_expect, pkeywords_given, + 'Previous keywords should contain prev keyword if ' + + 'overriding, otherwise null' + ); + }; + }, + + setUp: function() { // stub factories used for testing @@ -38,4 +87,60 @@ require( 'common' ).testCase( this.members = this.sut.initMembers(); }, + + + /** + * The validator can only do its job if we're providing it with the correct + * information + */ + 'Passes proper data to validator when not overriding': function() + { + var _self = this, + called = false, + + name = 'foo', + value = function() {}, + keywords = {} + ; + + this.mockValidate.validateMethod = function() + { + called = true; + _self.testArgs( arguments, name, value, keywords ); + }; + + this.sut.buildMethod( + this.members, {}, name, value, keywords, function() {}, 1, {} + ); + + this.assertEqual( true, called, 'validateMethod() was not called' ); + }, + + + 'Passes proper data to validator when overriding': function() + { + var _self = this, + called = false, + + name = 'foo', + value = function() {}, + keywords = { 'override': true } + ; + + // since we're overriding + ( this.members[ 'public' ].foo = function() {} ).___$$keywords$$ = + { 'public': true }; + + this.mockValidate.validateMethod = function() + { + called = true; + _self.testArgs( arguments, name, value, keywords ); + }; + + this.sut.buildMethod( + this.members, {}, name, value, keywords, function() {}, 1, {} + ); + + this.assertEqual( true, called, 'validateMethod() was not called' ); + }, } );