Permalink
Browse files

Setup warnings as part of the build.

- Always run specs with warnigs enabled.
- Fail the build if there are warnings from VCR's code.
- Capture the warnings and print it on exit so the output is cleaner.
  • Loading branch information...
myronmarston committed Aug 27, 2011
1 parent 7e2ef02 commit 297f028223ef8e551a07f8dd596817ca9e339720
Showing with 34 additions and 3 deletions.
  1. +3 −3 Rakefile
  2. +31 −0 spec/capture_warnings.rb
View
@@ -11,12 +11,12 @@ require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec) do |t|
t.verbose = false
- t.ruby_opts = "-w" if ENV['WARNINGS']
+ t.ruby_opts = "-w -r./spec/capture_warnings"
# I'm not sure why, but bundler seems to silence warnings...
- t.skip_bundler = true if ENV['WARNINGS'] || !using_git
+ t.skip_bundler = true
- t.rspec_opts = %w[--format progress] #if (ENV['FULL_BUILD'] || !using_git)
+ t.rspec_opts = %w[--format progress] if (ENV['FULL_BUILD'] || !using_git)
end
desc "Run all examples using rcov"
View
@@ -0,0 +1,31 @@
+require 'tempfile'
+stderr_file = Tempfile.new("vcr.stderr")
+$stderr.reopen(stderr_file.path)
+current_dir = Dir.pwd
+
+at_exit do
+ stderr_file.rewind
+ lines = stderr_file.read.split("\n").uniq
+ vcr_warnings, other_warnings = lines.partition { |line| line.include?(current_dir) }
+
+ if vcr_warnings.any?
+ puts
+ puts "-" * 30 + " VCR Warnings: " + "-" * 30
+ puts
+ puts vcr_warnings.join("\n")
+ puts
+ puts "-" * 75
+ puts
+ end
+
+ if other_warnings.any?
+ File.open('tmp/warnings.txt', 'w') { |f| f.write(other_warnings.join("\n")) }
+ puts
+ puts "Non-VCR warnings written to tmp/warnings.txt"
+ puts
+ end
+
+ # fail the build...
+ exit(1) if vcr_warnings.any?
+end
+

0 comments on commit 297f028

Please sign in to comment.