drewbourne / mockolate

fake chocolate, mock objects and test spies for AS3
http://mockolate.org/
MIT License
145 stars 27 forks source link

Creating any mocks throws InstanceRecipeBuilder.withClassRecipe #68

Open BlueRaja opened 10 years ago

BlueRaja commented 10 years ago

Using the prebuilt Mockolate v0.12.4 from here, and the latest version of FlexUnit that comes with FlashBuilder Professional (FlexUnit 4.1 I think).

My code looks like this:

package MyTestPackage
{
    import com.my.site.MyClass;
    import flash.events.Event;
    import mockolate.*;
    import org.flexunit.Assert;
    import org.flexunit.async.Async;

    public class MyClassTests
    {
        [Before(async, timeout = 5000)]
        public function prepareMockolates():void
        {
            Async.proceedOnEvent(this,
                prepare(MyClass),
                Event.COMPLETE);
        }

        [Test]
        public function mocksWorkTest():void
        {
            var myClass:MyClass = strict(MyClass);
            //The above line throws an exception, so what I put here doesn't matter
        }
    }
}

The line

var myClass:MyClass = strict(MyClass);

throws an exception

Error: InstanceRecipeBuilder.withClassRecipe
at mockolate.ingredients::InstanceRecipeBuilder/withClassRecipe(InstanceRecipeBuilder.as:21)
at mockolate.ingredients::Mockolatier/mockolate.ingredients.only::createInstanceRecipeFor(Mockolatier.as:183)
at mockolate.ingredients::Mockolatier/strict(Mockolatier.as:167)
at global/mockolate::strict(strict.as:28)
**[ at MyTestPackage::MyClassTests/mocksWorkTest(MyClassTests.as:22) ]
at Function/http://adobe.com/AS3/2006/builtin::apply
at flex.lang.reflect::Method/apply(Method.as:244)
at org.flexunit.runners.model::FrameworkMethod/invokeExplosively(FrameworkMethod.as:201)
at org.flexunit.internals.runners.statements::InvokeMethod/evaluate(InvokeMethod.as:72)
at org.flexunit.internals.runners.statements::RunBeforesInline/handleSequenceExecuteComplete(RunBeforesInline.as:112)
at org.flexunit.token::AsyncTestToken/sendResult(AsyncTestToken.as:107)
at org.flexunit.internals.runners.statements::AsyncStatementBase/sendComplete(AsyncStatementBase.as:76)
at org.flexunit.internals.runners.statements::StatementSequencer/sendComplete(StatementSequencer.as:172)
at org.flexunit.internals.runners.statements::StatementSequencer/handleChildExecuteComplete(StatementSequencer.as:145)
at org.flexunit.token::AsyncTestToken/sendResult(AsyncTestToken.as:107)
at org.flexunit.internals.runners.statements::ExpectAsync/sendComplete(ExpectAsync.as:560)
at org.flexunit.internals.runners.statements::ExpectAsync/handleAsyncEventFired(ExpectAsync.as:431)
at flash.events::EventDispatcher/dispatchEventFunction
at flash.events::EventDispatcher/dispatchEvent
at org.flexunit.async::AsyncHandler/handleEvent(AsyncHandler.as:156)
at flash.events::EventDispatcher/dispatchEventFunction
at flash.events::EventDispatcher/dispatchEvent
at Function/http://adobe.com/AS3/2006/builtin::apply
at SetIntervalTimer/onTimer
at flash.utils::Timer/_timerDispatch
at flash.utils::Timer/tick

The same thing happens when using nice().

If I create mocked fields using MockolateRule everything works perfectly, but of course that greatly reduces the flexibility of my tests, since I can no longer create mocks within the tests.

Does anyone know why this is happening or how to fix it?

mikecann commented 9 years ago

Did you ever solve this? Im having the same problem.

BlueRaja commented 9 years ago

No, the framework is broken and apparently no one cares about it.

mikecann commented 9 years ago

Ahh damn :( Some of us still have legacy projects to maintain!

mikecann commented 9 years ago

I believe it is to do with trying to mock concrete classes instead of interfaces. If the concrete class throws an error in the constructor then you get this error.

mikecann commented 9 years ago

Scratch all that, the problem was simply because I forgot to prepare on of the dependencies, doh!