【问题标题】:Rails 4.1, Guard 2.10, and Minitest 5.4.1 -- RuntimeError & Rails::Generators::TestCaseRails 4.1、Guard 2.10 和 Minitest 5.4.1——RuntimeError 和 Rails::Generators::TestCase
【发布时间】:2014-12-06 03:57:04
【问题描述】:

我正在尝试在一个新的 Rails 4 项目中使用 Minitest 设置 Guard。我用以下内容更新了我的 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 中的某些东西需要配置才能正常工作?

【问题讨论】:

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


    【解决方案1】:

    想通了——显然它认为这个类是一个生成器。将以下行添加到 class TestCase 块内的 test_helper.rb 解决了该问题:

    register_spec_type(/ClassToBeTested/, Minitest::Spec)
    

    有没有办法让test/services/ 中的所有类都被子类化到 Minitest::Spec 下,而不是 Generator 测试类?

    【讨论】:

    • ClassToBeTested 的实际名称是什么?它是否以Generator 结尾?
    • ......也许吧。这是ThingGenerator。如果我将它切换到GenerateThings,而不必担心register_spec_type 调用?
    猜你喜欢
    • 1970-01-01
    • 2012-06-04
    • 1970-01-01
    • 2017-01-18
    • 1970-01-01
    • 2011-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多