@@ -23,15 +23,15 @@ simply tell RSpec to tell Rails not to manage transactions:
23
23
config.use_transactional_fixtures = false
24
24
end
25
25
26
- ### Data created in ` before(:each ) ` are rolled back
26
+ ### Data created in ` before(:example ) ` are rolled back
27
27
28
- Any data you create in a ` before(:each ) ` hook will be rolled back at the end of
28
+ Any data you create in a ` before(:example ) ` hook will be rolled back at the end of
29
29
the example. This is a good thing because it means that each example is
30
30
isolated from state that would otherwise be left around by the examples that
31
31
already ran. For example:
32
32
33
33
describe Widget do
34
- before(:each ) do
34
+ before(:example ) do
35
35
@widget = Widget.create
36
36
end
37
37
@@ -48,34 +48,34 @@ The `@widget` is recreated in each of the two examples above, so each example
48
48
has a different object, _ and_ the underlying data is rolled back so the data
49
49
backing the ` @widget ` in each example is new.
50
50
51
- ### Data created in ` before(:all ) ` are _ not_ rolled back
51
+ ### Data created in ` before(:context ) ` are _ not_ rolled back
52
52
53
- ` before(:all ) ` hooks are invoked before the transaction is opened. You can use
53
+ ` before(:context ) ` hooks are invoked before the transaction is opened. You can use
54
54
this to speed things up by creating data once before any example in a group is
55
55
run, however, this introduces a number of complications and you should only do
56
56
this if you have a firm grasp of the implications. Here are a couple of
57
57
guidelines:
58
58
59
- 1 . Be sure to clean up any data in an ` after(:all ) ` hook:
59
+ 1 . Be sure to clean up any data in an ` after(:context ) ` hook:
60
60
61
- before(:all ) do
61
+ before(:context ) do
62
62
@widget = Widget.create!
63
63
end
64
64
65
- after(:all ) do
65
+ after(:context ) do
66
66
@widget.destroy
67
67
end
68
68
69
69
If you don't do that, you'll leave data lying around that will eventually
70
70
interfere with other examples.
71
71
72
- 2 . Reload the object in a ` before(:each ) ` hook.
72
+ 2 . Reload the object in a ` before(:example ) ` hook.
73
73
74
- before(:all ) do
74
+ before(:context ) do
75
75
@widget = Widget.create!
76
76
end
77
77
78
- before(:each ) do
78
+ before(:example ) do
79
79
@widget.reload
80
80
end
81
81
0 commit comments