drewbourne/hamcrest-as3

A more readable solution of using describeAs?

karfau opened this issue · 0 comments

Instead of writing:

assertThat(false, describedAs("false is false", isTrue()));

it would be more "intuitive" to be able to write:

assertThat(false, isTrue().describedAs("a failing false"));

I think describeAs is such a special-case-matcher that it would be OK to extend the matcher-API with this fluent method.

Another Idea would be to have a "fluent wrapper" for such cases which would be extendable. I just can't come up with a cool name for it ("more","multi","extend",...?):

assertThat(false, extend(isTrue()).describedAs("a failing false"));
assertThat(objUnderTest, extend(notNull()).and(hasOwnProperty("id"))));

Or maybe a combination of both worlds:

assertThat(false, isTrue().decorate().describedAs("a failing false"));
assertThat(objUnderTest, notNull().decorate().and(hasOwnProperty("id"))));

What do you think about it?