Skip to content

Commit

Permalink
Improve document for RSpec/BeforeAfterAll
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Nov 14, 2023
1 parent fe95441 commit c38be61
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
14 changes: 4 additions & 10 deletions docs/modules/ROOT/pages/cops_rspec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -381,25 +381,19 @@ expect(foo).to be(nil)
| 2.23
|===

Check that before/after(:all) isn't being used.
Check that before/after(:all/:context) isn't being used.

=== Examples

[source,ruby]
----
# bad
#
# Faster but risk of state leaking between examples
#
# bad - Faster but risk of state leaking between examples
describe MyClass do
before(:all) { Widget.create }
after(:all) { Widget.delete_all }
after(:context) { Widget.delete_all }
end
# good
#
# Slower but examples are properly isolated
#
# good - Slower but examples are properly isolated
describe MyClass do
before(:each) { Widget.create }
after(:each) { Widget.delete_all }
Expand Down
14 changes: 4 additions & 10 deletions lib/rubocop/cop/rspec/before_after_all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,16 @@
module RuboCop
module Cop
module RSpec
# Check that before/after(:all) isn't being used.
# Check that before/after(:all/:context) isn't being used.
#
# @example
# # bad
# #
# # Faster but risk of state leaking between examples
# #
# # bad - Faster but risk of state leaking between examples
# describe MyClass do
# before(:all) { Widget.create }
# after(:all) { Widget.delete_all }
# after(:context) { Widget.delete_all }
# end
#
# # good
# #
# # Slower but examples are properly isolated
# #
# # good - Slower but examples are properly isolated
# describe MyClass do
# before(:each) { Widget.create }
# after(:each) { Widget.delete_all }
Expand Down

0 comments on commit c38be61

Please sign in to comment.