Skip to content

Commit

Permalink
Replaced SmellDetector state with a hash
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrutherford committed Jul 5, 2009
1 parent ea47ff9 commit 8c20d1e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
10 changes: 3 additions & 7 deletions lib/reek/smells/smell_detector.rb
Expand Up @@ -46,8 +46,6 @@ def self.listen(hooks, config)

def initialize(config)
@config = config
@enabled = config[ENABLED_KEY]
@exceptions = config[EXCLUDE_KEY]
@smells_found = []
@masked = false
end
Expand All @@ -57,7 +55,7 @@ def be_masked
end

def enabled?
@enabled
@config[ENABLED_KEY]
end

def configure(config)
Expand All @@ -68,7 +66,6 @@ def configure(config)

def configure_with(config)
@config.adopt!(config)
@enabled = config[ENABLED_KEY] # if config.has_key?(ENABLED_KEY)
end

def copy
Expand All @@ -77,16 +74,15 @@ def copy

def examine(context)
before = @smells_found.size
examine_context(context) if @enabled and !exception?(context)
examine_context(context) if enabled? and !exception?(context)
@smells_found.length > before
end

def examine_context(context)
end

def exception?(context)
return false if @exceptions.nil? or @exceptions.length == 0
context.matches?(@exceptions)
context.matches?(@config[EXCLUDE_KEY])
end

def found(scope, warning)
Expand Down
13 changes: 5 additions & 8 deletions spec/reek/smells/duplication_spec.rb
Expand Up @@ -41,26 +41,23 @@
end
end

require 'ostruct'

describe Duplication, '#examine' do
before :each do
@mc = OpenStruct.new
@mc = MethodContext.new(StopContext.new, s(:defn, :fred))
@dup = Duplication.new
end

it 'should return true when reporting a smell' do
@mc.calls = {s(:call, nil, :other, s(:arglist)) => 47}
3.times { @mc.record_call_to(s(:call, nil, :other, s(:arglist)))}
@dup.examine(@mc).should == true
end

it 'should return false when not reporting a smell' do
@mc.calls = []
@dup.examine(@mc).should == false
end

it 'should return false when not reporting calls to new' do
@mc.calls = {[:call, :Set, :new] => 4}
4.times { @mc.record_call_to(s(:call, s(:Set), :new, s(:arglist)))}
@dup.examine(@mc).should == false
end
end
Expand Down

0 comments on commit 8c20d1e

Please sign in to comment.