Skip to content

Conversation

perljedi
Copy link

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.

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")
Copy link
Collaborator

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?

Copy link
Collaborator

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 :)

Copy link
Author

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.

Copy link
Author

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.

Copy link
Collaborator

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)

Copy link
Author

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
.

@andyjones
Copy link
Collaborator

Thanks, this is a nice improvement!

@perljedi
Copy link
Author

Anything I more I can do on this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants