lus I see a number of places on the web where the idea is mentioned,
e.g. http://www.herrodius.com/blog/?m=200704 . However I cannot find
any mock frameworks for AS3.
This evening I spent some time trying to mock one up on my own (ok,
sorry for the pun!) but I ran into troubles. Is anyone interested in
thinking about this problem with me?
Here is what I did during my 20 minutes of playing:
Define an interface:
public interface TestInterface
{
function setSomething(something : String) : void;
}
Run the following code:
public function flexmock() {
var i : TestInterface;
var c : Class =
flash.utils.getDefinitionByName("attempt.TestInterface") as Class;
var desc : XML = flash.utils.describeType(c);
var str : String = desc.toString();
var a : Object = new Object();
a["setSomething"] = function(something : String) : void
{
trace(something); };
// will fail on the following line, since a does not
implement
TestInterface.
i = TestInterface(a);
i.setSomething("blah");
}
AS3 doesn't support duck typing like Ruby, and I believe there is no
way to get an object in memory that implements the TestInterface
interface that my other objects can use as a mock.
Any thoughts about this? Am I doomed to use elbow grease or code
generation to create these things?
BTW, this message is also posted on the ActionScript 3 FlexUnit
Library forum in Google Groups. Hopefully that isn't some kind of
forum faux pas.
Thank you for any comments,
Adam