Sha256: 64b763ee201ad4f359e5ce84ab9b4823ed9c3be3cfec2fe31a7545dcce135fca

Contents?: true

Size: 1.37 KB

Versions: 11

Compression:

Stored size: 1.37 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe RuboCop::Cop::Lint::ConditionPosition do
  subject(:cop) { described_class.new }

  %w(if unless while until).each do |keyword|
    it 'registers an offense for condition on the next line' do
      inspect_source(cop,
                     ["#{keyword}",
                      'x == 10',
                      'end'
                     ])
      expect(cop.offenses.size).to eq(1)
    end

    it 'accepts condition on the same line' do
      inspect_source(cop,
                     ["#{keyword} x == 10",
                      ' bala',
                      'end'
                     ])
      expect(cop.offenses).to be_empty
    end

    it 'accepts condition on a different line for modifiers' do
      inspect_source(cop,
                     ["do_something #{keyword}",
                      '  something && something_else'])
      expect(cop.offenses).to be_empty
    end
  end

  it 'registers an offense for elsif condition on the next line' do
    inspect_source(cop,
                   ['if something',
                    '  test',
                    'elsif',
                    '  something',
                    '  test',
                    'end'
                   ])
    expect(cop.offenses.size).to eq(1)
  end

  it 'handles ternary ops' do
    inspect_source(cop, ['x ? a : b'])
    expect(cop.offenses).to be_empty
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/lint/condition_position_spec.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/lint/condition_position_spec.rb
rubocop-0.28.0 spec/rubocop/cop/lint/condition_position_spec.rb
rubocop-0.27.1 spec/rubocop/cop/lint/condition_position_spec.rb
rubocop-0.27.0 spec/rubocop/cop/lint/condition_position_spec.rb
rubocop-0.26.1 spec/rubocop/cop/lint/condition_position_spec.rb
rubocop-0.26.0 spec/rubocop/cop/lint/condition_position_spec.rb
rubocop-0.25.0 spec/rubocop/cop/lint/condition_position_spec.rb
rubocop-0.24.1 spec/rubocop/cop/lint/condition_position_spec.rb
rubocop-0.24.0 spec/rubocop/cop/lint/condition_position_spec.rb
rubocop-0.23.0 spec/rubocop/cop/lint/condition_position_spec.rb