Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quoth/57981d191eb72741a2e8948b9f03bc36 to your computer and use it in GitHub Desktop.
Save quoth/57981d191eb72741a2e8948b9f03bc36 to your computer and use it in GitHub Desktop.
#!/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