Rework running of 'after all' to not rely on global destruction#33
Rework running of 'after all' to not rely on global destruction#33perljedi wants to merge 2 commits intokingpong:developfrom
Conversation
| ok($first_nested_after, "first nested after has run"); | ||
| }; | ||
| it "doesn't run second nest after until all it's have run" => sub { | ||
| ok($second_nested_after, "second nested after hasn't run yet") |
There was a problem hiding this comment.
I think this should be testing that $second_nested_after is empty because I'd expect the after hook to run after this test?
There was a problem hiding this comment.
If this is correct, I'll probably move some of the code from Test::Spec into Test::Spec::Context to make it easier to run the "after all" tests so don't worry about changing the code. Just checking my understanding :)
There was a problem hiding this comment.
You are correct about that, but correcting the test makes it fail, so something is not quite right.
I am investigating further.
There was a problem hiding this comment.
Commit 90080db should correct this error. There was a flaw in the logic when describes had multiple examples.
There was a problem hiding this comment.
lovely, thanks! I'll try to get to this in the next couple of days (sorry, working late most of this week)
There was a problem hiding this comment.
Cool!
Cheers.
On Wed, Jun 1, 2016 at 4:33 AM, Andy Jones notifications@github.com wrote:
In t/run_after_spec.t
#33 (comment):
- describe "inner block" => sub {
describe "first nested block" => sub {it "runs first" => sub {ok(! $first_nested_after ,"first nested block");};after all => sub {$first_nested_after = 1;ok(1, "after all - first nested block");};};describe "second nested block" => sub {it "first nested after has run by now" => sub {ok($first_nested_after, "first nested after has run");};it "doesn't run second nest after until all it's have run" => sub {ok($second_nested_after, "second nested after hasn't run yet")lovely, thanks! I'll try to get to this in the next couple of days (sorry,
working late most of this week)—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/kingpong/perl-Test-Spec/pull/33/files/bff0254e79b3bf5c14c708213498be62ab5d2dda#r65321629,
or mute the thread
https://github.com/notifications/unsubscribe/AC3QAznb4Kt5yG4Rh6S-1yVOITZCY6kVks5qHUPkgaJpZM4In4PI
.
|
Thanks, this is a nice improvement! |
|
Anything I more I can do on this one? |
Current implementation means that all the "after all" tear down action happen during global destruction. This means that the "after all" for a nested describe is not run before the examples in a subsequent nested describe. This adjusted implementation will "after all" blocks after the last test within their context, but before the examples of any subsequent contexts. This does come at a performance cost, as after ever test we need to check to see if the next test (if there is one) is in a sibling or parent context. However by my observation, this performance cost is negligible in the context or running unit tests.
It is not as graceful a solution as allowing global destruction to trigger the "after all" tasks, but it does result in execution of these blocks at what I'd consider to be the expected time during execution.