Sha256: 469978be39f19cd593e2d5367dffdc77dc0608ce45eae590d36ee7e2bd71f58c

Contents?: true

Size: 1.67 KB

Versions: 15

Compression:

Stored size: 1.67 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_offense(<<-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_offenses(<<-RUBY)
      RSpec.describe User do
        subject { described_class.new }

        let(:params) { foo }
      end
    RUBY
  end

  it 'handles subjects in tests' do
    expect_no_offenses(<<-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_offenses(<<-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_offenses(<<-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

15 entries across 15 versions & 1 rubygems

Version Path
rubocop-rspec-1.25.1 spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb
rubocop-rspec-1.25.0 spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb
rubocop-rspec-1.24.0 spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb
rubocop-rspec-1.23.0 spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb
rubocop-rspec-1.22.2 spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb
rubocop-rspec-1.22.1 spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb
rubocop-rspec-1.22.0 spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb
rubocop-rspec-1.21.0 spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb
rubocop-rspec-1.20.1 spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb
rubocop-rspec-1.20.0 spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb
rubocop-rspec-1.19.0 spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb
rubocop-rspec-1.18.0 spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb
rubocop-rspec-1.17.1 spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb
rubocop-rspec-1.17.0 spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb
rubocop-rspec-1.16.0 spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb