spec/rubocop/cop/rspec/leading_subject_spec.rb in rubocop-rspec-1.26.0 vs spec/rubocop/cop/rspec/leading_subject_spec.rb in rubocop-rspec-1.27.0

- old
+ new

@@ -18,11 +18,11 @@ expect_offense(<<-RUBY) RSpec.describe User do let!(:params) { foo } subject { described_class.new } - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Declare `subject` above any other `let` declarations. + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Declare `subject` above any other `let!` declarations. end RUBY end it 'approves of subject above let' do @@ -61,12 +61,35 @@ end end RUBY end + it 'checks subject below hook' do + expect_offense(<<-RUBY) + RSpec.describe User do + before { allow(Foo).to receive(:bar) } + + subject { described_class.new } + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Declare `subject` above any other `before` declarations. + end + RUBY + end + + it 'checks subject below example' do + expect_offense(<<-RUBY) + RSpec.describe User do + it { is_expected.to be_present } + + subject { described_class.new } + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Declare `subject` above any other `it` declarations. + end + RUBY + end + bad_code = <<-RUBY RSpec.describe User do + before { allow(Foo).to receive(:bar) } let(:params) { foo } let(:bar) { baz } subject { described_class.new } it { is_expected.to do_something } @@ -74,9 +97,10 @@ RUBY good_code = <<-RUBY RSpec.describe User do subject { described_class.new } + before { allow(Foo).to receive(:bar) } let(:params) { foo } let(:bar) { baz } it { is_expected.to do_something } end