Skip to content

Instantly share code, notes, and snippets.

@mwean
Created December 8, 2016 21:45
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 mwean/22446ec1dfc565986c86b73c6d35ca76 to your computer and use it in GitHub Desktop.
Save mwean/22446ec1dfc565986c86b73c6d35ca76 to your computer and use it in GitHub Desktop.
Run any changed specs
#!/usr/bin/env ruby
project_root = `git rev-parse --show-toplevel`.strip
git_status = `git status --porcelain --untracked-files=all`.split("\n")
changed_files = git_status.map { |line| line[3..-1] }
grouped_specs = Hash.new { |hash, key| hash[key] = [] }
changed_files.select { |file| file =~ /spec/ }.each do |spec|
project, file = spec.split("/spec/")
grouped_specs[project] << "spec/#{file}"
end
commands = grouped_specs.map do |project, specs|
"'cd #{project_root}/#{project} && bundle exec rspec #{specs.join(" ")}'"
end
system("parallel -vu -j #{grouped_specs.size} ::: #{commands.join(' ')}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment