From 32893fcab01a55e234bb2bade21e7d78328992b5 Mon Sep 17 00:00:00 2001 From: Kevin Rutherford Date: Sun, 28 Jun 2009 22:07:59 +0100 Subject: [PATCH] Header now printed for every source --- bin/reek | 7 ++----- features/masking_smells.feature | 4 ++-- features/samples.feature | 6 +++--- features/stdin.feature | 21 +++++++++++---------- lib/reek/options.rb | 2 +- lib/reek/report.rb | 4 ++-- lib/reek/source.rb | 4 ++++ spec/slow/reek_source_spec.rb | 2 +- 8 files changed, 26 insertions(+), 24 deletions(-) diff --git a/bin/reek b/bin/reek index 83f9d360f..b18d30c89 100755 --- a/bin/reek +++ b/bin/reek @@ -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 diff --git a/features/masking_smells.feature b/features/masking_smells.feature index 0d1f503f2..634360496 100644 --- a/features/masking_smells.feature +++ b/features/masking_smells.feature @@ -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) @@ -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) diff --git a/features/samples.feature b/features/samples.feature index 5644a3b88..5a462d908 100644 --- a/features/samples.feature +++ b/features/samples.feature @@ -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) @@ -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) @@ -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) diff --git a/features/stdin.feature b/features/stdin.feature index dcb095cbe..5c1d7d1b5 100644 --- a/features/stdin.feature +++ b/features/stdin.feature @@ -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) diff --git a/lib/reek/options.rb b/lib/reek/options.rb index e446e4937..37bb294b5 100644 --- a/lib/reek/options.rb +++ b/lib/reek/options.rb @@ -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 diff --git a/lib/reek/report.rb b/lib/reek/report.rb index 9c0e515b5..b56978994 100644 --- a/lib/reek/report.rb +++ b/lib/reek/report.rb @@ -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 @@ -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 diff --git a/lib/reek/source.rb b/lib/reek/source.rb index 85a36d83f..ca4af059e 100644 --- a/lib/reek/source.rb +++ b/lib/reek/source.rb @@ -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 diff --git a/spec/slow/reek_source_spec.rb b/spec/slow/reek_source_spec.rb index 5030f7653..0b2a69aa7 100644 --- a/spec/slow/reek_source_spec.rb +++ b/spec/slow/reek_source_spec.rb @@ -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