Sha256: cb3e3d253a398ec2cffd7fb753837389834924edca4e6c63c6586dcfe53ef260

Contents?: true

Size: 1.19 KB

Versions: 8

Compression:

Stored size: 1.19 KB

Contents

# encoding: utf-8

require 'spec_helper'

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

  it 'registers an offence for when x;' do
    inspect_source(cop, ['case a',
                         'when b; c',
                         'end'])
    expect(cop.messages).to eq(
      ['Never use "when x;". Use "when x then" instead.'])
  end

  it 'accepts when x then' do
    inspect_source(cop, ['case a',
                         'when b then c',
                         'end'])
    expect(cop.messages).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.messages).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

8 entries across 8 versions & 2 rubygems

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