Sha256: 307b805f42238b6f5bfaf01210dcb15b4ec1f25a4177ada5fc437955c2a64208

Contents?: true

Size: 1.52 KB

Versions: 8

Compression:

Stored size: 1.52 KB

Contents

# encoding: utf-8

require 'spec_helper'

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

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

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

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

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

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

  it 'it accepts multi-line until without do' do
    inspect_source(cop, ['until cond',
                         'end'])
    expect(cop.offences).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\nend")
  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\nend")
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

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