Sha256: 91c5aad593f70b7e2a4cc817835074879c30ca1cf4910251629f8dc88e17bb21

Contents?: true

Size: 1.22 KB

Versions: 9

Compression:

Stored size: 1.22 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',
                              'when b then c',
                              'end'].join("\n"))
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/style/when_then_spec.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/style/when_then_spec.rb
rubocop-0.29.1 spec/rubocop/cop/style/when_then_spec.rb
rubocop-0.29.0 spec/rubocop/cop/style/when_then_spec.rb
rubocop-0.28.0 spec/rubocop/cop/style/when_then_spec.rb
rubocop-0.27.1 spec/rubocop/cop/style/when_then_spec.rb
rubocop-0.27.0 spec/rubocop/cop/style/when_then_spec.rb
rubocop-0.26.1 spec/rubocop/cop/style/when_then_spec.rb
rubocop-0.26.0 spec/rubocop/cop/style/when_then_spec.rb