require 'spec_helper' require 'reek/smells/repeated_conditional' require 'reek/core/code_context' require 'reek/smells/smell_detector_shared' include Reek::Core include Reek::Smells describe RepeatedConditional do before :each do @source_name = 'howdy-doody' @detector = RepeatedConditional.new(@source_name) end it_should_behave_like 'SmellDetector' context 'with no conditionals' do it 'gathers an empty hash' do ast = 'module Stable; end'.to_reek_source.syntax_tree ctx = CodeContext.new(nil, ast) expect(@detector.conditional_counts(ctx).length).to eq(0) end end context 'with a test of block_given?' do it 'does not record the condition' do ast = 'def fred() yield(3) if block_given?; end'.to_reek_source.syntax_tree ctx = CodeContext.new(nil, ast) expect(@detector.conditional_counts(ctx).length).to eq(0) end end context 'with an empty condition' do it 'does not record the condition' do ast = 'def fred() case; when 3; end; end'.to_reek_source.syntax_tree ctx = CodeContext.new(nil, ast) expect(@detector.conditional_counts(ctx).length).to eq(0) end end context 'with three identical conditionals' do before :each do @cond = '@field == :sym' @cond_expr = @cond.to_reek_source.syntax_tree src = <