Skip to content

Commit

Permalink
Header now printed for every source
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrutherford committed Jun 28, 2009
1 parent 71133c4 commit 32893fc
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 24 deletions.
7 changes: 2 additions & 5 deletions bin/reek
Expand Up @@ -13,11 +13,8 @@ require 'reek/options'
def reek(args)
begin
source = Reek::Options.parse(args)
if source.smelly?
puts source.report
return 2
end
return 0
puts source.full_report
return source.smelly? ? 2 : 0
rescue SystemExit => ex
return ex.status
rescue Exception => error
Expand Down
4 changes: 2 additions & 2 deletions features/masking_smells.feature
Expand Up @@ -9,7 +9,7 @@ Feature: Masking smells using config files
Then it fails with exit status 2
And it reports:
"""
"spec/samples/empty_config_file/dirty.rb" -- 6 warnings:
spec/samples/empty_config_file/dirty.rb -- 6 warnings:
Dirty has the variable name '@s' (Uncommunicative Name)
Dirty#a calls @s.title multiple times (Duplication)
Dirty#a calls puts(@s.title) multiple times (Duplication)
Expand All @@ -34,7 +34,7 @@ Feature: Masking smells using config files
Then it fails with exit status 2
And it reports:
"""
"spec/samples/masked/dirty.rb" -- 3 warnings:
spec/samples/masked/dirty.rb -- 3 warnings:
Dirty#a calls @s.title multiple times (Duplication)
Dirty#a calls puts(@s.title) multiple times (Duplication)
Dirty#a/block/block is nested (Nested Iterators)
Expand Down
6 changes: 3 additions & 3 deletions features/samples.feature
Expand Up @@ -9,7 +9,7 @@ Feature: Basic smell detection
Then it fails with exit status 2
And it reports:
"""
"spec/samples/inline.rb" -- 32 warnings:
spec/samples/inline.rb -- 32 warnings:
Inline::C has at least 13 instance variables (Large Class)
Inline::C#build calls ($? == 0) multiple times (Duplication)
Inline::C#build calls Inline.directory multiple times (Duplication)
Expand Down Expand Up @@ -50,7 +50,7 @@ Feature: Basic smell detection
Then it fails with exit status 2
And it reports:
"""
"spec/samples/optparse.rb" -- 117 warnings:
spec/samples/optparse.rb -- 117 warnings:
OptionParser has at least 59 methods (Large Class)
OptionParser#CompletingHash#match/block/block is nested (Nested Iterators)
OptionParser#Completion::complete calls candidates.size multiple times (Duplication)
Expand Down Expand Up @@ -176,7 +176,7 @@ Feature: Basic smell detection
Then it fails with exit status 2
And it reports:
"""
"spec/samples/redcloth.rb" -- 93 warnings:
spec/samples/redcloth.rb -- 93 warnings:
RedCloth has at least 44 methods (Large Class)
RedCloth#block has the variable name 'a' (Uncommunicative Name)
RedCloth#block has the variable name 'b' (Uncommunicative Name)
Expand Down
21 changes: 11 additions & 10 deletions features/stdin.feature
Expand Up @@ -7,26 +7,27 @@ Feature: Reek reads from $stdin when no files are given
Scenario: return zero status with no smells
When I pass "def simple() @fred = 3 end" to reek
Then it succeeds
And it reports:
"""
$stdin -- 0 warnings
"""

Scenario: outputs nothing on empty stdin
When I pass "" to reek
Then it succeeds
And stdout equals ""

Scenario: return non-zero status when there are smells
When I pass "def x() 3; end" to reek
Then it fails with exit status 2
And it reports:
"""
$stdin -- 0 warnings
Scenario: output nothing when no smells
When I pass "def simple() @fred = 3; end" to reek
Then it succeeds
And stdout equals ""
"""

Scenario: report smells correctly
Scenario: return non-zero status when there are smells
When I pass "class Turn; def y() @x = 3; end end" to reek
Then it fails with exit status 2
And it reports:
"""
$stdin -- 2 warnings:
Turn has the variable name '@x' (Uncommunicative Name)
Turn#y has the name 'y' (Uncommunicative Name)
Expand Down
2 changes: 1 addition & 1 deletion lib/reek/options.rb
Expand Up @@ -46,7 +46,7 @@ def self.parse(args)
if args.length > 0
return Source.from_pathlist(args)
else
return Source.from_io($stdin, 'stdin')
return Source.from_io($stdin, '$stdin')
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/reek/report.rb
Expand Up @@ -55,7 +55,7 @@ def full_report(desc)
end

def header(desc, num_smells)
result = "\"#{desc}\" -- #{num_smells} warning"
result = "#{desc} -- #{num_smells} warning"
result += 's' unless num_smells == 1
result += " (+#{@masked_smells.length} masked)" unless @masked_smells.empty?
result
Expand Down Expand Up @@ -94,7 +94,7 @@ def smelly_sources
@sources.select {|src| src.smelly? }
end

def to_s
def full_report
@sources.map { |src| src.full_report }.join("\n")
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/reek/source.rb
Expand Up @@ -118,6 +118,10 @@ def smelly?
@sources.any? {|source| source.smelly? }
end

def full_report
ReportList.new(@sources).full_report
end

def report
ReportList.new(@sources)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/slow/reek_source_spec.rb
Expand Up @@ -15,6 +15,6 @@
describe 'RakeTask' do
it 'should report no duplication' do
report = `rake reek`.split("\n")
report.length.should == 1
$?.exitstatus.should == 0
end
end

0 comments on commit 32893fc

Please sign in to comment.