[mockbox 2.2] mock methods which use inbuilt method names

Hi,

Consider that you have some code like this:

function hasVerifiedLocale(){
local.locale = mycollaborator.getLocale();
return !isnull(local.locale)
}

getLocale is an in-built function name in ColdFusion but as it’s namespaced it is fine to use here. If I try and mock that method using mockbox like so:

function test_hasVerifiedLocale(){
local.mocked = mockbox.createStub().$(“getLocale”, “en-GB”);
CUT.setMyCollaborator(local.mocked);
assertTrue(CUT. hasVerifiedLocale());
}

I get this error (on ACF 9.0.2) :

Template: The names of user-defined functions cannot be the same as built-in ColdFusion functions. The name getLocale is the name of a built-in ColdFusion function.

I can do it with mightymock and MXUnit like so:

function test_hasVerifiedLocale(){
local.mocked = mock().getLocale().returns(“en-GB”);
CUT.setMyCollaborator(local.mocked);
assertTrue(CUT. hasVerifiedLocale());
}

but I’d rather not mix mocking frameworks.

Thanks,

John

Does anyone have any thoughts on my post below for mocking methods that are named after in-built CFML functions?

Also, I had someone ask me an interesting question, the other day. What he wanted to do was get mockbox to throw and exception based on argument matching. So something like:

$(“foo”)
.$args(1).returns(“one”)
.$args(2).returns(“two”)
.$args(2.5).returns(some exception thrown here)
.$args(3).returns(“three”)

Is that possible?

Thanks,

John

Hi John. What version are you using?
I swore I resolved the built in udf issue

As for the throw according to argument matching, I don’t think so but it should be easy to add. Can you make a ticket for that.

Luis

Hi Luis,

Thanks for the reply - hope you had a good holiday :slight_smile:

I’m using mockbox 2.2.0.00058. This test throws the error.

function test_mockbox(){
local.mocked = mockbox.createStub().$(“getLocale”, “en-GB”);
assertEquals(“en-GB”, local.mocked.getLocale());
}

Thanks,

John

Fixed

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Awesome - thanks Luis :slight_smile: