Created
December 22, 2011 05:20
-
-
Save shuhei/1509029 to your computer and use it in GitHub Desktop.
Pre-commit hook for RSpec
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 | |
def bash_source(file) | |
`bash -c "source #{file}"` | |
end | |
# Make sure to use RVM | |
user_rvm = "#{ENV['HOME']}/.rvm/scripts/rvm" | |
system_rvm = "/usr/local/rvm/scripts/rvm" | |
if File.exists?(user_rvm) | |
bash_source user_rvm | |
elsif File.exists?(system_rvm) | |
bash_source system_rvm | |
else | |
puts "No RVM!" | |
puts '***** COMMIT FAILED *****' | |
exit 1 | |
end | |
`rvm reload` | |
# Run RSpec showing results on stdout and writing them into a temporary file. | |
out_path = '__spec_results__' | |
system "rspec -c -fp -fp -o #{out_path}" | |
last_line = File.open(out_path).read.split("\n").last | |
File.delete out_path | |
failed = (last_line =~ /, 0 failures/).nil? | |
if failed | |
puts '***** COMMIT FAILED *****' | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script should be placed in .git/hooks.