Method: RSpec::Core::Hooks#after
- Defined in:
- lib/rspec/core/hooks.rb
permalink #after(&block) ⇒ void #after(scope, &block) ⇒ void #after(scope, *conditions, &block) ⇒ void #after(conditions, &block) ⇒ void Also known as: prepend_after
The :example
and :context
scopes are also available as
:each
and :all
, respectively. Use whichever you prefer.
The :suite
scope is only supported for hooks registered on
RSpec.configuration
since they exist independently of any
example or example group.
Declare a block of code to be run after each example (using :example
)
or once after all examples n the context (using :context
). See
#before for more information about ordering.
Exceptions
after
hooks are guaranteed to run even when there are exceptions in
before
hooks or examples. When an exception is raised in an after
block, the exception is captured for later reporting, and subsequent
after
blocks are run.
Order
after
hooks are stored in three scopes, which are run in order:
:example
, :context
, and :suite
. They can also be declared in
several different places: RSpec.configure
, a parent group, the current
group. They are run in the following order:
after(:example) # Declared in the current group.
after(:example) # Declared in a parent group.
after(:example) # Declared in RSpec.configure.
after(:context) # Declared in the current group.
after(:context) # Declared in a parent group.
after(:context) # Declared in RSpec.configure.
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 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.
277 278 279 |
# File 'lib/rspec/core/hooks.rb', line 277 def after(*args, &block) hooks.register :prepend, :after, *args, &block end |