我想从模型开始将现有的 rails 应用程序从 rspec 切换到 minitest。因此我创建了一个文件夹test
。在里面我创建了一个文件minitest_helper.rb
,其内容如下:
require "minitest/autorun"
ENV["RAILS_ENV"] = "test"
和models
包含的文件夹forum_spec.rb
:
require "minitest_helper"
describe "one is really one" do
before do
@one = 1
end
it "must be one" do
@one.must_equal 1
end
end
现在我可以运行ruby -Itest test/models/forum_spec.rb
以下结果:
Loaded suite test/models/forum_spec
Started
.
Finished in 0.000553 seconds.
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
Test run options: --seed 12523
那很好。但现在我希望加载环境,并将以下行添加到minitest_helper.rb
(从 rspec 的等效文件复制):
require File.expand_path("../../config/environment", __FILE__)
现在我再次运行它,结果如下:
Loaded suite test/models/forum_spec
Started
Finished in 0.001257 seconds.
0 tests, 0 assertions, 0 failures, 0 errors, 0 skips
Test run options: --seed 57545
测试和断言消失了。这可能是什么原因?
系统信息:
- 红宝石 1.9.2p180(2011-02-18 修订版 30909)[x86_64-darwin10.8.0]
- 导轨 3.1.0.rc4