Sha256: dfe3e972ff5720056d6722d32017d19cedcf2dccafb129b2097b82d30c388ea4

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

# encoding: utf-8

require 'spec_helper'

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

  it 'registers an offense for when x;' do
    inspect_source(cop, ['case a',
                         'when b; c',
                         'end'])
    expect(cop.offenses.size).to eq(1)
  end

  it 'accepts when x then' do
    inspect_source(cop, ['case a',
                         'when b then c',
                         'end'])
    expect(cop.offenses).to be_empty
  end

  it 'accepts ; separating statements in the body of when' do
    inspect_source(cop, ['case a',
                         'when b then c; d',
                         'end',
                         '',
                         'case e',
                         'when f',
                         '  g; h',
                         'end'])
    expect(cop.offenses).to be_empty
  end

  it 'auto-corrects "when x;" with "when x then"' do
    new_source = autocorrect_source(cop, ['case a',
                                          'when b; c',
                                          'end'])
    expect(new_source).to eq("case a\nwhen b then c\nend")
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.22.0 spec/rubocop/cop/style/when_then_spec.rb
rubocop-0.21.0 spec/rubocop/cop/style/when_then_spec.rb
rubocop-0.20.1 spec/rubocop/cop/style/when_then_spec.rb
rubocop-0.20.0 spec/rubocop/cop/style/when_then_spec.rb