Sha256: 745ac9e5618f97432c374700513e46b536f2fd1362c5ce08bc7f18c73dba6608
Contents?: true
Size: 1.43 KB
Versions: 3
Compression:
Stored size: 1.43 KB
Contents
# encoding: utf-8 require 'spec_helper' module Rubocop module Cop describe MultilineTernaryOperator do let (:op) { MultilineTernaryOperator.new } it 'registers an offence for a multiline ternary operator expression' do inspect_source(op, 'file.rb', ['a = cond ?', ' b : c']) op.offences.map(&:message).should == ['Avoid multi-line ?: (the ternary operator); use if/unless ' + 'instead.'] end it 'accepts a single line ternary operator expression' do inspect_source(op, 'file.rb', ['a = cond ? b : c']) op.offences.map(&:message).should == [] end end describe NestedTernaryOperator do let (:op) { NestedTernaryOperator.new } it 'registers an offence for a nested ternary operator expression' do inspect_source(op, 'file.rb', ['a ? (b ? b1 : b2) : a2']) op.offences.map(&:message).should == ['Ternary operators must not be nested. Prefer if/else constructs ' + 'instead.'] end it 'accepts a non-nested ternary operator within an if' do inspect_source(op, 'file.rb', ['a = if x', ' cond ? b : c', 'else', ' d', 'end']) op.offences.map(&:message).should == [] end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rubocop-0.3.2 | spec/rubocop/cops/ternary_operator_spec.rb |
rubocop-0.3.1 | spec/rubocop/cops/ternary_operator_spec.rb |
rubocop-0.3.0 | spec/rubocop/cops/ternary_operator_spec.rb |