Skip to content

Instantly share code, notes, and snippets.

@jhelwig
Created December 4, 2012 16:11
Show Gist options
  • Save jhelwig/4205644 to your computer and use it in GitHub Desktop.
Save jhelwig/4205644 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