dsaff / truth-old

Truth: we've made Failure a Strategy
Apache License 2.0
5 stars 2 forks source link

Make success a strategy #18

Open dsaff opened 13 years ago

dsaff commented 13 years ago

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.

cgruber commented 13 years ago

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.

dsaff commented 13 years ago

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.

cgruber commented 13 years ago

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.