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 }