From 55b73613fb4980f02ed24746ba88eb24b428c88d Mon Sep 17 00:00:00 2001 From: ydah <13041216+ydah@users.noreply.github.com> Date: Wed, 15 Nov 2023 00:01:12 +0900 Subject: [PATCH] Improve document for `RSpec/BeforeAfterAll` --- config/default.yml | 2 +- docs/modules/ROOT/pages/cops_rspec.adoc | 14 ++++---------- lib/rubocop/cop/rspec/before_after_all.rb | 14 ++++---------- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/config/default.yml b/config/default.yml index f5e731437..f672f26f4 100644 --- a/config/default.yml +++ b/config/default.yml @@ -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" diff --git a/docs/modules/ROOT/pages/cops_rspec.adoc b/docs/modules/ROOT/pages/cops_rspec.adoc index 14bb6f073..f985c7e5f 100644 --- a/docs/modules/ROOT/pages/cops_rspec.adoc +++ b/docs/modules/ROOT/pages/cops_rspec.adoc @@ -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 } diff --git a/lib/rubocop/cop/rspec/before_after_all.rb b/lib/rubocop/cop/rspec/before_after_all.rb index 7c3298c8f..b26c4bc46 100644 --- a/lib/rubocop/cop/rspec/before_after_all.rb +++ b/lib/rubocop/cop/rspec/before_after_all.rb @@ -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 }