-
Notifications
You must be signed in to change notification settings - Fork 17
Rework running of 'after all' to not rely on global destruction #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
t/run_after_spec.t
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
Cheers.
On Wed, Jun 1, 2016 at 4:33 AM, Andy Jones [email protected] 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.