spec/rubocop/cop/rspec/leading_subject_spec.rb in rubocop-rspec-1.32.0 vs spec/rubocop/cop/rspec/leading_subject_spec.rb in rubocop-rspec-1.33.0
- old
+ new
@@ -10,10 +10,18 @@
subject { described_class.new }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Declare `subject` above any other `let` declarations.
end
RUBY
+
+ expect_correction(<<-RUBY)
+ RSpec.describe User do
+ subject { described_class.new }
+ let(:params) { foo }
+
+ end
+ RUBY
end
it 'checks subject below let!' do
expect_offense(<<-RUBY)
RSpec.describe User do
@@ -21,10 +29,18 @@
subject { described_class.new }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Declare `subject` above any other `let!` declarations.
end
RUBY
+
+ expect_correction(<<-RUBY)
+ RSpec.describe User do
+ subject { described_class.new }
+ let!(:params) { foo }
+
+ end
+ RUBY
end
it 'approves of subject above let' do
expect_no_offenses(<<-RUBY)
RSpec.describe User do
@@ -70,10 +86,18 @@
subject { described_class.new }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Declare `subject` above any other `before` declarations.
end
RUBY
+
+ expect_correction(<<-RUBY)
+ RSpec.describe User do
+ subject { described_class.new }
+ before { allow(Foo).to receive(:bar) }
+
+ end
+ RUBY
end
it 'checks subject below example' do
expect_offense(<<-RUBY)
RSpec.describe User do
@@ -81,55 +105,15 @@
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 }
+ expect_correction(<<-RUBY)
+ RSpec.describe User do
+ subject { described_class.new }
+ it { is_expected.to be_present }
- subject { described_class.new }
- it { is_expected.to do_something }
- end
- 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
- RUBY
-
- include_examples 'autocorrect', bad_code, good_code
-
- bad_code = <<-RUBY
- RSpec.describe User do
- let(:params) { foo }
- let(:bar) { baz }
- subject do
- described_class.new
end
- it { is_expected.to do_something }
- end
- RUBY
-
- good_code = <<-RUBY
- RSpec.describe User do
- subject do
- described_class.new
- end
- let(:params) { foo }
- let(:bar) { baz }
- it { is_expected.to do_something }
- end
- RUBY
-
- include_examples 'autocorrect', bad_code, good_code
+ RUBY
+ end
end