Sha256: 84c479deccc72f42f175ad4307129b16de3c964c7fe6b90997df70e9ea0ad55b

Contents?: true

Size: 1.61 KB

Versions: 7

Compression:

Stored size: 1.61 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe RuboCop::Cop::Style::WhileUntilDo do
  subject(:cop) { described_class.new }

  it 'registers an offense for do in multiline while' do
    inspect_source(cop, ['while cond do',
                         'end'])
    expect(cop.offenses.size).to eq(1)
  end

  it 'registers an offense for do in multiline until' do
    inspect_source(cop, ['until cond do',
                         'end'])
    expect(cop.offenses.size).to eq(1)
  end

  it 'accepts do in single-line while' do
    inspect_source(cop, ['while cond do something end'])
    expect(cop.offenses).to be_empty
  end

  it 'accepts do in single-line until' do
    inspect_source(cop, ['until cond do something end'])
    expect(cop.offenses).to be_empty
  end

  it 'it accepts multi-line while without do' do
    inspect_source(cop, ['while cond',
                         'end'])
    expect(cop.offenses).to be_empty
  end

  it 'it accepts multi-line until without do' do
    inspect_source(cop, ['until cond',
                         'end'])
    expect(cop.offenses).to be_empty
  end

  it 'auto-corrects the usage of "do" in multiline while' do
    new_source = autocorrect_source(cop, ['while cond do',
                                          'end'])
    expect(new_source).to eq(['while cond',
                              'end'].join("\n"))
  end

  it 'auto-corrects the usage of "do" in multiline until' do
    new_source = autocorrect_source(cop, ['until cond do',
                                          'end'])
    expect(new_source).to eq(['until cond',
                              'end'].join("\n"))
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

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