在单个Ruby文件上使用guard-minitest

时间:2012-10-13 07:21:22

标签: ruby testing guard minitest

我显然做错了什么。我正在尝试在单个文件中编写和测试纯红宝石。我希望看守文件和测试文件,并在文件更改时随时运行minitest。

所以,有两个文件:game.rb和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

我还有一个看起来像这样的Guardfile:

notification :terminal_notifier

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

现在,我可能忘了什么,但我不能为我的生活弄清楚它是什么。

如果我开始守卫并按Enter键,则“全部运行”并且测试运行..至少大部分时间。但是,我必须按Enter键才能实现。

另外,如果我对文件进行了更改,则没有任何反应。我已经尝试将gem'rb-fsevent'放在Gemfile中并使用“bundle exec guard”运行,但这似乎也无济于事。

非常感谢任何帮助。我疯了。

谢谢, 杰里米

1 个答案:

答案 0 :(得分:5)

您的第一个“监视”定义将简单地传递“game.rb”,这不是测试文件,因此不会运行。 第二个“监视”是正确的,所以当你保存“game_test.rb”时,测试应该运行。

这应该是一个更正确的Guardfile:

notification :terminal_notifier

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