require File.dirname(__FILE__) + '/../../spec_helper.rb' require 'reek/class_context' require 'reek/stop_context' require 'reek/code_parser' require 'reek/smells/large_class' include Reek include Reek::Smells describe LargeClass, 'checking Class objects' do it 'should not report class with 26 methods' do pending('test requires ParseTree') unless ObjectSource.can_parse_objects? class BigOne 26.times do |i| define_method "method#{i}x".to_sym do @melting end end end BigOne.should_not reek end it 'should not report short class' do pending('test requires ParseTree') unless ObjectSource.can_parse_objects? class ShortClass def method_a() @var_a; end def method_b() @var_b; end def method_c() @var_c; end def method_d() @var_d; end def method_e() @var_e; end def method_f() @var_f; end end ShortClass.should_not reek end describe LargeClass, 'counting instance variables' do it 'should not report class with 10 ivars' do pending('test requires ParseTree') unless ObjectSource.can_parse_objects? class ManyIvars def meth @vara = @varb = @varc = @vard = @vare @varf = @varg = @varh = @vari = @varj end end ManyIvars.should_not reek end it 'ignores class with only a couple of ivars' do pending('test requires ParseTree') unless ObjectSource.can_parse_objects? LargeClass.should_not reek_of(:LargeClass) end it 'ignores fq class with only a couple of ivars' do pending('test requires ParseTree') unless ObjectSource.can_parse_objects? Reek::Smells::LargeClass.should_not reek_of(:LargeClass) end end end describe LargeClass, 'when exceptions are listed' do before(:each) do @ctx = ClassContext.create(StopContext.new, [0, :Humungous]) 30.times { |num| @ctx.record_method("method#{num}") } @config = LargeClass.default_config end it 'should ignore first excepted name' do @config[LargeClass::EXCLUDE_KEY] = ['Humungous'] lc = LargeClass.new(@config) lc.examine(@ctx).should == false end it 'should ignore second excepted name' do @config[LargeClass::EXCLUDE_KEY] = ['Oversized', 'Humungous'] lc = LargeClass.new(@config) lc.examine(@ctx).should == false end it 'should report non-excepted name' do @config[LargeClass::EXCLUDE_KEY] = ['SmellMe'] lc = LargeClass.new(@config) lc.examine(@ctx).should == true end end describe LargeClass, 'checking source code' do describe 'counting instance variables' do it 'should not report empty class' do ClassContext.from_s('class Empty;end').should have(0).variable_names end it 'should count ivars in one method' do ClassContext.from_s('class Empty;def ivars() @aa=@ab=@ac=@ad; end;end').should have(4).variable_names end it 'should count ivars in 2 methods' do ClassContext.from_s('class Empty;def iv1() @aa=@ab; end;def iv2() @aa=@ac; end;end').should have(3).variable_names end it 'should not report 9 ivars' do 'class Empty;def ivars() @aa=@ab=@ac=@ad=@ae=@af=@ag=@ah=@ai; end;end'.should_not reek end it 'should report 10 ivars' do 'class Empty;def ivars() @aa=@ab=@ac=@ad=@ae=@af=@ag=@ah=@ai=@aj; end;end'.should reek_of(:LargeClass) end it 'should not report 10 ivars in 2 extensions' do src = <