Sha256: 41b71d48c4fa0b6107fac3bdb43d1968868802c9db1979e96f7b97734139c7e8
Contents?: true
Size: 1.75 KB
Versions: 13
Compression:
Stored size: 1.75 KB
Contents
# encoding: utf-8 require 'spec_helper' module Rubocop module Cop describe AmpersandsPipesVsAndOr do let(:amp) { AmpersandsPipesVsAndOr.new } it 'registers an offence for AND used in condition of if statement' do check('if', 'and', '&&') end it 'registers an offence for OR used in condition of if statement' do check('if', 'or', '||') end it 'registers an offence for AND used in condition of unless' do check('unless', 'and', '&&') end it 'registers an offence for OR used in condition of unless' do check('unless', 'or', '||') end it 'registers an offence for AND used in condition of while' do check('while', 'and', '&&') end it 'registers an offence for OR used in condition of while' do check('while', 'or', '||') end it 'registers an offence for AND used in condition of until' do check('until', 'and', '&&') end it 'registers an offence for OR used in condition of until' do check('until', 'or', '||') end def check(keyword, bad_operator, good_operator) inspect_source(amp, 'file.rb', ["#{keyword} a #{bad_operator} b", ' c', 'end', "#{keyword} a #{good_operator} b", ' c', 'end']) # Just one offence should be registered. The good_operator # should be accepted. expect(amp.offences.map(&:message)).to eq( ['Use &&/|| for boolean expressions, and/or for control flow.']) expect(amp.offences[0].line_number).to eq(1) end end end end
Version data entries
13 entries across 13 versions & 1 rubygems