如何在 Rails 中正确设置事务装置?
我昨天刚刚开始一个新项目,遇到了很多非常奇怪的事务固定问题。听起来这是 Rails 的一个问题,所以我希望 StackOverflow 能够提供帮助。这是概要。
同事可以很好地运行测试。他们运行的是 Mac OS X;我正在运行 Ubuntu。
当
use_transactional_fixtures
为true
时,许多测试都会失败,并显示can't find [record] with ID=[some-id]
。我的同事在此模式下运行,但没有遇到任何问题。如果我将
use_transactional_fixtures
设置为false
,几乎所有之前失败的测试都会再次通过。我的同事没有看到任何差异,只是测试运行速度稍慢,因为不再使用事务。当测试单独运行时(
rake spec SPEC=spec/some-specific-spec.rb
)且固定装置为false
,有在测试 #1,234 中失败,并且仅测试 #1,234。当测试全部一起(
rake规范
)运行且固定装置为false
时,测试#3,456中出现失败,并且仅测试 #3,456。这两个测试没有任何明显的相关性。有很多测试(超过 5,000 个),因此可能发生巧合似乎并不令人意外。
您会从这种情况中得出什么推论,以及您将如何解决它?
I just started a new project yesterday and I'm having a lot of very strange transactional fixture problems. It sounds like this is something of an issue with Rails, so I'm hoping StackOverflow can help. Here's the rundown.
Coworkers can run tests fine. They are running Mac OS X; I'm running Ubuntu.
When
use_transactional_fixtures
istrue
, lots of tests fail withcan't find [record] with ID=[some-id]
. My coworkers run in this mode, but experience no problems.If I set
use_transactional_fixtures
tofalse
, almost all of the previously failing tests pass again. My coworkers don't see a difference, except that the tests run moderately slower since transactions aren't being used anymore.When tests are run individually (
rake spec SPEC=spec/some-specific-spec.rb
) with fixtures onfalse
, there is a failure in test #1,234, and only test #1,234.When tests are run all together (
rake spec
) with fixtures onfalse
, there is a failure in test #3,456, and only test #3,456.These two tests are not related in any apparent way. There are a lot of tests (over 5,000), so it doesn't seem terribly surprising that there might be a coincidence happening.
What inferences would you draw from this situation, and how would you go about fixing it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来最新的 Rails-rspec2 有问题:
http://github.com/rspec/rspec-rails/issues/issue/ 58
Looks like there is an issue with latest rails-rspec2:
http://github.com/rspec/rspec-rails/issues/issue/58