Rails 3 和 Rspec 2 为单个测试关闭事务性装置 [英] Rails 3 and Rspec 2 turn off transactional fixtures for individual tests

查看:18
本文介绍了Rails 3 和 Rspec 2 为单个测试关闭事务性装置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我的应用程序升级到 Rails 3.我开始在 Rails 3 中使用 Rspec 2.我需要关闭一些 rspec 测试的事务性装置.之前我在我的模型规范中使用了以下代码

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

现在给了我错误:

 Failure/Error: ActiveSupport::TestCase.use_transactional_fixtures = false
     undefined method `use_transactional_fixtures=' for ActiveSupport::TestCase:Class

有没有办法在带有 Rspec 2 的 Rails 3 中按测试块执行此操作?

Is there a way to do this per test block in Rails 3 with Rspec 2?

推荐答案

我正在寻找这个问题的答案,遇到了 此博客条目

I'm looking for the answer to this question, came across this blog entry

建议在describe块内声明

It suggests to declare inside the describe block

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

我在 Rails 3.0.7 和 RSpec 2.6.3 上尝试过,看起来可以正常工作.

I tried it with Rails 3.0.7 with RSpec 2.6.3, and looks like working.

这篇关于Rails 3 和 Rspec 2 为单个测试关闭事务性装置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆