Skip to content
Browse files

Correct the running order of the hooks

* Before hooks are run in the order they are defined
* After hooks are run in reverse
  • Loading branch information...
1 parent dd341fe commit 7ee2cb4fb226dfdb075edd41e7578218a340e130 @davedevelopment committed Aug 22, 2012
Showing with 12 additions and 7 deletions.
  1. +11 −6 features/hooks/before_and_after_hooks.feature
  2. +1 −1 src/DSpec/ExampleGroup.php
View
17 features/hooks/before_and_after_hooks.feature
@@ -46,15 +46,19 @@ Feature: before and after hooks
<?php
describe("before and after callbacks", function() {
beforeEach(function() {
- echo "before each\n";
+ echo "before one\n";
});
beforeEach(function() {
- echo "before each\n";
+ echo "before two\n";
});
afterEach(function() {
- echo "after each\n";
+ echo "after one\n";
+ });
+
+ afterEach(function() {
+ echo "after two\n";
});
it("gets run in order", function() {
@@ -65,10 +69,11 @@ Feature: before and after hooks
When I run `dspec BeforeAfterOrderSpec.php`
Then the output should contain:
"""
- before each
- before each
+ before one
+ before two
it
- after each
+ after two
+ after one
"""
Scenario: exception in beforeEach is captured and reported as failure
View
2 src/DSpec/ExampleGroup.php
@@ -94,7 +94,7 @@ public function runHooks($name, AbstractContext $context, $reverse = false)
if ($parent) {
$parent->runHooks($name, $context, $reverse);
}
- foreach (array_reverse($hooks) as $hook) {
+ foreach ($hooks as $hook) {
$hook->run($context);
}
}

0 comments on commit 7ee2cb4

Please sign in to comment.
Something went wrong with that request. Please try again.