From 076cf64ff3052751277ba3d027d24e99ef04e0aa Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Thu, 17 Sep 2015 22:32:53 -0500 Subject: [PATCH] Disable coverage/warnings output when passing in dev --- .simplecov | 33 ++++++++++++++++++++++----------- .travis.yml | 2 +- test/capture_warnings.rb | 32 +++++++++++++++++++------------- 3 files changed, 42 insertions(+), 25 deletions(-) diff --git a/.simplecov b/.simplecov index 37d037a1..ce914ce6 100644 --- a/.simplecov +++ b/.simplecov @@ -49,21 +49,32 @@ Coverage.start ## ADD SOME CUSTOM REPORTING AT EXIT SimpleCov.at_exit do + next if $! and not ($!.kind_of? SystemExit and $!.success?) + header = "#{'*' * 20} SimpleCov Results #{'*' * 20}" - @output.puts - @output.puts header - @output.puts SimpleCov.result.format! + results = SimpleCov.result.format!.join("\n") + exit_message = <<-EOF + +#{header} +{{RESULTS}} +{{FAILURE_MESSAGE}} + +#{'*' * header.size} + EOF percent = Float(SimpleCov.result.covered_percent) if percent < @minimum_coverage - @output.puts "Spec coverage was not high enough: "\ - "#{percent.round(2)} is < #{@minimum_coverage}%\n" - exit 1 if @generate_report - else - @output.puts "Nice job! Spec coverage (#{percent.round(2)}) "\ - "is still at or above #{@minimum_coverage}%\n" + failure_message = <<-EOF +Spec coverage was not high enough: #{percent.round(2)}% is < #{@minimum_coverage}% + EOF + exit_message.sub!('{{RESULTS}}', results).sub!('{{FAILURE_MESSAGE}}', failure_message) + @output.puts exit_message + abort(failure_message) if @generate_report + elsif @running_ci + exit_message.sub!('{{RESULTS}}', results).sub!('{{FAILURE_MESSAGE}}', <<-EOF) +Nice job! Spec coverage (#{percent.round(2)}%) is still at or above #{@minimum_coverage}% + EOF + @output.puts exit_message end - @output.puts - @output.puts '*' * header.size end ## CAPTURE CONFIG IN CLOSURE 'AppCoverage.start' diff --git a/.travis.yml b/.travis.yml index 9aaaafdd..e52f9bae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ install: - bundle install --retry=3 script: - - bundle exec rake + - env CAPTURE_STDERR=false bundle exec rake - bundle exec rake rubocop env: diff --git a/test/capture_warnings.rb b/test/capture_warnings.rb index 5acdb3a0..1015fc00 100644 --- a/test/capture_warnings.rb +++ b/test/capture_warnings.rb @@ -26,38 +26,44 @@ class CaptureWarnings end end - # rubocop:disable Metrics/AbcSize def after_tests(lines) app_warnings, other_warnings = lines.partition { |line| line.include?(app_root) && !line.include?(bundle_dir) } - header = "#{'-' * 22} app warnings: #{'-' * 22}" - output.puts - output.puts header - if app_warnings.any? - output.puts app_warnings.join("\n") + warnings_message = app_warnings.join("\n") + print_warnings = true else - output.puts 'None. Yay!' + warnings_message = 'None. Yay!' + ENV['FULL_BUILD'] ||= ENV['CI'] + running_ci = ENV['FULL_BUILD'] =~ /\Atrue\z/i + print_warnings = running_ci end if other_warnings.any? File.write(File.join(output_dir, 'warnings.txt'), other_warnings.join("\n") << "\n") - output.puts - output.puts 'Non-app warnings written to tmp/warnings.txt' - output.puts + warnings_message << "\nNon-app warnings written to tmp/warnings.txt" + print_warnings = true end - output.puts - output.puts '-' * header.size + header = "#{'-' * 22} app warnings: #{'-' * 22}" + message = <<-EOF.strip_heredoc + + #{header} + + #{warnings_message} + + #{'-' * header.size} + EOF + + output.puts(message) if print_warnings # fail the build... if fail_on_warnings && app_warnings.any? abort "Failing build due to app warnings: #{app_warnings.inspect}" end end - # rubocop:enable Metrics/AbcSize private