require File.dirname(__FILE__) + '/../../spec_helper.rb' require 'reek/smells/simulated_polymorphism' require 'reek/code_context' include Reek include Reek::Smells describe SimulatedPolymorphism do before :each do @detector = SimulatedPolymorphism.new end 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 = <