Sha256: 58dfd3ce3e6069ae910fbb9a2df7da87af8413eb898f75168c7caeb2645a22a0

Contents?: true

Size: 921 Bytes

Versions: 1

Compression:

Stored size: 921 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    module Lint
      describe LiteralInCondition do
        let(:cop) { LiteralInCondition.new }

        %w(1 2.0 [1] {}).each do |lit|
          it "registers an offence for literal #{lit} in condition" do
            inspect_source(cop,
                           ["if x && #{lit}",
                            '  top',
                            'end'
                           ])
            expect(cop.offences.size).to eq(1)
          end
        end

        %w(1 2.0 [1] {}).each do |lit|
          it "accepts literal #{lit} if it's not an and/or operand" do
            inspect_source(cop,
                           ["if test(#{lit})",
                            '  top',
                            'end'
                           ])
            expect(cop.offences).to be_empty
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.9.0 spec/rubocop/cops/lint/literal_in_condition_spec.rb