spec/reek/smells/utility_function_spec.rb in reek-2.2.1 vs spec/reek/smells/utility_function_spec.rb in reek-3.0.0

- old
+ new

@@ -19,11 +19,11 @@ def simple(arga) arga.b.c end EOS source = Reek::Source::SourceCode.from(src) - mctx = Reek::Core::TreeWalker.new.process_def(source.syntax_tree) + mctx = Reek::TreeWalker.new.process_def(source.syntax_tree) @warning = @detector.examine_context(mctx)[0] # SMELL: too cumbersome! end it_should_behave_like 'common fields set correctly' @@ -37,9 +37,31 @@ ['self', 'local_call', '$global'].each do |receiver| it 'ignores the receiver' do src = "def #{receiver}.simple(arga) arga.to_s + arga.to_i end" expect(src).not_to reek_of(:UtilityFunction) end + end + end + + context 'Singleton methods' do + it 'for classes with `class << self` notation should not report UtilityFunction' do + src = 'class C; class << self; def m(a) a.to_s; end; end; end' + expect(src).not_to reek_of(:UtilityFunction) + end + + it 'for classes with `self.` notation should not report UtilityFunction' do + src = 'class C; def self.m(a) a.to_s; end; end' + expect(src).not_to reek_of(:UtilityFunction) + end + + it 'for modules with `class << self` notation should not report UtilityFunction' do + src = 'module M; class << self; def self.m(a) a.to_s; end; end; end' + expect(src).not_to reek_of(:UtilityFunction) + end + + it 'for modules with `self.` notation should not report UtilityFunction' do + src = 'module M; def self.simple(a) a.to_s; end; end' + expect(src).not_to reek_of(:UtilityFunction) end end context 'with no calls' do it 'does not report empty method' do