Sha256: d9d829e267524c249a1e31244954b980d44f2fa4212fdabf15ef1f63c93651f4

Contents?: true

Size: 1.66 KB

Versions: 8

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 offence for #{t} before other statements" do
      inspect_source(cop,
                     ['foo = 5',
                      "#{t}",
                      'bar'
                     ])
      expect(cop.offences.size).to eq(1)
    end

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

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

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

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

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

Version data entries

8 entries across 8 versions & 2 rubygems

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