Sha256: 2dd2b67bec0b70ec0ae664fb906316e566ef96c096adf9db50ae28fb8a70b114

Contents?: true

Size: 1.66 KB

Versions: 6

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

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-0.22.0 spec/rubocop/cop/lint/unreachable_code_spec.rb
rubocop-0.21.0 spec/rubocop/cop/lint/unreachable_code_spec.rb
rubocop-0.20.1 spec/rubocop/cop/lint/unreachable_code_spec.rb
rubocop-0.20.0 spec/rubocop/cop/lint/unreachable_code_spec.rb
rubocop-0.19.1 spec/rubocop/cop/lint/unreachable_code_spec.rb
rubocop-0.19.0 spec/rubocop/cop/lint/unreachable_code_spec.rb