Skip to content

Commit

Permalink
Reverse the order of after hooks when applied to a test case.
Browse files Browse the repository at this point in the history
Add a feature documenting the order after hooks should be executed.
See: https://github.com/cucumber/cucumber/wiki/Hooks#scenario-hooks

cc. @mattwynne
  • Loading branch information
tooky committed Mar 24, 2015
1 parent 6cd83b8 commit 24ea079
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions features/docs/writing_support_code/after_hooks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,27 @@ Feature: After Hooks
./features/support/bad_hook.rb:2:in `After'
"""

Scenario: After hooks are executed in reverse order of definition
Given a file named "features/support/hooks.rb" with:
"""
After do
puts "First"
end
After do
puts "Second"
end
"""
And a file named "features/pass.feature" with:
"""
Feature:
Scenario:
Given this step passes
"""
When I run `cucumber -f progress`
Then the output should contain:
"""
Second
First
"""
2 changes: 1 addition & 1 deletion lib/cucumber/runtime/after_hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(action_blocks)

def apply_to(test_case)
test_case.with_steps(
test_case.test_steps + after_hooks(test_case.source)
test_case.test_steps + after_hooks(test_case.source).reverse
)
end

Expand Down

4 comments on commit 24ea079

@mattwynne
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted @tooky. I have deja vu about this but I can't find an existing ticket. Glad it's resolved anyway. Don't forget to update History.md too.

@brasmusson
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattwynne Yep, it was fixed once in the core: cucumber/cucumber-ruby-core#64. I remember playing with several hooks of the same type when working on formatter issues (like #746 - which the screen shots shows), but in the end I did not leave a feature or spec using more than one hook of each type for those formatter changes.

@mattwynne
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that explains it. And when we moved the hooks out of the core we lost that detail. Thanks @brasmusson.

@tooky
Copy link
Member Author

@tooky tooky commented on 24ea079 Mar 24, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @brasmusson, I had a feeling it might have been in the core.

Please sign in to comment.