5

I'm clearly doing something wrong. I'm trying to write and test plain ruby in a single file. I want guard to watch the file and the test file and run minitest any time either file changes.

So, two files: game.rb and game_test.rb

game.rb

class Game
end

game_test.rb

require 'rubygems'
require 'minitest/autorun'
require './game'

class GameTest < MiniTest::Unit::TestCase
  def test_truth
    assert true
  end
end

I also have a Guardfile that looks like this:

notification :terminal_notifier

guard 'minitest', test_folders: '.' do
  watch('game.rb')
  watch('game_test.rb')
end

Now, I'm probably forgetting something, but I can't for the life of me figure out what it is.

If I start guard and press Enter, "Run All" happens and the tests run.. at least most of the time. However, I have to press Enter for it to happen.

Also, if I make a change to the files nothing happens. I've tried putting gem 'rb-fsevent' in a Gemfile and running with "bundle exec guard" but that doesn't seem to help either.

Any help would be much appreciated. I'm going nuts.

Thanks, Jeremy

1 Answer 1

5

Your first "watch" definition will simply pass "game.rb", which is not a test file so it won't be run. The second "watch" is correct so when you save "game_test.rb", the tests should run.

This should be a more correct Guardfile:

notification :terminal_notifier

guard 'minitest', test_folders: '.' do
  watch('game.rb') { 'game_test.rb' }
  watch('game_test.rb')
end
3
  • 2
    So, I tried that and had no luck. The only thing I could get working was watch('game.rb') { './game_test.rb' } with the relative directory in there. I really don't understand why. Any thoughts? Oct 20, 2012 at 16:31
  • 1
    If it's any consolation, I have the same problem. I had to do same thing for both files (the equivalent of watch('game.rb') { './game_test.rb' }; watch('game_test.rb') { './game_test.rb') }. Jul 29, 2013 at 6:43
  • That's weird, don't hesitate to report any issue to guard-minitest (also be sure to run Guard in debug mode, just start it with the --debug flag). Also, I advise you to take inspiration from the guard-minitest's Guardfile template.
    – rymai
    Mar 5, 2014 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.