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 55b7361
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
2 changes: 1 addition & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ RSpec/BeNil:
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeNil

RSpec/BeforeAfterAll:
Description: Check that before/after(:all) isn't being used.
Description: Check that before/after(:all/:context) isn't being used.
Enabled: true
Exclude:
- "**/spec/spec_helper.rb"
Expand Down
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 55b7361

Please sign in to comment.