Skip to content

Commit

Permalink
Added first test for masked smells
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrutherford committed Jun 17, 2009
1 parent 00bb11a commit 0545915
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/reek/report.rb
Expand Up @@ -7,6 +7,7 @@ class Report
include Enumerable

def initialize(sniffer = nil) # :nodoc:
@masked_smells = 0
@report = SortedSet.new
sniffer.report_on(self) if sniffer
end
Expand All @@ -22,6 +23,14 @@ def <<(smell) # :nodoc:
@report << smell
true
end

def record_masked_smell(smell)
@masked_smells += 1
end

def num_masked_smells
@masked_smells
end

def empty?
@report.empty?
Expand Down
13 changes: 12 additions & 1 deletion lib/reek/smells/smell_detector.rb
Expand Up @@ -44,6 +44,11 @@ def initialize(config)
@enabled = config[ENABLED_KEY]
@exceptions = config[EXCLUDE_KEY]
@smells_found = []
@masked = false
end

def be_masked
@masked = true
end

def examine(context)
Expand All @@ -67,7 +72,13 @@ def found(scope, warning)
end

def report_on(report)
@smells_found.each {|smell| report << smell}
@smells_found.each do |smell|
if @masked
report.record_masked_smell(smell)
else
report << smell
end
end
end

def smell_name
Expand Down
23 changes: 23 additions & 0 deletions spec/reek/smells/smell_detector_spec.rb
@@ -0,0 +1,23 @@
require File.dirname(__FILE__) + '/../../spec_helper.rb'

require 'reek/report'
require 'reek/smells/duplication'

include Reek
include Reek::Smells

describe SmellDetector, 'when masked' do
before(:each) do
@detector = Duplication.new
@detector.be_masked
@detector.found(nil, 'help')
end

it 'reports smells as masked' do
rpt = Report.new
@detector.report_on(rpt)
rpt.length.should == 0
rpt.num_masked_smells.should == 1
end
end

0 comments on commit 0545915

Please sign in to comment.