Sha256: 20b9e6bd426b0df5dceb1ff390f307c02f9632d5293909a911f2d0a4a03c1b7e

Contents?: true

Size: 1.66 KB

Versions: 13

Compression:

Stored size: 1.66 KB

Contents

# encoding: utf-8

require 'spec_helper'

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

  described_class::NODE_TYPES.each do |t|
    it "registers an offense for #{t} before other statements" do
      inspect_source(cop,
                     ['foo = 5',
                      "#{t}",
                      'bar'
                     ])
      expect(cop.offenses.size).to eq(1)
    end

    it "accepts code with conditional #{t}" do
      inspect_source(cop,
                     ['foo = 5',
                      "#{t} if test",
                      'bar'
                     ])
      expect(cop.offenses).to be_empty
    end

    it "accepts #{t} as the final expression" do
      inspect_source(cop,
                     ['foo = 5',
                      "#{t} if test"
                     ])
      expect(cop.offenses).to be_empty
    end
  end

  described_class::FLOW_COMMANDS.each do |t|
    it "registers an offense for #{t} before other statements" do
      inspect_source(cop,
                     ['foo = 5',
                      "#{t} something",
                      'bar'
                     ])
      expect(cop.offenses.size).to eq(1)
    end

    it "accepts code with conditional #{t}" do
      inspect_source(cop,
                     ['foo = 5',
                      "#{t} something if test",
                      'bar'
                     ])
      expect(cop.offenses).to be_empty
    end

    it "accepts #{t} as the final expression" do
      inspect_source(cop,
                     ['foo = 5',
                      "#{t} something if test"
                     ])
      expect(cop.offenses).to be_empty
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

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