[英]Rails 2.3.2 unit test passes when run with normal ruby, fails when run with rake test:units
When creating a record in a unit test, I'm getting an 'ActiveRecord::RecordInvalid' when it's run with rake test:units. 在单元测试中创建记录时,当它与rake test:units一起运行时,我得到的是“ ActiveRecord :: RecordInvalid”。 I don't get this error when I run the unit test manually with ruby ('ruby unit/blah_test.rb').
当我使用ruby手动运行单元测试时,我没有得到这个错误('ruby unit / blah_test.rb')。 I've narrowed the issue down to a validation that exists in my model.
我将问题缩小为模型中存在的验证。 It is an inclusion validation which is actually performing a find against a different model to get the valid values.
这是一个包含验证,实际上是针对其他模型执行查找以获取有效值。 I'm thinking this is related to the fixtures not being loaded in time, but I do have 'fixtures :all' in my test_helper.rb (I've also tried including 'fixtures :all' in the unit test itself.
我认为这与未及时加载固定装置有关,但我的test_helper.rb中确实包含“ fixtures:all”(我也尝试过在单元测试中包含“ fixtures:all”。
Does anyone have any suggestions on how I can try to narrow this down even further? 有人对我如何进一步缩小范围有任何建议吗?
Thanks. 谢谢。
Certainly what you are seeing would fit with fixtures being missing. 当然,您所看到的将与缺少的灯具相匹配。 With
rake test:units
the test database schema will be set up (and cleared) so your included model's fixtures may not be populated. 使用
rake test:units
将会建立(并清除)测试数据库架构,因此可能不会填充您所包含的模型的固定装置。 With the direct call you'll be using the test database in the state you last left it which probably does include the fixutres for the included model. 通过直接调用,您将以上次离开数据库的状态使用测试数据库,该数据库可能确实包含所包含模型的fixutres。
Is there another call to fixtures
in the test class which may be causing fixtures :all
not to kick in? 在测试类中是否还有另一个对
fixtures
调用,这可能会导致fixtures :all
无法踢入?
You could try doing rake db:test:prepare
prior to running your test via ruby which would mean you were running on a fresh test database. 您可以在通过ruby运行测试之前尝试进行
rake db:test:prepare
,这意味着您正在新的测试数据库上运行。 This would further highlight if the fixtures aren't being loaded for your included model. 这将进一步突出显示是否未为包含的模型加载固定装置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.