From c38be61bdd5c3d011ebba05d9d6cec0d15f028ec Mon Sep 17 00:00:00 2001 From: ydah <13041216+ydah@users.noreply.github.com> Date: Tue, 14 Nov 2023 23:56:20 +0900 Subject: [PATCH] Improve document for `RSpec/BeforeAfterAll` --- docs/modules/ROOT/pages/cops_rspec.adoc | 14 ++++---------- lib/rubocop/cop/rspec/before_after_all.rb | 14 ++++---------- 2 files changed, 8 insertions(+), 20 deletions(-) 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 }