From ea6bc4e08d3140838e7cb95b56c1b569c47749df Mon Sep 17 00:00:00 2001 From: Kevin Rutherford Date: Thu, 9 Jul 2009 16:07:47 +0100 Subject: [PATCH] Spec failure reports are now quiet --- lib/reek/report.rb | 12 ++++++++++++ lib/reek/source.rb | 8 ++++++++ lib/reek/spec.rb | 6 +++--- spec/reek/spec_spec.rb | 21 +++++++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/lib/reek/report.rb b/lib/reek/report.rb index 8d702d252..66c73f165 100644 --- a/lib/reek/report.rb +++ b/lib/reek/report.rb @@ -60,6 +60,14 @@ def full_report(desc) result end + def quiet_report(desc) + return if @warnings.empty? + result = header(desc, @warnings.length) + result += ":\n#{to_s}" if should_report + result += "\n" + result + end + def should_report @warnings.length > 0 or (Options[:show_all] and @masked_warnings.length > 0) end @@ -106,6 +114,10 @@ def full_report @sources.map { |src| src.full_report }.join end + def quiet_report + @sources.map { |src| src.quiet_report }.join + end + # # Checks this report for instances of +smell_class+, and returns +true+ # only if one of them has a report string matching all of the +patterns+. diff --git a/lib/reek/source.rb b/lib/reek/source.rb index bab68bf4f..294ea80f1 100644 --- a/lib/reek/source.rb +++ b/lib/reek/source.rb @@ -101,6 +101,10 @@ def full_report report.full_report(@desc) end + def quiet_report + report.quiet_report(@desc) + end + def to_s @desc end @@ -130,6 +134,10 @@ def full_report ReportList.new(@sources).full_report end + def quiet_report + ReportList.new(@sources).quiet_report + end + def report ReportList.new(@sources) end diff --git a/lib/reek/spec.rb b/lib/reek/spec.rb index c0f48ffc1..e49b30a8f 100644 --- a/lib/reek/spec.rb +++ b/lib/reek/spec.rb @@ -49,7 +49,7 @@ def failure_message_for_should "Expected source to reek, but it didn't" end def failure_message_for_should_not - "Expected no smells, but got:\n#{@source.full_report}" + "Expected no smells, but got:\n#{@source.quiet_report}" end end @@ -66,7 +66,7 @@ def failure_message_for_should "Expected #{@source} to reek of #{@klass}, but it didn't" end def failure_message_for_should_not - "Expected #{@source} not to reek of #{@klass}, but got:\n#{@source.full_report}" + "Expected #{@source} not to reek of #{@klass}, but got:\n#{@source.quiet_report}" end end @@ -80,7 +80,7 @@ def matches?(actual) @source.report.length == 1 and @source.has_smell?(@klass, @patterns) end def failure_message_for_should - "Expected source to reek only of #{@klass}, but got:\n#{@source.full_report}" + "Expected source to reek only of #{@klass}, but got:\n#{@source.quiet_report}" end def failure_message_for_should_not "Expected source not to reek only of #{@klass}, but it did" diff --git a/spec/reek/spec_spec.rb b/spec/reek/spec_spec.rb index 52398f949..b431f6d22 100644 --- a/spec/reek/spec_spec.rb +++ b/spec/reek/spec_spec.rb @@ -66,3 +66,24 @@ @matcher.failure_message_for_should_not.should include(@smelly_file.to_source.full_report) end end + +describe ShouldReek, 'report formatting' do + before :each do + @smelly_dir = Dir['spec/samples/mixed_results/*.rb'] + @matcher = ShouldReek.new + @matcher.matches?(@smelly_dir) + @lines = @matcher.failure_message_for_should_not.split("\n").map {|str| str.chomp} + @error_message = @lines.shift + @smells = @lines.grep(/^ /) + @headers = (@lines - @smells) + end + + it 'mentions every smell in the report' do + @smells.should have(12).warnings + end + + it 'doesnt mention the clean files' do + @headers.should have(2).headers + @headers.should_not include('clean') + end +end