Rails 4.1,Guard 2.10和Minitest 5.4.1 - RuntimeError&轨道::发电机:: TestCase的

时间:2014-12-05 19:37:56

标签: ruby-on-rails-4 guard minitest

我试图在新的Rails 4项目中设置Guard with Minitest。我使用以下内容更新了我的Gemfile:

group :development do
  gem 'guard'
  gem 'guard-minitest'
end

然后跑bundle exec guard init minitest

我有一个非常简单的测试:

require 'test_helper'

describe ClassToBeTested do
  describe "#initialize" do
    it "should return a ClassToBeTested object" do
      obj = ClassToBeTested.new
      obj.must_be_kind_of ClassToBeTested
    end
  end
end

正在测试的课程在app/services/class_to_be_tested.rb

当我运行bundle exec guard -n f时,我得到以下内容:

11:35:43 - INFO - Guard::Minitest 2.3.2 is running, with Minitest::Unit 5.4.1!
11:35:43 - INFO - Running: all tests
Run options: --seed 36837

# Running:

E

Finished in 0.005190s, 192.6728 runs/s, 0.0000 assertions/s.

  1) Error:
ClassToBeTested::#initialize#test_0001_should return a ClassToBeTested object:
RuntimeError: You need to configure your Rails::Generators::TestCase destination root.


1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
11:35:45 - INFO - Guard is now watching at '/home/sean/Code/Ruby/work/project'

我有什么遗失的东西吗? Guard / Minitest / Rails中的某些东西需要配置才能正常工作?

1 个答案:

答案 0 :(得分:0)

想出来 - 显然它认为这个班级是一个发电机。将以下行添加到class TestCase块内的test_helper.rb可修复问题:

register_spec_type(/ClassToBeTested/, Minitest::Spec)

有没有办法让test/services/中的所有类都在Minitest :: Spec下进行子类化,而不是Gene测试类?