Created
March 29, 2019 08:47
-
-
Save quoth/57981d191eb72741a2e8948b9f03bc36 to your computer and use it in GitHub Desktop.
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 'open3' | |
base_branch = ARGV[0] || 'master' | |
target_branch = ARGV[1] || 'HEAD' | |
stdout, stdin, status = Open3.capture3("git diff #{base_branch}..#{target_branch} --name-only") | |
raise "Failure. #{stdin}" unless status | |
spec_files = [] | |
stdout.split(/\n/).each do |file_name| | |
next unless file_name =~ /\.rb\Z/ | |
spec_files << if file_name.match?(/\_spec\.rb\Z/) | |
file_name | |
elsif file_name.match?(/routes.rb/) | |
file_name.gsub('routes.rb', 'routing_spec.rb') | |
else | |
file_name.gsub('app/', 'spec/').gsub('.rb', '_spec.rb') | |
end | |
end | |
puts '********** Checking diff **********' | |
puts "Checking between #{base_branch}..#{target_branch}" | |
puts '' | |
puts 'Files:' | |
spec_files.each do |file| | |
puts file.to_s | |
end | |
target_files = spec_files.uniq.select {|f| File.exist?(f) } | |
notfound_files = spec_files.uniq - target_files | |
unless notfound_files.empty? | |
puts '********** Not Found **********' | |
puts notfound_files.join("\n") | |
puts "\n" | |
end | |
if target_files.empty? | |
puts 'Test target have not been found.' | |
else | |
puts '********** Test Target **********' | |
puts target_files.join("\n") | |
puts '********** Executing Test **********' | |
puts "bundle exec rspec #{target_files.join(' ')}" | |
system "bundle exec rspec #{target_files.join(' ')}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment