Rails 3 和 Rspec 2 关闭单个测试的事务装置
我正在将我的应用程序升级到 Rails 3。我开始将 Rspec 2 与 Rails 3 一起使用。我需要关闭一些 rspec 测试的事务装置。之前我在模型规范中使用了以下代码
before(:all) do
ActiveSupport::TestCase.use_transactional_fixtures = false
end
after(:all) do
ActiveSupport::TestCase.use_transactional_fixtures = true
clean_engine_database
end
现在给了我错误:
Failure/Error: ActiveSupport::TestCase.use_transactional_fixtures = false
undefined method `use_transactional_fixtures=' for ActiveSupport::TestCase:Class
有没有办法在 Rails 3 中使用 Rspec 2 对每个测试块执行此操作?
I am in the process of upgrading my application to Rails 3. I started using Rspec 2 with Rails 3. I need to turn off transactional fixtures for some of my rspec tests. Prior I used the following code in my model specs
before(:all) do
ActiveSupport::TestCase.use_transactional_fixtures = false
end
after(:all) do
ActiveSupport::TestCase.use_transactional_fixtures = true
clean_engine_database
end
That now gives me the error:
Failure/Error: ActiveSupport::TestCase.use_transactional_fixtures = false
undefined method `use_transactional_fixtures=' for ActiveSupport::TestCase:Class
Is there a way to do this per test block in Rails 3 with Rspec 2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我正在寻找这个问题的答案,遇到这个博客条目
它建议在描述块内声明
我用 Rails 3.0.7 和 RSpec 2.6.3 尝试过,看起来可以工作。
I'm looking for the answer to this question, came across this blog entry
It suggests to declare inside the describe block
I tried it with Rails 3.0.7 with RSpec 2.6.3, and looks like working.
您可以通过在spec_helper.rb上放置
config.use_transactional_fixtures = false
来全局禁用事务装置。如果您想通过测试来控制它们(例如,仅对其中一些使用事务性),您可以使用 DatabaseCleaner 设置此行为。我在浏览器上使用 javascript 测试页面时遇到了相关问题(这种情况不适用于事务装置)。以下是我设法解决这个问题的方法: http://github.com/lailsonbm/contact_manager_app
You can disable transactional fixtures globally by putting
config.use_transactional_fixtures = false
on the spec_helper.rb. If you want to control them by test (e.g. use transactional just on some of them), you can set this behavior with DatabaseCleaner.I've had a related problem when testing pages with javascript on the browser (a scenario that does not work with transactional fixtures). Here's how I managed to work around it: http://github.com/lailsonbm/contact_manager_app