jtanistra / spock

Automatically exported from code.google.com/p/spock
0 stars 0 forks source link

provide a power assert friendly waiting utility #207

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
It would be really nice to be able to use a kind of waitFor utility that 
supported power asserts:

e.g.

waitFor(20, 0.5) { 2 == 3 }

Which would retry the block every half a second, wait for at least 20 seconds 
before giving up (with power assert output for the failed evaluation.

It would probably need to be multistatement capable

waitFor {
  2 == 2
  2 == 3
  2 == 4
}

So in that example, the power assert output would be for 2 == 3 as it was the 
first statement to fail.

For Geb in particular, it would be awesome to be able to somehow plug in to 
this. That is, Geb has its own waitFor method but it doesn't do power assert 
output. If Geb users could use Spock's better version that would be nice.

Original issue reported on code.google.com by luke.da...@gradle.biz on 30 Sep 2011 at 1:10

GoogleCodeExporter commented 8 years ago
I see two challenges here. First, such a "power assert block" needs to be 
detected statically so that we can rewrite it. Second, it might be confusing to 
have implicit power asserts in some blocks (e.g. waitFor {}) but not in others 
(e.g. collection.every {}). All in all, I wonder if this is worth the troubles 
over explicit use of 'assert'.

Original comment by pnied...@gmail.com on 4 Oct 2011 at 7:59

GoogleCodeExporter commented 8 years ago
I can't comment much on the first challenge, but the second one seems a bit 
weak to me. If this waitFor method is part of Spock then that seems like it 
would be a clear enough distinction.

Whether it's worth it or not I can't really answer because I am not sure how 
difficult the rewriting is. I do know that I've wanted something like this 
several times and it's always cumbersome.

Original comment by luke.da...@gradle.biz on 4 Oct 2011 at 8:14

GoogleCodeExporter commented 8 years ago
> If this waitFor method is part of Spock then that seems like it would be a 
clear enough distinction.

If at all I'd want to have this as a general mechanism.

> I do know that I've wanted something like this several times and it's always 
cumbersome.

What exactly is cumbersome? Explicit use of 'assert'?

Original comment by pnied...@gmail.com on 4 Oct 2011 at 8:20

GoogleCodeExporter commented 8 years ago
That and that assert statements have no value.

Original comment by luke.da...@gradle.biz on 4 Oct 2011 at 8:24

GoogleCodeExporter commented 8 years ago
No value? You'll still get a ConditionNotSatisfiedError from which you can get 
to the assertion message (if that's what you are worrying about).

Original comment by pnied...@gmail.com on 4 Oct 2011 at 8:30

GoogleCodeExporter commented 8 years ago
There's now PollingConditions and @ConditionBlock.

Original comment by pnied...@gmail.com on 4 Oct 2012 at 7:14