spec/rubocop/cop/rspec/leading_subject_spec.rb in rubocop-rspec-1.13.0 vs spec/rubocop/cop/rspec/leading_subject_spec.rb in rubocop-rspec-1.14.0
- old
+ new
@@ -12,10 +12,21 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Declare `subject` above any other `let` declarations.
end
RUBY
end
+ it 'checks subject below let!' do
+ expect_violation(<<-RUBY)
+ RSpec.describe User do
+ let!(:params) { foo }
+
+ subject { described_class.new }
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Declare `subject` above any other `let` declarations.
+ end
+ RUBY
+ end
+
it 'approves of subject above let' do
expect_no_violations(<<-RUBY)
RSpec.describe User do
context 'blah' do
end
@@ -49,6 +60,52 @@
subject { bar }
end
end
RUBY
end
+
+ bad_code = <<-RUBY
+ RSpec.describe User do
+ let(:params) { foo }
+ let(:bar) { baz }
+
+ subject { described_class.new }
+ it { is_expected.to do_something }
+ end
+ RUBY
+
+ good_code = <<-RUBY
+ RSpec.describe User do
+ subject { described_class.new }
+ 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
end