require 'spec_helper' require 'reek/smells/feature_envy' require 'reek/smells/smell_detector_shared' include Reek include Reek::Smells describe FeatureEnvy do context 'with no smell' do it 'should not report use of self' do expect('def simple() self.to_s + self.to_i end').not_to reek_of(:FeatureEnvy) end it 'should not report vcall with no argument' do expect('def simple() func; end').not_to reek_of(:FeatureEnvy) end it 'should not report single use' do expect('def no_envy(arga) arga.barg(@item) end').not_to reek_of(:FeatureEnvy) end it 'should not report return value' do expect('def no_envy(arga) arga.barg(@item); arga end').not_to reek_of(:FeatureEnvy) end it 'should ignore global variables' do expect('def no_envy() $s2.to_a; $s2[@item] end').not_to reek_of(:FeatureEnvy) end it 'should not report class methods' do expect('def simple() self.class.new.flatten_merge(self) end'). not_to reek_of(:FeatureEnvy) end it 'should not report single use of an ivar' do expect('def no_envy() @item.to_a end').not_to reek_of(:FeatureEnvy) end it 'should not report returning an ivar' do expect('def no_envy() @item.to_a; @item end').not_to reek_of(:FeatureEnvy) end it 'should not report ivar usage in a parameter' do expect('def no_envy() @item.price + tax(@item) - savings(@item) end'). not_to reek_of(:FeatureEnvy) end it 'should not report single use of an lvar' do expect('def no_envy() lv = @item; lv.to_a end').not_to reek_of(:FeatureEnvy) end it 'should not report returning an lvar' do expect('def no_envy() lv = @item; lv.to_a; lv end').not_to reek_of(:FeatureEnvy) end it 'ignores lvar usage in a parameter' do expect('def no_envy() lv = @item; lv.price + tax(lv) - savings(lv); end'). not_to reek_of(:FeatureEnvy) end it 'ignores multiple ivars' do src = <