Hi guys,
Is it possible to mock arguments by type?
For example I’d like to be able to write a test like this:
function test_mockbox_passes(){
_getMockBox().prepareMock(this);
this.$(“foo”).$args(1).$results(“one”);
this.$(“foo”).$args(2).$results(“two”);
assertEquals(“one”, foo(1));
assertEquals(“two”, foo(2));
}
function test_mockbox_fails(){
_getMockBox().prepareMock(this);
this.$(“foo”).$args(1, this).$results(“one”);
this.$(“foo”).$args(2, this).$results(“two”);
assertEquals(“one”, foo(1, this));
assertEquals(“two”, foo(2, this));
}
function test_mockbox_would_be_useful(){
_getMockBox().prepareMock(this);
this.$(“foo”).$args(1, ‘{any}’).$results(“one”);
this.$(“foo”).$args(2, ‘{any}’).$results(“two”);
assertEquals(“one”, foo(1, this));
assertEquals(“two”, foo(2, this));
}
On Mockbox 2.2 only the 1st test passes.
Thanks!
John
This fails:
function test_mockbox_fails(){
_getMockBox().prepareMock(this);
this.$(“foo”).$args(1, this).$results(“one”);
this.$(“foo”).$args(2, this).$results(“two”);
assertEquals(“one”, foo(1, this));
assertEquals(“two”, foo(2, this));
}
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
Hi Luis,
Sorry - I didn’t make myself very clear. I was expecting that code to work, but it fails. I just used ‘this’ in the example to make it easy to “copy/paste and run”.
Originally I was hoping to use argument type matching - like MightyMock does:
Then I tried using a mock for the second argument, but got undefined errors. I hope that makes a bit more sense?
Thanks,
John
Sorry John,
Revisiting this now. As of now, MockBox does not support type matching, do you think this is a necessary addition when the arguments could potentially be anything in ColdFusion?
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
Yeah I think this will be a tough one to implement, my question would be this. As ColdFusion is cough typeless, then this would make this rather hard. especially how would you handle how ColdFusion can send extra arguments to the method / function as well (Which I personally don’t like about ColdFusion).
I am not sure what it was you are actually testing there, with which I am guessing that the second argument is optional, which would make it even hard to.
Could you describe what it is you are actually trying to test for?