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

标签 ruby testing guard minitest

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

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

游戏.rb

class Game
end

游戏测试.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

现在,我可能忘记了什么,但我终究无法弄清楚它是什么。

如果我启动 guard 并按 Enter,“全部运行”会发生并且测试会运行……至少大部分时间是这样。但是,我必须按 Enter 键才能发生。

此外,如果我对文件进行更改,则什么也不会发生。我试过将 gem 'rb-fsevent' 放入 Gemfile 并使用“bundle exec guard”运行,但这似乎也无济于事。

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

谢谢, 杰里米

最佳答案

您的第一个“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

关于ruby - 在单个 Ruby 文件上使用 guard-minitest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12870935/

相关文章:

ruby - 如何在ruby中获取字符串数组的总和

iphone - 在设备上运行 OCUnit 应用程序测试套件时偶尔会出错

testing - 如何测试 WSDL

c++ - C++中的重新定义,头文件中的先前定义?

ruby-on-rails - Guard-rspec 和 ember 不能很好地协同工作

ruby - 将数组作为值插入另一个数组

ruby - 哪个 Ruby 版本更可取?

ruby - NoMethodError,在sinatra中调用属性

javascript - 如何使用单个命令运行多个 QUnit (node.js) 测试文件?

c++ - 有没有Makefile依赖的 "watch"/"monitor"/"guard"程序?