ruby-on-rails - 新 Rails 3 项目中的未定义方法 `use_transactional_fixtures='

标签 ruby-on-rails testing

尝试使用 MongoDB 和 Mongoid 在 Rails3 项目中运行我的测试时出现错误:

undefined method `use_transactional_fixtures=' for ActiveSupport::TestCase:Class

这是一个运行在 3.0.7 上的全新项目。我的 test_helper.rb 文件正是这样的:

ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

class ActiveSupport::TestCase

  self.use_transactional_fixtures = true

end

这是一个仅适用于 ActiveRecord 的方法吗?我在其他也使用 ActiveSupport::TestCase 的 Rails 项目中没有这个问题。此外,我正在使用 Fabricator 生成我的测试数据,但这并不能真正解释这个错误。

最佳答案

事情是这样的:use_transactional_filters 是/rails/test_helper.rb 中定义的方法

module ActiveRecord
  module TestFixtures
    extend ActiveSupport::Concern

    included do

      class_attribute :use_instantiated_fixtures   # true, false, or :no_instances
    end
  end
end

所以实际上它是特定于 ActiveRecord 的。因为我没有在我的项目中使用 ActiveRecord,所以这没有效果,我将不得不找到另一种方法来在测试运行之间清除我的数据库。

关于ruby-on-rails - 新 Rails 3 项目中的未定义方法 `use_transactional_fixtures=',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5904129/

相关文章:

ruby-on-rails - 使用 pik 后,gem 列表不显示本地 gems

android - 机器人 : getCurrentViews() Null pointer exception

.net - .NET 是否有一个好的 http 级别测试框架?

google-app-engine - 部署在 Google App Engine 上的测试服务器

java - 关于带有测试自动化的 IntelliJ 项目结构的问题

ruby-on-rails - Rake 命令在终端中有效,但在 crontab 中无效

ruby-on-rails - Heroku 和 Rails : how to set utf-8 as the default encoding

ruby-on-rails - 从 Backbone 检索 rails/devise current_user

javascript - 在脚本式的高光效果*之后*如何发生一些事情

java - 让我的 Spring 测试切片扫描单个类而不是整个包