dsaff/truth-old

Make success a strategy

dsaff opened this issue · 3 comments

Ooooh. It occurs to me that if we also make success a strategy, something wonderful happens. We can write a one-line test like this:

expectFailingBecause("Not true that is inclusively in range ").whenAsserting().that(1).isInclusivelyInRange(2, 4);

It also allows "logging successes", which people have asked from JUnit several times.

Can you describe "logging successes" more? I'm not sure I understand that.

As to the line above, I like the english meaning of it, though I feel like there's something blocky about the specific methods and how it's constructed. I think I'm not quite getting "it" yet.

I'm imagining:

protected final And nextChain() {
getFailureStrategy().succeed(); // Can throw an exception if this is a perverse failure strategy, or just increment a counter.
return chain;
}

In terms of "logging successes", people have several times asked for a way to log the number of passing assertions, apparently as a way of proving to their dangerously out-of-touch bosses that some kind of magic-number measurable progress is being made. This would allow that, although it wouldn't help with which assertions were passing, just the counter.

In terms of syntax, whenAsserting() is completely a no-op here to get the English not entirely terrible. Basically, we need an expression X such that

X("_failure message substring_") is a TestVerb. Very open to better names.

Wild. (re: assertion counting). Though I know JsTD has that too.

I have to think about this - it's only sort of working in my brain. Let's keep noodling and I'm sure I'll get it.