Skip to content

strict expect() bug #54

@jbarrus

Description

@jbarrus

This is a pretty far out edge case, but there exists a problem with an expectation being carried over from one test to another. Here's an example test case. testStrictBug2 will fail with "examples::Engine<"niceEngine">#talk(ANYTHING,an instance of String)".

If the order is reversed, both of the tests below will succeed.

I found this while doing some experimentation with times(). I was surprised to find out that with a nice, .times() will not cause verification to fail if the expected method was called too many times. It appears that verification that something was called the correct number of times can only be done with a strict or with a test spy (received()).

Also, it had not occurred to me that expect() would not work with a strict. This is actually what led me to discover this bug.

package flexUnitTests
{
    import examples.Engine;

    import mockolate.arg;
    import mockolate.expect;
    import mockolate.runner.MockolateRule;
    import mockolate.strict;

    import org.hamcrest.core.anything;
    import org.hamcrest.object.instanceOf;

    public class StrictBugTestCase
    {
        [Rule]
        public var mockolate:MockolateRule = new MockolateRule();

        [Mock(type="nice")]
        public var niceEngine:Engine;

        [Test(order="1", expects="mockolate.errors.InvocationError")]
        public function testStrictBug1():void
        {
            var strictEngine:Engine = strict( Engine );

            expect( strictEngine.talk( arg( anything() )));
        }

        [Test(order="2")]
        public function testStrictBug2():void
        {
            expect( niceEngine.talk( arg( instanceOf( String ))));

            niceEngine.talk( "test" );
        }
    }
}
package examples
{
    public class Engine
    {
        public function talk( words:String ):void
        {
            trace( words );
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions