Sha256: 2869f1089473fc2f4ceddf75bd0d074b0b54b78bb2633e996c4f8bb8da6a9f21

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 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 '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

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-0.4.2 spec/rubocop/cops/when_then_spec.rb
rubocop-0.4.1 spec/rubocop/cops/when_then_spec.rb
rubocop-0.4.0 spec/rubocop/cops/when_then_spec.rb