Rails 3 和 Rspec 2 关闭单个测试的事务装置

发布于 2024-09-26 23:26:39 字数 588 浏览 4 评论 0原文

我正在将我的应用程序升级到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

来世叙缘 2024-10-03 23:26:39

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

它建议在描述块内声明

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

我用 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

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.

半城柳色半声笛 2024-10-03 23:26:39
RSpec.configure do |config|
  config.use_transactional_fixtures = true
end
RSpec.configure do |config|
  config.use_transactional_fixtures = true
end
鱼窥荷 2024-10-03 23:26:39

您可以通过在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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文