require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper') require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'simulated_polymorphism') require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'code_context') require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared') include Reek::Core include Reek::Smells describe SimulatedPolymorphism do before :each do @source_name = 'howdy-doody' @detector = SimulatedPolymorphism.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) @detector.conditional_counts(ctx).length.should == 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) @detector.conditional_counts(ctx).length.should == 0 end end context 'with three identical conditionals' do before :each do @cond = '@field == :sym' @cond_expr = @cond.to_reek_source.syntax_tree src = <