Sha256: 451ed590e66bf76ca631bd48516dc78bcf4805cf5b7842859ed2d5436c15b904

Contents?: true

Size: 1.76 KB

Versions: 6

Compression:

Stored size: 1.76 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Rubocop::Cop::Style::EmptyLinesAroundAccessModifier do
  subject(:cop) { described_class.new }

  %w(private protected public).each do |access_modifier|
    it "requires blank line before #{access_modifier}" do
      inspect_source(cop,
                     ['class Test',
                      '  something',
                      "  #{access_modifier}",
                      '',
                      '  def test; end',
                      'end'])
      expect(cop.offences.size).to eq(1)
      expect(cop.messages)
        .to eq(["Keep a blank line before and after #{access_modifier}."])
    end

    it 'requires blank line after #{access_modifier}' do
      inspect_source(cop,
                     ['class Test',
                      '  something',
                      '',
                      "  #{access_modifier}",
                      '  def test; end',
                      'end'])
      expect(cop.offences.size).to eq(1)
      expect(cop.messages)
        .to eq(["Keep a blank line before and after #{access_modifier}."])
    end

    it 'accepts missing blank line when at the beginning of class/module' do
      inspect_source(cop,
                     ['class Test',
                      "  #{access_modifier}",
                      '',
                      '  def test; end',
                      'end'])
      expect(cop.offences).to be_empty
    end

    it 'recognizes blank lines with DOS style line endings' do
      inspect_source(cop,
                     ["class Test\r",
                      "\r",
                      "  #{access_modifier}\r",
                      "\r",
                      "  def test; end\r",
                      "end\r"])
      expect(cop.offences.size).to eq(0)
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
ridecharge-rubocop-0.0.1 spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb
rubocop-0.18.1 spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb
rubocop-0.18.0 spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb
rubocop-0.17.0 spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb
rubocop-0.16.0 spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb
rubocop-0.15.0 spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb