Skip to content

Commit

Permalink
Renamed the spec matcher to reek
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrutherford committed Mar 27, 2009
1 parent 5ec33d3 commit 082e553
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions spec/reek/smells/feature_envy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def to_source
end
end

class ShouldSmell
class ShouldReek
def matches?(actual)
@source = actual.to_source
@source.smelly?
Expand All @@ -27,11 +27,11 @@ def failure_message_for_should_not
end
end

def smell
ShouldSmell.new
def reek
ShouldReek.new
end

class ShouldSmellOf
class ShouldReekOf
def initialize(klass, patterns)
@klass = klass
@patterns = patterns
Expand All @@ -48,37 +48,37 @@ def failure_message_for_should_not
end
end

def smell_of(klass, *patterns)
ShouldSmellOf.new(klass, patterns)
def reek_of(klass, *patterns)
ShouldReekOf.new(klass, patterns)
end

#-------------------------------------------------------------------------------------------

describe FeatureEnvy, 'with only messages to self' do
it 'should not report use of self' do
'def simple() self.to_s + self.to_i end'.should_not smell
'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 smell
'def simple() func; end'.should_not reek
end

it 'should not report vcall with argument' do
'def simple(arga) func(17); end'.should_not smell
'def simple(arga) func(17); end'.should_not reek
end
end

describe FeatureEnvy, 'when the receiver is a parameter' do
it 'should not report single use' do
'def no_envy(arga) arga.barg(@item) end'.should_not smell
'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 smell
'def no_envy(arga) arga.barg(@item); arga end'.should_not reek
end

it 'should report many calls to parameter' do
'def envy(arga) arga.b(arga) + arga.c(@fred) end'.should smell_of(:FeatureEnvy, /arga/)
'def envy(arga) arga.b(arga) + arga.c(@fred) end'.should reek_of(:FeatureEnvy, /arga/)
end
end

Expand All @@ -91,8 +91,8 @@ def smell_of(klass, *patterns)
total += fred.tax
total *= 1.15
end'
ruby.should smell_of(:FeatureEnvy, /total/)
ruby.should_not smell_of(:FeatureEnvy, /fred/)
ruby.should reek_of(:FeatureEnvy, /total/)
ruby.should_not reek_of(:FeatureEnvy, /fred/)
end

it 'should report multiple affinities' do
Expand All @@ -102,39 +102,39 @@ def smell_of(klass, *patterns)
total += fred.price
total += fred.tax
end'
ruby.should smell_of(:FeatureEnvy, /total/)
ruby.should smell_of(:FeatureEnvy, /fred/)
ruby.should reek_of(:FeatureEnvy, /total/)
ruby.should reek_of(:FeatureEnvy, /fred/)
end
end

describe FeatureEnvy, 'when the receiver is external' do
it 'should ignore global variables' do
'def no_envy() $s2.to_a; $s2[@item] end'.should_not smell
'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 smell
'def simple() self.class.new.flatten_merge(self) end'.should_not reek
end
end

describe FeatureEnvy, 'when the receiver is an ivar' do
it 'should not report single use of an ivar' do
'def no_envy() @item.to_a end'.should_not smell
'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 smell
'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 smell
'def no_envy; @item.price + tax(@item) - savings(@item) end'.should_not reek
end

it 'should not be fooled by duplication' do
'def feed(thing); @cow.feed_to(thing.pig); @duck.feed_to(thing.pig); end'.should_not smell_of(:FeatureEnvy)
'def feed(thing); @cow.feed_to(thing.pig); @duck.feed_to(thing.pig); end'.should_not reek_of(:FeatureEnvy)
end
it 'should count local calls' do
'def feed(thing); cow.feed_to(thing.pig); duck.feed_to(thing.pig); end'.should_not smell_of(:FeatureEnvy)
'def feed(thing); cow.feed_to(thing.pig); duck.feed_to(thing.pig); end'.should_not reek_of(:FeatureEnvy)
end
end

Expand All @@ -158,18 +158,18 @@ def smell_of(klass, *patterns)

describe FeatureEnvy, 'when the receiver is an lvar' do
it 'should not report single use of an lvar' do
'def no_envy() lv = @item; lv.to_a end'.should_not smell
'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 smell
'def no_envy() lv = @item; lv.to_a; lv end'.should_not reek
end

it 'should report many calls to lvar' do
'def envy; lv = @item; lv.price + lv.tax end'.should smell_of(:FeatureEnvy, /lv/)
'def envy; lv = @item; lv.price + lv.tax end'.should reek_of(:FeatureEnvy, /lv/)
end

it 'should not report lvar usage in a parameter' do
'def no_envy; lv = @item; lv.price + tax(lv) - savings(lv) end'.should_not smell
'def no_envy; lv = @item; lv.price + tax(lv) - savings(lv) end'.should_not reek
end
end

0 comments on commit 082e553

Please sign in to comment.