简体   繁体   English

Rails 3和Rspec 2关闭各个测试的事务夹具

[英]Rails 3 and Rspec 2 turn off transactional fixtures for individual tests

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. 我正在将我的应用程序升级到Rails 3.我开始在Rails 3中使用Rspec 2.我需要为我的一些rspec测试关闭事务装置。 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? 有没有办法在Rails 3中使用Rspec 2的每个测试块执行此操作?

I'm looking for the answer to this question, came across this blog entry 我正在寻找这个问题的答案,遇到了这篇博客文章

It suggests to declare inside the describe block 它建议在describe块中声明

describe "xxx" do
  self.use_transactional_fixtures = false
  ...

I tried it with Rails 3.0.7 with RSpec 2.6.3, and looks like working. 我用Rails 3.0.7和RSpec 2.6.3试了一下,看起来很像。

You can disable transactional fixtures globally by putting config.use_transactional_fixtures = false on the spec_helper.rb. 您可以通过在config.use_transactional_fixtures = false上放置config.use_transactional_fixtures = false来全局禁用事务夹具。 If you want to control them by test (eg use transactional just on some of them), you can set this behavior with DatabaseCleaner. 如果您想通过测试来控制它们(例如,只使用其中一些事务处理),您可以使用DatabaseCleaner设置此行为。

I've had a related problem when testing pages with javascript on the browser (a scenario that does not work with transactional fixtures). 我在浏览器上使用javascript测试页面时遇到了相关问题(这种情况不适用于事务性灯具)。 Here's how I managed to work around it: http://github.com/lailsonbm/contact_manager_app 以下是我设法解决它的方法: http//github.com/lailsonbm/contact_manager_app

RSpec.configure do |config|
  config.use_transactional_fixtures = true
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM