Trailblazer and Minitest - NameError: uninitialized constant MiniTest

Trailblazer and Minitest - NameError: uninitialized constant MiniTest

环境:

rails -v
Rails 4.2.5

ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux-gnu]

bundle list trailblazer
trailblazer-1.1.0

我正在研究 Trailblazer 书中的示例,但我 运行 遇到了我不理解的情况。按照书中给出的设置,当我 运行 使用 bundle rake test/concerns/ar_invoice/crud_test.rb 进行特定测试时,它 运行 符合预期。但是,如果我只是 运行 bundle rake test 那么我会看到这个:

bundle rake test
rake aborted!
NameError: uninitialized constant MiniTest
./test/concepts/ar_invoice/crud_test.rb:1:in `<top (required)>'
./bundle/lib/gems/railties-4.2.5/lib/rails/test_unit/sub_test_task.rb:114:in `block (3 levels) in define'
./bundle  /lib/gems/railties-4.2.5/lib/rails/test_unit/sub_test_task.rb:114:in `each'
./bundle/lib/gems/railties-4.2.5/lib/rails/test_unit/sub_test_task.rb:114:in `block (2 levels) in define'
./bundle/lib/gems/railties-4.2.5/lib/rails/test_unit/sub_test_task.rb:113:in `each'
./bundle/lib/gems/railties-4.2.5/lib/rails/test_unit/sub_test_task.rb:113:in `block in define'
./bundle/lib/gems/railties-4.2.5/lib/rails/test_unit/sub_test_task.rb:20:in `invoke_rake_task'
./bundle/lib/gems/railties-4.2.5/lib/rails/test_unit/testing.rake:8:in `block in   <top (required)>'
Tasks: TOP => test:run
(See full trace by running task with --trace)

文件 crud_test.rb 包含以下内容:

cat test/concepts/ar_invoice/crud_test.rb

class ARInvoiceCrudTest < MiniTest::Spec
  describe( "Create" ) do
    it( "persists valid" ) do
      ar_invoice = ARInvoice::Create.(
        :ar_invoice => { :invoice_number => 101,
                         :client_number => 1234
        }
      ).model

      ar_invoice.persisted?.must_equal( true )
      ar_invoice.invoice_number.must_equal( 102 )
      ar_invoice.client_number.must_equal( 5678 )
    end
  end
end

而 .test/test_helper.rb 看起来像这样:

cat test/test_helper.rb

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)

require 'rails/test_help'
require 'minitest/spec'
require "minitest/autorun"

require "trailblazer/rails/test/integration"

并且env | grep RAILS_ENV没有输出。

我在设置中还缺少什么? 运行宁 bundle rake test 不应该简单地拿起 crud_test.rb 文件和 运行 测试与在命令行上明确命名文件时相同吗?

这是答案:

当然,在每个测试文件的顶部添加 require 'test_helper'