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 def process_singleton_method(src) source = src.to_reek_source sniffer = Core::Sniffer.new(source) Core::CodeParser.new(sniffer).process_defs(source.syntax_tree) end describe LongMethod do it 'should not report short methods' do src = 'def short(arga) alf = f(1);@bet = 2;@cut = 3;@dit = 4; @emp = 5;end' src.should_not smell_of(LongMethod) end it 'should report long methods' do src = 'def long() alf = f(1);@bet = 2;@cut = 3;@dit = 4; @emp = 5;@fry = 6;end' src.should reek_only_of(:LongMethod, /6 statements/) end it 'should not report initialize' do src = 'def initialize(arga) alf = f(1);@bet = 2;@cut = 3;@dit = 4; @emp = 5;@fry = 6;end' src.should_not smell_of(LongMethod) end it 'should only report a long method once' do src = <