简体   繁体   English

Rails 2.3.2单元测试在使用正常红宝石运行时通过,而在瑞克测试运行时失败:

[英]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.

相关问题 在Ruby on Rails中运行rake测试时出错 - Error when I run rake test in Ruby on Rails Rails 密码重置测试在单独运行时通过但在运行整个测试套件时失败 - Rails Password Reset Test Passes When Run Individually But Fails When Running the Entire Test Suite Ruby on Rails rake 测试:单元错误 - Ruby on Rails rake test:units error Rspec系统测试在单独运行时通过,在使用整个套件运行时失败 - Rspec System Test passes when run individually, fails when run with entire suite rspec 规范仅在整个测试套件中运行时才会失败 - 单独运行时通过 - rspec spec fails only when run in entire test suite - passes when run individually 无法运行rake测试Rails - Cannot run rake test Rails 在Rails中从Minitest切换到RSpec时,如何使“ rails test”(或“ rake test”)运行RSpec测试? - When switching from Minitest to RSpec in Rails, how to make `rails test` (or `rake test`) run the RSpec tests? 抽佣测试:单位失败,状态为() - rake test:units fails with status () 瑞克测试:单位失败,状态为(1) - Rake test:units fails with status(1) 如何使用 Unit::Test 在 Ruby on Rails 3.0.7 中运行单个测试? - How to run a single test in Ruby on Rails 3.0.7 using Unit::Test?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM