Sha256: 12d1cd7873e01fa0f602cd0fe6bc38265b15c1e243d45114e9c20f5074ff2d43

Contents?: true

Size: 1.49 KB

Versions: 10

Compression:

Stored size: 1.49 KB

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    describe WhenThen do
      let(:wt) { WhenThen.new }

      it 'registers an offence for when x;' do
        inspect_source(wt, 'file.rb', ['case a',
                                       'when b; c',
                                       'end'])
        expect(wt.offences.map(&:message)).to eq(
          ['Never use "when x;". Use "when x then" instead.'])
      end

      it 'misses semicolon but does not crash when there are no tokens' do
        inspect_source(wt, 'file.rb', ['case a',
                                       'when []; {}',
                                       'end'])
        expect(wt.offences.map(&:message)).to eq([])
      end

      it 'accepts when x then' do
        inspect_source(wt, 'file.rb', ['case a',
                                       'when b then c',
                                       'end'])
        expect(wt.offences.map(&:message)).to be_empty
      end

      it 'accepts ; separating statements in the body of when' do
        inspect_source(wt, 'file.rb', ['case a',
                                       'when b then c; d',
                                       'end',
                                       '',
                                       'case e',
                                       'when f',
                                       '  g; h',
                                       'end'])
        expect(wt.offences.map(&:message)).to be_empty
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rubocop-0.7.2 spec/rubocop/cops/when_then_spec.rb
rubocop-0.7.1 spec/rubocop/cops/when_then_spec.rb
rubocop-0.7.0 spec/rubocop/cops/when_then_spec.rb
rubocop-0.6.1 spec/rubocop/cops/when_then_spec.rb
rubocop-0.6.0 spec/rubocop/cops/when_then_spec.rb
rubocop-0.5.0 spec/rubocop/cops/when_then_spec.rb
rubocop-0.4.6 spec/rubocop/cops/when_then_spec.rb
rubocop-0.4.5 spec/rubocop/cops/when_then_spec.rb
rubocop-0.4.4 spec/rubocop/cops/when_then_spec.rb
rubocop-0.4.3 spec/rubocop/cops/when_then_spec.rb