From 5e46298e39eb6e607eb2ab5b84fabe411dea5273 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sun, 23 Oct 2011 00:27:25 -0400 Subject: [PATCH] [#25] Moved MemberBuilderValidator's quickFailureTest into its own file to share with upcoming property tests --- test/MemberBuilderValidator/MethodTest.js | 29 +--------- test/MemberBuilderValidator/inc-common.js | 69 +++++++++++++++++++++++ 2 files changed, 71 insertions(+), 27 deletions(-) create mode 100644 test/MemberBuilderValidator/inc-common.js diff --git a/test/MemberBuilderValidator/MethodTest.js b/test/MemberBuilderValidator/MethodTest.js index 2f4203a..163c19f 100644 --- a/test/MemberBuilderValidator/MethodTest.js +++ b/test/MemberBuilderValidator/MethodTest.js @@ -80,33 +80,8 @@ require( 'common' ).testCase( }; - this.quickFailureTest = function( name, identifier, action ) - { - _self.incAssertCount(); - - try - { - action(); - } - catch ( e ) - { - // using the identifier, ensure the error string makes sense - _self.assertOk( ( e.message.search( identifier ) !== -1 ), - "Incorrect error; expected identifier '" + identifier + - "', but received: " + e.message - ); - - // to aid in debugging, the error message should contain the - // name of the method - _self.assertOk( ( e.message.search( name ) !== -1 ), - 'Error message should contain method name' - ); - - return; - } - - _self.fail( "Expected failure" ); - }; + this.quickFailureTest = require( __dirname + '/inc-common' ) + .quickFailureTest; this.quickVisChangeTest = function( start, override, failtest ) diff --git a/test/MemberBuilderValidator/inc-common.js b/test/MemberBuilderValidator/inc-common.js new file mode 100644 index 0000000..d7d7b41 --- /dev/null +++ b/test/MemberBuilderValidator/inc-common.js @@ -0,0 +1,69 @@ +/** + * Shared functions for MemberBuilderValidator tests + * + * Copyright (C) 2010 Mike Gerwitz + * + * This file is part of ease.js. + * + * ease.js is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * @author Mike Gerwitz + * @package test + */ + + +/** + * Quickly tests for validation failures + * + * The following will be ensured by this assertion: + * - An exception must be thrown + * - The exception message must contain the name of the member + * - The exception message must contain the identifier string + * + * @param {string} name name expected in error string + * @param {string} identifier string to match in error message + * + * @param {function()} action function to invoke for test + * + * @return {undefined} + */ +exports.quickFailureTest = function( name, identifier, action ) +{ + var _self = this; + + _self.incAssertCount(); + + try + { + action(); + } + catch ( e ) + { + // using the identifier, ensure the error string makes sense + _self.assertOk( ( e.message.search( identifier ) !== -1 ), + "Incorrect error; expected identifier '" + identifier + + "', but received: " + e.message + ); + + // to aid in debugging, the error message should contain the + // name of the method + _self.assertOk( ( e.message.search( name ) !== -1 ), + 'Error message should contain method name' + ); + + return; + } + + _self.fail( "Expected failure" ); +};