drewbourne / mockolate

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

Partial mocks throw error when an unstubbed getter returning Vector is called #67

Open ericklaus-wf opened 11 years ago

ericklaus-wf commented 11 years ago

Only unstubbed properties exhibit this bug. Methods and stubbed properties can be retrieved as expected.

The failing unit test will throw "Error #1065: Variable AS3vec::Vector. is not defined."

public class PartialMockVectorError
{
    [Rule]
    public var mocks:MockolateRule = new MockolateRule();

    [Mock(type="partial")]
    public var vectorWrapper:ClassWithVector;

    [Test]
    public function testShouldGetVector():void
    {
        //fails
        vectorWrapper.someList;
    }

    [Test]
    public function testStubbedPropertyShouldGetVector():void
    {
        //passes
        var vector:Vector.<String> = new Vector.<String>();
        stub(vectorWrapper).getter("someList").returns(vector);
        assertTrue(vectorWrapper.someList === vector);
    }

    [Test]
    public function testMethodShouldGetVector():void
    {
        //passes
        vectorWrapper.retrieveSomeList();
    }
}

public class ClassWithVector
{

    private var _someList:Vector.<String>;

    public function ClassWithVector():void
    {
        _someList = new Vector.<String>();
    }

    public function get someList():Vector.<String>
    {
        return _someList;
    }

    public function set someList(value:Vector.<String>):void
    {
        _someList = value;
    }

    public function retrieveSomeList():Vector.<String>
    {
        return _someList;
    }
}