Skip to content

Commit

Permalink
Spec failure reports are now quiet
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrutherford committed Jul 9, 2009
1 parent 0cc72b3 commit ea6bc4e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
12 changes: 12 additions & 0 deletions lib/reek/report.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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+.
Expand Down
8 changes: 8 additions & 0 deletions lib/reek/source.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/reek/spec.rb
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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"
Expand Down
21 changes: 21 additions & 0 deletions spec/reek/spec_spec.rb
Expand Up @@ -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

0 comments on commit ea6bc4e

Please sign in to comment.