require File.dirname(__FILE__) + '/../../spec_helper.rb' require 'reek/smells/utility_function' include Reek include Reek::Smells describe UtilityFunction do it 'should count usages of self'do 'def <=>(other) Options[:sort_order].compare(self, other) end'.should_not reek end it 'should count self reference within a dstr' do 'def as(alias_name); "#{self} as #{alias_name}".to_sym; end'.should_not reek end it 'should count calls to self within a dstr' do 'def to_sql; "\'#{self.gsub(/\'/, "\'\'")}\'"; end'.should_not reek end it 'should report simple parameter call' do 'def simple(arga) arga.to_s end'.should reek_of(:UtilityFunction, /simple/) end it 'should report message chain' do 'def simple(arga) arga.b.c end'.should reek_of(:UtilityFunction, /simple/) end it 'does not report a method that calls super' do 'def child(arg) super; arg.to_s; end'.should_not reek end it 'should recognise a deep call' do src = <