Sha256: 864a16d3c0f234fcb8d38c4bed401e8f32dd5b502e78d0fbc3de3b53834efa67

Contents?: true

Size: 1.25 KB

Versions: 7

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

RSpec.describe RuboCop::Cop::RSpec::LeadingSubject do
  subject(:cop) { described_class.new }

  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

        subject { described_class.new }

        let(:params) { foo }
      end
    RUBY
  end

  it 'handles subjects in contexts' do
    expect_no_violations(<<-RUBY)
      RSpec.describe User do
        let(:params) { foo }

        context "when something happens" do
          subject { described_class.new }
        end
      end
    RUBY
  end

  it 'handles subjects in tests' do
    expect_no_violations(<<-RUBY)
      RSpec.describe User do
        # This shouldn't really ever happen in a sane codebase but I still
        # want to avoid false positives
        it "doesn't mind me calling a method called subject in the test" do
          let(foo)
          subject { bar }
        end
      end
    RUBY
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rubocop-rspec-1.12.0 spec/rubocop/cop/rspec/leading_subject_spec.rb
rubocop-rspec-1.11.0 spec/rubocop/cop/rspec/leading_subject_spec.rb
rubocop-rspec-1.10.0 spec/rubocop/cop/rspec/leading_subject_spec.rb
rubocop-rspec-1.9.1 spec/rubocop/cop/rspec/leading_subject_spec.rb
rubocop-rspec-1.9.0 spec/rubocop/cop/rspec/leading_subject_spec.rb
rubocop-rspec-1.8.0 spec/rubocop/cop/rspec/leading_subject_spec.rb
rubocop-rspec-1.7.0 spec/rubocop/cop/rspec/leading_subject_spec.rb