Wiki

Clone wiki

morefluent / MoreFluentApi

API

The api consists of 3 core functionalities:

Polling assertion

Polling assertion examines given condition periodically until it is met or the timeout occurs.

//polling assertion with equals()
poll().assert(timer, "currentCount").equals(1);

//polling assertion with custom timeout
poll(2000).assert(timer, "currentCount").equals(1);

Asserting synchronuosly

If the assertion needs to be done after some asynchronous event you simply instruct what event should precede the assertion.

//asserting after event
after(SomeEvent.COMPLETE).on(someObject).assert(someObject, "someMember").equals(10);

//example with Timer & multiple assertions
after(TimerEvent.TIMER_COMPLETE).on(timer)
    .assert(timer, "currentCount").equals(20)
    .and().assert(timer, "status").startsWith("Cool ").endsWith(" stuff.");

Calling functions synchronuosly

If an assertion is very complex or there are additional steps to be taken after an event, it is possible to call a function executes the next steps.

//calling function after event
after(SomeEvent.COMPLETE).on(someObject).call(someFunction, argOne, argTwo);

//example with Timer & custom timeout
after(TimerEvent.TIMER_COMPLETE, 2000).on(timer).call(checkTimerValue, timer, expectedValue);

//combining method call and assertion after event
after(TimerEvent.TIMER_COMPLETE).on(timer)
    .call(resetTimer)
    .assert(resetTimer, "currentCount").equals(0);

Additionally API provides shortcuts to the most useful hamcrest matchers. Matchers API has been reproduced so for details please refer to the hamcrest documentation.

Some of additional matchers

// text assertions
assert(target, "text").startsWith("bigbang");
assert(target, "text").endsWith(".");
assert(target, "text").containsString("passed");
// date assertions
assert(target, "date").dateAfter(today);
// numeric
assert(target, "amount").closeTo(100, 0.01);
// array
assert(target, "array").everyItem(new MyMatcher());
assert(target, "array").hasItem("a");
// objects
assert(target, "property").instanceOf(MyClass);
assert(target, "property").hasProperty("a",);
// calling custom matcher
assert(target, "property").that(new EverythingIsOkMatcher());

Chaining assertions

after(TimerEvent.TIMER_COMPLETE).on(timer)
         .assert(timer, "currentCount")
                 .equals(1)
         .and().assert(timer, "repeatCount").equals(3);

Asserting on event

after(TimerEvent.TIMER_COMPLETE).on(timer).assertOnEvent("toString")
         .equals('[TimerEvent type="timerComplete" bubbles=false cancelable=false eventPhase=2]');

Synchronous events verification (1.2)

// given
var dispatcher:EventDispatcher = new EventDispatcher();
observing("someEvent").on(dispatcher);
// when
dispatcher.dispatchEvent(new Event("someEvent"));
// then
assert(dispatcher).observed("someEvent", times(1));

Updated