Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve document for RSpec/BeforeAfterAll #1738

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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