From df74e3b52caf42ae9f8439a92694c7c36a7a827c Mon Sep 17 00:00:00 2001 From: George Cook Date: Wed, 20 May 2020 11:30:42 -0500 Subject: [PATCH] fix(mocks): Better handling for mock creation failures --- src/BaseTestSuite.bs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/BaseTestSuite.bs b/src/BaseTestSuite.bs index a5a811cc..aec5d74c 100644 --- a/src/BaseTestSuite.bs +++ b/src/BaseTestSuite.bs @@ -1458,21 +1458,23 @@ end function public function Mock(target, methodName, expectedInvocations = 1, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false, lineNumber = -1) as object 'check params if not RBS_CMN.IsAssociativeArray(target) - m.Fail("mock args: target was not an AA") + methodName = "" + m.MockFail(lineNumber, "", "mock args: target was not an AA") else if not RBS_CMN.IsString(methodName) - m.Fail("mock args: methodName was not a string") + methodName = "" + m.MockFail(lineNumber, "", "mock args: methodName was not a string") else if not RBS_CMN.IsNumber(expectedInvocations) - m.Fail("mock args: expectedInvocations was not an int") + m.MockFail(lineNumber, methodName, "mock args: expectedInvocations was not an int") else if not RBS_CMN.IsArray(expectedArgs) and RBS_CMN.IsValid(expectedArgs) - m.Fail("mock args: expectedArgs was not invalid or an array of args") + m.MockFail(lineNumber, methodName, "mock args: expectedArgs was not invalid or an array of args") else if RBS_CMN.IsUndefined(expectedArgs) - m.Fail("mock args: expectedArgs undefined") + m.MockFail(lineNumber, methodName, "mock args: expectedArgs undefined") else if RBS_CMN.IsUndefined(returnValue) - m.Fail("mock args: returnValue undefined") + m.MockFail(lineNumber, methodName, "mock args: returnValue undefined") end if if m.currentResult.isFail - ? "ERROR: "; m.currentResult.messages[m.currentResult.currentAssertIndex - 1] + ? "ERROR! Cannot create MOCK. method " ; methodName ;" " str(lineNumber) ; " "; m.currentResult.messages.peek() return {} end if