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', 'feature_envy') require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared') include Reek include Reek::Smells describe FeatureEnvy do context 'with no smell' do it 'should not report use of self' do 'def simple() self.to_s + self.to_i end'.should_not reek end it 'should not report vcall with no argument' do 'def simple() func; end'.should_not reek end it 'should not report vcall with argument' do 'def simple(arga) func(17); end'.should_not reek end it 'should not report single use' do 'def no_envy(arga) arga.barg(@item) end'.should_not reek end it 'should not report return value' do 'def no_envy(arga) arga.barg(@item); arga end'.should_not reek end it 'should ignore global variables' do 'def no_envy() $s2.to_a; $s2[@item] end'.should_not reek end it 'should not report class methods' do 'def simple() self.class.new.flatten_merge(self) end'.should_not reek end it 'should not report single use of an ivar' do 'def no_envy() @item.to_a end'.should_not reek end it 'should not report returning an ivar' do 'def no_envy() @item.to_a; @item end'.should_not reek end it 'should not report ivar usage in a parameter' do 'def no_envy() @item.price + tax(@item) - savings(@item) end'.should_not reek end it 'should not report single use of an lvar' do 'def no_envy() lv = @item; lv.to_a end'.should_not reek end it 'should not report returning an lvar' do 'def no_envy() lv = @item; lv.to_a; lv end'.should_not reek end it 'ignores lvar usage in a parameter' do 'def no_envy() lv = @item; lv.price + tax(lv) - savings(lv); end'.should_not reek end it 'ignores multiple ivars' do src = <