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

Commit 5685ccf

Browse files
authored
Merge pull request #2735 from rspec/fix-hook-docs
Fix documentation surrounding hook order
2 parents ceecf78 + dac90f3 commit 5685ccf

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

features/hooks/around_hooks.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Feature: `around` hooks
1717
**WARNING:** Mock frameworks are set up and torn down within the context of
1818
running the example. You cannot interact with them directly in `around` hooks.
1919

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

2323
Scenario: Use the example as a proc within the block passed to `around()`

features/hooks/before_and_after_hooks.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Feature: `before` and `after` hooks
3232

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

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

3838
Note: the `:example` and `:context` scopes are also available as `:each` and

lib/rspec/core/hooks.rb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ module Hooks
6060
# before(:example) # Declared in a parent group.
6161
# before(:example) # Declared in the current group.
6262
#
63-
# If more than one `before` is declared within any one scope, they are run
64-
# in the order in which they are declared. Any `around` hooks will execute
65-
# later than any `before` hook regardless of scope.
63+
# If more than one `before` is declared within any one example group, they
64+
# are run in the order in which they are declared. Any `around` hooks will
65+
# execute after `before` context hooks but before any `before` example
66+
# hook regardless of where they are declared.
6667
#
6768
# ### Conditions
6869
#
@@ -263,9 +264,10 @@ def prepend_before(*args, &block)
263264
# after(:suite) # Declared in RSpec.configure.
264265
#
265266
# This is the reverse of the order in which `before` hooks are run.
266-
# Similarly, if more than one `after` is declared within any one scope,
267-
# they are run in reverse order of that in which they are declared. Also
268-
# `around` hooks will all have run before any after hooks are invoked.
267+
# Similarly, if more than one `after` is declared within any example
268+
# group, they are run in reverse order of that in which they are declared.
269+
# Also `around` hooks will run after any `after` example hooks are
270+
# invoked but before any `after` context hooks.
269271
#
270272
# @note The `:example` and `:context` scopes are also available as
271273
# `:each` and `:all`, respectively. Use whichever you prefer.
@@ -337,8 +339,11 @@ def append_after(*args, &block)
337339
#
338340
# ### Order
339341
#
340-
# All `around` hooks execute immediately surrounding an example, this means
341-
# that all `before` hooks will have run and no `after` hooks will have run yet.
342+
# The `around` hooks execute surrounding an example and its hooks.
343+
#
344+
# This means after any `before` context hooks, but before any `before`
345+
# example hooks, and similarly after any `after` example hooks but before
346+
# any `after` context hooks.
342347
#
343348
# They are not a synonym for `before`/`after`.
344349
def around(*args, &block)

0 commit comments

Comments
 (0)