Skip to content

Commit

Permalink
Added copy operation for smell detectors
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrutherford committed Jul 5, 2009
1 parent 8107dec commit ea47ff9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/reek/smells/long_method.rb
Expand Up @@ -23,9 +23,14 @@ def self.default_config
)
end

attr_reader :max_statements

def initialize(config = LongMethod.default_config)
super
@max_statements = config[MAX_ALLOWED_STATEMENTS_KEY]
super(config)
end

def max_statements
@config['max_statements']
end

#
Expand All @@ -34,7 +39,7 @@ def initialize(config = LongMethod.default_config)
#
def examine_context(method)
num = method.num_statements
return false if num <= @max_statements
return false if num <= max_statements
found(method, "has approx #{num} statements")
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/reek/smells/smell_detector.rb
Expand Up @@ -45,6 +45,7 @@ def self.listen(hooks, config)
end

def initialize(config)
@config = config
@enabled = config[ENABLED_KEY]
@exceptions = config[EXCLUDE_KEY]
@smells_found = []
Expand All @@ -66,9 +67,14 @@ def configure(config)
end

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

def copy
self.class.new(@config.deep_copy)
end

def examine(context)
before = @smells_found.size
examine_context(context) if @enabled and !exception?(context)
Expand Down
28 changes: 28 additions & 0 deletions spec/reek/smells/smell_detector_spec.rb
Expand Up @@ -7,6 +7,34 @@
include Reek
include Reek::Smells

describe SmellDetector, 'configuration' do
before:each do
@detector = LongMethod.new
end

it 'adopts new max_statements value' do
@detector.configure_with('max_statements' => 25)
@detector.max_statements.should == 25
end
end

describe SmellDetector, 'when copied' do
before :each do
@detector = LongMethod.new
@copy = @detector.copy
end

it 'should have the same state' do
@copy.max_statements.should == @detector.max_statements
end

it 'should change independently of its parent' do
default_max = @detector.max_statements
@copy.configure_with('max_statements' => 25)
@detector.max_statements.should == default_max
end
end

describe SmellDetector, 'when masked' do
before(:each) do
@detector = Duplication.new
Expand Down

0 comments on commit ea47ff9

Please sign in to comment.