spec/rubocop/cop/rspec/implicit_subject_spec.rb in rubocop-rspec-1.29.1 vs spec/rubocop/cop/rspec/implicit_subject_spec.rb in rubocop-rspec-1.30.0

- old
+ new

@@ -15,10 +15,18 @@ ^^^^^^^^^^^ Don't use implicit subject. end RUBY end + it 'allows `is_expected` inside `its` block, in multi-line examples' do + expect_no_offenses(<<-RUBY) + its(:quality) do + is_expected.to be :high + end + RUBY + end + it 'flags `should` in multi-line examples' do expect_offense(<<-RUBY) it 'expect subject to be used' do should be_good ^^^^^^^^^^^^^^ Don't use implicit subject. @@ -90,10 +98,54 @@ include_examples 'autocorrect', bad_code, good_code end + context 'with EnforcedStyle `single_statement_only`' do + let(:enforced_style) { 'single_statement_only' } + + it 'allows `is_expected` in multi-line example with single statement' do + expect_no_offenses(<<-RUBY) + it 'expect subject to be used' do + is_expected.to be_good + end + RUBY + end + + it 'flags `is_expected` in multi-statement examples' do + expect_offense(<<-RUBY) + it 'expect subject to be used' do + subject.age = 18 + is_expected.to be_valid + ^^^^^^^^^^^ Don't use implicit subject. + end + RUBY + end + + bad_code = <<-RUBY + it 'is valid' do + subject.age = 18 + is_expected.to be_valid + end + RUBY + + good_code = <<-RUBY + it 'is valid' do + subject.age = 18 + expect(subject).to be_valid + end + RUBY + + include_examples 'autocorrect', + bad_code, + good_code + + include_examples 'autocorrect', + bad_code, + good_code + end + context 'with EnforcedStyle `disallow`' do let(:enforced_style) { 'disallow' } it 'flags `is_expected` in multi-line examples' do expect_offense(<<-RUBY) @@ -122,9 +174,15 @@ it 'flags `should` in single-line examples' do expect_offense(<<-RUBY) it { should be_good } ^^^^^^^^^^^^^^ Don't use implicit subject. + RUBY + end + + it 'allows `is_expected` inside `its` block' do + expect_no_offenses(<<-RUBY) + its(:quality) { is_expected.to be :high } RUBY end include_examples 'autocorrect', 'it { is_expected.to be_truthy }',