spec/rubocop/cop/rspec/shared_context_spec.rb in rubocop-rspec-1.32.0 vs spec/rubocop/cop/rspec/shared_context_spec.rb in rubocop-rspec-1.33.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + RSpec.describe RuboCop::Cop::RSpec::SharedContext do subject(:cop) { described_class.new } describe 'shared_context' do it 'does not register an offense for empty contexts' do @@ -15,10 +17,17 @@ ^^^^^^^^^^^^^^^^^^^^ Use `shared_examples` when you don't define context. it 'performs actions' do end end RUBY + + expect_correction(<<-RUBY) + shared_examples 'foo' do + it 'performs actions' do + end + end + RUBY end it 'does not register an offense for `shared_context` with let' do expect_no_offenses(<<-RUBY) shared_context 'foo' do @@ -68,19 +77,31 @@ shared_examples 'foo' do ^^^^^^^^^^^^^^^^^^^^^ Use `shared_context` when you don't define examples. let(:foo) { :bar } end RUBY + + expect_correction(<<-RUBY) + shared_context 'foo' do + let(:foo) { :bar } + end + RUBY end it 'registers an offense for shared_examples with only subject' do expect_offense(<<-RUBY) shared_examples 'foo' do ^^^^^^^^^^^^^^^^^^^^^ Use `shared_context` when you don't define examples. subject(:foo) { :bar } end RUBY + + expect_correction(<<-RUBY) + shared_context 'foo' do + subject(:foo) { :bar } + end + RUBY end it 'registers an offense for shared_examples with only hooks' do expect_offense(<<-RUBY) shared_examples 'foo' do @@ -88,10 +109,18 @@ before do foo end end RUBY + + expect_correction(<<-RUBY) + shared_context 'foo' do + before do + foo + end + end + RUBY end it 'does not register an offense for `shared_examples` with it' do expect_no_offenses(<<-RUBY) shared_examples 'foo' do @@ -103,40 +132,6 @@ end end RUBY end end - - bad_shared_context = <<-RUBY - shared_context 'foo' do - it 'performs actions' do - end - end - RUBY - - good_shared_context = <<-RUBY - shared_examples 'foo' do - it 'performs actions' do - end - end - RUBY - - include_examples 'autocorrect', - bad_shared_context, - good_shared_context - - bad_shared_examples = <<-RUBY - shared_examples 'foo' do - let(:foo) { :bar } - end - RUBY - - good_shared_examples = <<-RUBY - shared_context 'foo' do - let(:foo) { :bar } - end - RUBY - - include_examples 'autocorrect', - bad_shared_examples, - good_shared_examples end