“ActiveSupport::TestCase:Class 的未定义方法‘装置’"在使用 Rails 3.1 进行测试时 [英] "undefined method `fixtures' for ActiveSupport::TestCase:Class" while testing with Rails 3.1

查看:37
本文介绍了“ActiveSupport::TestCase:Class 的未定义方法‘装置’"在使用 Rails 3.1 进行测试时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Gem 编写测试,经过几个小时试图摆脱这种情况后,决定环顾四周 - 令我惊讶的是,Google 上没有一个对它的引用(除了 mongoid 上的一个,人们只是忽略了它).

I'm writing tests for a Gem and after a couple of hours trying to get rid of this, decided to look around - and to my surprise, there's not a single reference to it on Google (apart from one on mongoid, where people simply ignored it).

所以,问题很简单:我的测试初始化​​中有这个块:

So, the problem is simple: I have this block on my test initialization:

class ActiveSupport::TestCase
  fixtures :all
end

但测试无法执行:

`<class:TestCase>': undefined method `fixtures' for ActiveSupport::TestCase:Class (NoMethodError)

gem 依赖于 Rails 3,并且检查每个依赖项双重检查.代码在 github 上,以防有人想检查(https://github.com/herval/acts_as_recommendable)我没有想法了.有人分享一盏灯吗?

The gem depends on Rails 3 and every dependency is checked & double-checked. The code is on github, in case anyone wants to check (https://github.com/herval/acts_as_recommendable) I'm out of ideas. Anyone share a light?

推荐答案

我已经很久没有使用 Rails 的内置测试了,所以请谨慎对待.我猜在到达初始化程序之前,实际的 ActiveSupport::TestCase 类实际上并没有被加载.

It's been a long time since I used Rails' built in testing, so take this with a grain of salt. I'm guessing that the actual ActiveSupport::TestCase class hasn't actually been loaded before the initializer is being reached.

在初始值设定项的顶部添加 require 'test_help' 可能就足够了.

It might be enough to just add require 'test_help' at the top of the initializer.

这篇关于“ActiveSupport::TestCase:Class 的未定义方法‘装置’"在使用 Rails 3.1 进行测试时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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