Sha256: 740413e2e8b0a809da4fc05c3baef3fd2937439d9a446cecf36613cf3fde0a5f

Contents?: true

Size: 1.68 KB

Versions: 3

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

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

  it 'checks for empty line after subject' do
    expect_violation(<<-RUBY)
      RSpec.describe User do
        subject { described_class.new }
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add empty line after `subject`.
        let(:params) { foo }
      end
    RUBY
  end

  it 'approves empty line after subject' do
    expect_no_violations(<<-RUBY)
      RSpec.describe User do
        subject { described_class.new }

        let(:params) { foo }
      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
          subject { bar }
          let(foo)
        end
      end
    RUBY
  end

  it 'handles multiline subject block' do
    expect_no_violations(<<-RUBY)
      RSpec.describe User do
        subject do
          described_class.new
        end

        let(:params) { foo }
      end
    RUBY
  end

  it 'handles let being the latest node' do
    expect_no_violations(<<-RUBY)
      RSpec.describe User do
        subject { described_user }
      end
    RUBY
  end

  bad_example = <<-RUBY
  RSpec.describe User do
    subject { described_class.new }
    let(:params) { foo }
  end
  RUBY

  good_example = <<-RUBY
  RSpec.describe User do
    subject { described_class.new }

    let(:params) { foo }
  end
  RUBY

  include_examples 'autocorrect',
                   bad_example,
                   good_example
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-rspec-1.15.1 spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb
rubocop-rspec-1.15.0 spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb
rubocop-rspec-1.14.0 spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb