Created
December 4, 2016 17:08
-
-
Save mitramejia/98b6f34b498e1dc1e5199e30d1ca5ba1 to your computer and use it in GitHub Desktop.
pre-push git hook, a ruby script to run behat tests before a git push is executed. If tests pass git push will be allowed
This file contains hidden or 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 'colorize' | |
require 'git' | |
# Get working directory and make git read it | |
working_dir = "/Users/yourname/app" | |
git = Git.open working_dir | |
# Get current git branch | |
current_branch = git.branches.select { |branch| branch.current == true }.first | |
result = Dir.chdir "#{working_dir}/site" do | |
# Display info | |
puts "\n*".light_blue | |
puts "* Running tests for ".light_blue + "#{current_branch}".light_blue.bold | |
puts "*\n".light_blue | |
# Run Behat tests wihout interactive questions '-n' | |
system "bin/behat -n" | |
end | |
# Print result and exit if any test failed | |
if result | |
puts "\n*".green | |
puts "* All tests passed. Pushing branch ".green + "#{current_branch}".green.bold | |
puts "*\n".green | |
else | |
puts "\n=".red | |
puts "One ore more tests failed - push deniend".red.bold | |
puts "=\n".red | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment