Last active
August 29, 2015 14:07
-
-
Save hisapy/bf5080f54debc0ba5785 to your computer and use it in GitHub Desktop.
Count false/real positives based on rspec failed examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'getoptlong' | |
opts = GetoptLong.new( | |
[ '--help', '-h', GetoptLong::NO_ARGUMENT ], | |
[ '--rspec-command', '-r', GetoptLong::REQUIRED_ARGUMENT ], | |
[ '--suite-output-file', '-f', GetoptLong::REQUIRED_ARGUMENT ] | |
) | |
@rspec = "zeus test" | |
@filename = "./spec/full_suite_output.txt" | |
opts.each do |opt, arg| | |
case opt | |
when '--help' | |
puts <<-EOF | |
verify_rspec_failed_examples [OPTION] | |
-h, --help: | |
show help | |
--rspec-command [command], -r [command]: | |
string indicating the command to be used, ie.: "bundle exec rspec" | |
--suite-output-file [command], -f [file]: | |
the file containing the fullsuite output with failed examples descriptions (defaults to ./full_suite_output.txt) | |
EOF | |
when '--rspec-command' | |
@rspec = arg.to_i | |
when '--suite-output-file' | |
@filename = arg | |
end | |
end | |
failures_section = false | |
false_positives_count = 0 | |
real_positives_count = 0 | |
File.open(@filename).each_line do | l | | |
if failures_section && l.match(/^rspec.*/) && ! l.match(/spec\/support/) | |
false_positive = system("#{@rspec} #{l.gsub(/rspec|#.*/, '')}") | |
if false_positive === true | |
false_positives_count+=1 | |
elsif false_positive === false | |
real_positives_count+=1 | |
end | |
elsif l && l.match(/Failed Examples/i) && !failures_section | |
failures_section = true | |
puts 'Running each failure individually' | |
puts "=================================\n" | |
puts | |
end | |
end | |
puts "\n\n" | |
puts "No failed examples found" if failures_section == false | |
puts "#{false_positives_count} false positives found" | |
puts "#{real_positives_count} individual positives found" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment