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', 'long_method') require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'code_parser') require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'sniffer') require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared') include Reek include Reek::Smells def process_method(src) source = src.to_reek_source sniffer = Core::Sniffer.new(source) Core::CodeParser.new(sniffer).process_defn(source.syntax_tree) end describe LongMethod do it 'should not report short methods' do 'def short(arga) alf = f(1);@bet = 2;@cut = 3;@dit = 4; @emp = 5;end'.should_not reek end it 'should report long methods' do 'def long(arga) alf = f(1);@bet = 2;@cut = 3;@dit = 4; @emp = 5;@fry = 6;end'.should reek_only_of(:LongMethod, /6 statements/) end it 'should not report initialize' do 'def initialize(arga) alf = f(1);@bet = 2;@cut = 3;@dit = 4; @emp = 5;@fry = 6;end'.should_not reek end it 'should only report a long method once' do src = < true) @ctx.should_receive(:num_statements).and_return(@num_statements) @detector.examine_context(@ctx) @yaml = @detector.smells_found.to_a[0].to_yaml # SMELL: too cumbersome! end it 'reports the number of statements' do @yaml.should match(/statement_count:[\s]*#{@num_statements}/) # SMELL: many tests duplicate the names of the YAML fields end it 'reports the correct subclass' do @yaml.should match(/subclass:[\s]*#{LongMethod::SUBCLASS_TOO_MANY_STATEMENTS}/) end end end