Sha256: 57c323908377d18882087c04d67fc8f6ee3615177d64acdb35dd0e44b0d66f8a

Contents?: true

Size: 2 KB

Versions: 7

Compression:

Stored size: 2 KB

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    module Style
      describe SpaceAfterControlKeyword do
        let(:ap) { SpaceAfterControlKeyword.new }

        it 'registers an offence for normal if' do
          inspect_source(ap,
                         ['if(test) then result end'])
          expect(ap.offences.size).to eq(1)
        end

        it 'registers an offence for modifier unless' do
          inspect_source(ap, ['action unless(test)'])

          expect(ap.offences.size).to eq(1)
        end

        it 'does not get confused by keywords' do
          inspect_source(ap, ['[:if, :unless].action'])
          expect(ap.offences).to be_empty
        end

        it 'does not get confused by the ternary operator' do
          inspect_source(ap, ['a ? b : c'])
          expect(ap.offences).to be_empty
        end

        it 'registers an offence for if, elsif, and unless' do
          inspect_source(ap,
                         ['if(a)',
                          'elsif(b)',
                          '  unless(c)',
                          '  end',
                          'end'])
          expect(ap.offences.map(&:line)).to eq([1, 2, 3])
        end

        it 'registers an offence for case and when' do
          inspect_source(ap,
                         ['case(a)',
                          'when(0) then 1',
                          'end'])
          expect(ap.offences.map(&:line)).to eq([1, 2])
        end

        it 'registers an offence for case and when' do
          inspect_source(ap,
                         ['case(a)',
                          'when(0) then 1',
                          'end'])
          expect(ap.offences.map(&:line)).to eq([1, 2])
        end

        it 'registers an offence for while and until' do
          inspect_source(ap,
                         ['while(a)',
                          '  b until(c)',
                          'end'])
          expect(ap.offences.map(&:line)).to eq([1, 2])
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
rubocop-0.12.0 spec/rubocop/cop/style/space_after_control_keyword_spec.rb
rubocop-0.11.1 spec/rubocop/cop/style/space_after_control_keyword_spec.rb
rubocop-0.11.0 spec/rubocop/cops/style/space_after_control_keyword_spec.rb
rubocop-0.10.0 spec/rubocop/cops/style/space_after_control_keyword_spec.rb
rubocop-0.9.1 spec/rubocop/cops/style/space_after_control_keyword_spec.rb
sabat-rubocop-0.9.0 spec/rubocop/cops/style/space_after_control_keyword_spec.rb
rubocop-0.9.0 spec/rubocop/cops/style/space_after_control_keyword_spec.rb