0 Replies Latest reply: Apr 3, 2011 9:54 AM by JonnyReeves RSS

    Eventual Async Assertions

    JonnyReeves Community Member

      Hi All,

       

      I've been playing around with the idea of EventualMatchers from Specs (a testing framework written in Scala) that allow you to write assertions that will be evaluated continuously until it is true, or a timeout value is reached.

       

      I've written a blog post which goes into a bit more detail; but in summary, it allows you to write code like this:

       

      [Test (async)]
      public function spriteTweensToTargetPosition() : void
      {
              const shape : MovingShape = new MovingShape();
              const expectedPosition : Point = new Point(300, 200);
              
              shape.tweenTo(expectedPosition);
      
              assertEventuallyEquals(this, "Shape is at the expected x position", expectedPosition.x, function() : * { 
                      return shape.x; 
              });
              assertEventuallyEquals(this, "Shape is at the expected y position", expectedPosition.y, function() : * { 
                      return shape.y; 
              });
      }
      

       

      I'm not totally happy with the syntax, mainly because of the clunky way we have to write closures in ActionScript, but I thought I would share it with everyone to see what they thought?  I've pushed the code to a github branch which is over here:

       

      Thanks

      jonny.