Skip to content

Instantly share code, notes, and snippets.

@drewbourne
Created June 21, 2011 03:30
Show Gist options
  • Save drewbourne/1037188 to your computer and use it in GitHub Desktop.
Save drewbourne/1037188 to your computer and use it in GitHub Desktop.
Mockolate FlexUnit Setup Examples
package example
{
import flash.events.Event;
import mockolate.mock;
import mockolate.nice;
import mockolate.prepare;
import org.flexunit.assertThat;
import org.flexunit.async.Async;
import org.hamcrest.object.isTrue;
public class CreateMockolatesManually
{
public var myClass:MyClass;
[Before(async, order=1)]
public function prepareMockClasses():void
{
Async.proceedOnEvent(this, prepare(MyClass), Event.COMPLETE);
}
[Before(order=2)]
public function setup():void
{
myClass = nice(MyClass);
}
[Test]
public function myClass_shouldDoSomething():void
{
mock(myClass).method("doSomething").returns(true);
assertThat(myClass.doSomething(), isTrue());
}
}
}
package example
{
import mockolate.mock;
import mockolate.runner.MockolateRule;
import org.flexunit.assertThat;
import org.hamcrest.object.isTrue;
public class CreateMockolatesUsingRule
{
[Rule]
public var mocks:MockolateRule = new MockolateRule();
[Mock]
public var myClass:MyClass;
[Test]
public function myClass_shouldDoSomething():void
{
mock(myClass).method("doSomething").returns(true);
assertThat(myClass.doSomething(), isTrue());
}
}
}
package example
{
import mockolate.mock;
import mockolate.runner.MockolateRunner;
import org.flexunit.assertThat;
import org.hamcrest.object.isTrue;
MockolateRunner;
[RunWith("mockolate.runner.MockolateRunner")]
public class CreateMockolatesUsingRunner
{
[Mock]
public var myClass:MyClass;
[Test]
public function myClass_shouldDoSomething():void
{
mock(myClass).method("doSomething").returns(true);
assertThat(myClass.doSomething(), isTrue());
}
}
}
package example
{
public class MyClass
{
public function MyClass()
{
super();
}
public function doSomething():Boolean
{
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment