Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Fix documentation surrounding hook order #2735

Merged
merged 1 commit into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion features/hooks/around_hooks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Feature: `around` hooks
**WARNING:** Mock frameworks are set up and torn down within the context of
running the example. You cannot interact with them directly in `around` hooks.

**WARNING:** `around` hooks will execute *after* any `before` hooks, and *before*
**WARNING:** `around` hooks will execute *before* any `before` hooks, and *after*
any `after` hooks regardless of the context they were defined in.

Scenario: Use the example as a proc within the block passed to `around()`
Expand Down
2 changes: 1 addition & 1 deletion features/hooks/before_and_after_hooks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Feature: `before` and `after` hooks

**WARNING:** Mocks are only supported in `before(:example)`.

**WARNING:** `around` hooks will execute *after* any `before` hooks, and *before*
**WARNING:** `around` hooks will execute *before* any `before` hooks, and *after*
any `after` hooks regardless of the context they were defined in.

Note: the `:example` and `:context` scopes are also available as `:each` and
Expand Down
21 changes: 13 additions & 8 deletions lib/rspec/core/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ module Hooks
# before(:example) # Declared in a parent group.
# before(:example) # Declared in the current group.
#
# If more than one `before` is declared within any one scope, they are run
# in the order in which they are declared. Any `around` hooks will execute
# later than any `before` hook regardless of scope.
# If more than one `before` is declared within any one example group, they
# are run in the order in which they are declared. Any `around` hooks will
# execute after `before` context hooks but before any `before` example
# hook regardless of where they are declared.
#
# ### Conditions
#
Expand Down Expand Up @@ -263,9 +264,10 @@ def prepend_before(*args, &block)
# after(:suite) # Declared in RSpec.configure.
#
# This is the reverse of the order in which `before` hooks are run.
# Similarly, if more than one `after` is declared within any one scope,
# they are run in reverse order of that in which they are declared. Also
# `around` hooks will all have run before any after hooks are invoked.
# Similarly, if more than one `after` is declared within any example
# group, they are run in reverse order of that in which they are declared.
# Also `around` hooks will run after any `after` example hooks are
# invoked but before any `after` context hooks.
#
# @note The `:example` and `:context` scopes are also available as
# `:each` and `:all`, respectively. Use whichever you prefer.
Expand Down Expand Up @@ -337,8 +339,11 @@ def append_after(*args, &block)
#
# ### Order
#
# All `around` hooks execute immediately surrounding an example, this means
# that all `before` hooks will have run and no `after` hooks will have run yet.
# The `around` hooks execute surrounding an example and its hooks.
#
# This means after any `before` context hooks, but before any `before`
# example hooks, and similarly after any `after` example hooks but before
# any `after` context hooks.
#
# They are not a synonym for `before`/`after`.
def around(*args, &block)
Expand Down