使用Rails 3.1测试时,"ActiveSupport :: TestCase:Class"的"undefined方法`fixtures"

her*_*val 9 unit-testing ruby-on-rails

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

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

class ActiveSupport::TestCase
  fixtures :all
end
Run Code Online (Sandbox Code Playgroud)

但是测试无法执行:

`<class:TestCase>': undefined method `fixtures' for ActiveSupport::TestCase:Class (NoMethodError)
Run Code Online (Sandbox Code Playgroud)

gem依赖于Rails 3,每个依赖项都经过检查和双重检查.代码在github上,万一有人想检查(https://github.com/herval/acts_as_recommendable)我没有想法.有人共用灯吗?

Zen*_*Zen 5

我不确定,但似乎固定装置不能与 mongoid 一起使用。

看一下这个以获取更多详细信息:

https://groups.google.com/forum/?fromgroups=#!topic/mongoid/tqlx3j88Lqw


Rya*_*yan 3

我已经很长时间没有使用 Rails 的内置测试了,所以对此持保留态度。我猜测在到达初始化程序之前实际的 ActiveSupport::TestCase 类实际上尚未加载。

只需添加到require 'test_help'初始值设定项的顶部就足够了。