在 Rspec 中禁用事务装置没有效果
由于我使用的是旧数据库,我只能使用 MyISAM 的 MySQL,这意味着我的表不支持事务。这导致测试失败,因为测试生成的表数据(我使用factory_girl作为固定装置)不会针对每个场景进行恢复。
我发现 Rspec 公开了spec_helper.rb 中的 config.use_transactional_fixtures 配置设置。
默认情况下设置为 true。当我将其设置为 false 时,我没有看到对我的测试有任何影响;由于重复记录,它们仍然失败。
该设置是否应该自动展开对数据库所做的任何更改?或者我应该手动执行此操作?
Due to a legacy database I'm using, I'm stuck with MySQL using MyISAM, which means my tables don't support transactions. This is causing the tests to fail, since table data generated (I'm using factory_girl for fixtures) by the tests are not reverted for each scenario.
I discovered that Rspec exposes the config.use_transactional_fixtures
config setting in spec_helper.rb.
which is set to true by default. When I set it to false, I don't see any effect on my tests; they still fail due to duplicate records.
Isn't that setting supposed to automatically unroll any changes made to the DB? Or am I supposed to do that manually?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是对的 - 如果你的数据库不支持事务,你必须在每个语句之前发出几个 SQL 命令来擦除数据:
每个表一个。
在你的 helper.rb 中试试这个:
You're correct - if your database doesn't support transactions you must issue several SQL commands to wipe out data before each statement:
One for each of your tables.
In your helper.rb try this: