Skip to content

Commit

Permalink
docs: beef up before/after hook narrative
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Dec 23, 2010
1 parent 059c1e8 commit 37a31cf
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions features/hooks/before_and_after_hooks.feature
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
Feature: before and after hooks

As a developer using RSpec
I want to execute arbitrary code before and after each example
So that I can control the environment in which it is run
Use `before` and `after` hooks to execute arbitrary code before and/or
after the body of an example is run:

This is supported by the before and after methods which each take a symbol
indicating the scope, and a block of code to execute.
before(:each) # run before each example
before(:all) # run one time only, before all of the examples in a group

before(:each) blocks are run before each example
before(:all) blocks are run once before all of the examples in a group
after(:each) # run after each example
after(:all) # run one time only, after all of the examples in a group

after(:each) blocks are run after each example
after(:all) blocks are run once after all of the examples in a group
Before and after blocks are called in the following order:

Before and after blocks are called in the following order:
before suite
before all
before each
after each
after all
after suite

Before and after blocks can be defined in the example groups to which they
apply or in a configuration. When defined in a configuration, they can be
applied to all groups or subsets of all groups defined by example group
types.
`before` and `after` hooks can be defined directly in the example groups they
should run in, or in a global RSpec.configure block. When defined in a
configuration, they can be applied to all groups or subsets of all groups
filtered by metadata associated with each example and/or group.

Scenario: define before(:each) block
Given a file named "before_each_spec.rb" with:
Expand Down

0 comments on commit 37a31cf

Please sign in to comment.