【问题标题】:Using guard-minitest on a single Ruby file在单个 Ruby 文件上使用 guard-minitest
【发布时间】:2012-10-03 23:16:16
【问题描述】:

我显然做错了什么。我正在尝试在单个文件中编写和测试纯红宝石。我想让守卫观察文件和测试文件,并在任何文件更改时运行 minitest。

所以,两个文件:game.rb 和 game_test.rb

游戏.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”运行,但这似乎也无济于事。

任何帮助将不胜感激。我要疯了。

谢谢, 杰里米

【问题讨论】:

    标签: ruby testing guard minitest


    【解决方案1】:

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

    这应该是更正确的Guardfile:

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

    【讨论】:

    • 所以,我试过了,但没有运气。我唯一能做的就是 watch('game.rb') { './game_test.rb' } 里面有相对目录。我真的不明白为什么。有什么想法吗?
    • 如果有什么安慰的话,我也有同样的问题。我必须对这两个文件做同样的事情(相当于watch('game.rb') { './game_test.rb' }; watch('game_test.rb') { './game_test.rb') }.
    • 这很奇怪,不要犹豫report any issue to guard-minitest(也一定要在调试模式下运行Guard,只需使用--debug 标志启动它)。另外,我建议您从guard-minitest's Guardfile template 中获取灵感。
    猜你喜欢
    • 2017-01-18
    • 1970-01-01
    • 1970-01-01
    • 2012-07-19
    • 1970-01-01
    • 2013-09-22
    • 2011-10-16
    • 2011-08-18
    • 2014-02-22
    相关资源
    最近更新 更多