Skip to content

Instantly share code, notes, and snippets.

@bak
Forked from jhelwig/Guardfile
Created December 5, 2012 21:23
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 bak/4219636 to your computer and use it in GitHub Desktop.
Save bak/4219636 to your computer and use it in GitHub Desktop.
Auto-commit & run tests on every save
# More info at https://github.com/guard/guard#readme
ignore /^coverage\//
require 'tempfile'
notification :'terminal_notifier'
#notification :tmux,
# :display_message => true,
# :timeout => 5, # in seconds
# :default_message_format => '%s >> %s',
# # the first %s will show the title, the second the message
# # Alternately you can also configure *success_message_format*,
# # *pending_message_format*, *failed_message_format*
# :line_separator => ' > ' # since we are single line we need a separator
guard 'minitest' do
# with Minitest::Unit
watch(/^test\/(.*)\/?(.*)_test\.rb/)
watch(/^(lib\/.*)([^\/]+)\.rb/) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
watch(/^test\/test_helper\.rb/) { "test" }
end
# Add files and commands to this file, like the example:
# watch(%r{file/path}) { `command(s)` }
#
guard 'shell' do
watch(/(.*)/) do |m|
if system("git ls-files --exclude-standard -d -o -m | egrep '.' > /dev/null")
test_output = Tempfile.new('guard_commit_test_output')
test_output.close
tests_passing = system("rake 2>&1 >> #{test_output.path}")
commit_message = Tempfile.new('guard_commit_message')
commit_message.write("WIP: #{m[0]} (Tests: #{tests_passing ? 'passing' : 'failing'})\n\n")
commit_message.write(File.read test_output.path)
commit_message.close
system('git add -A')
system("git commit -F #{commit_message.path}")
test_output.unlink
commit_message.unlink
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment