我在测试 rails 3.2 引擎时遇到了很大的困难。
我执行以下操作:
# generate the engine
rails plugin new myengine --mountable
cd myengine
# generate user resource
rails generate scaffold user name email password_digest
# try to run rake test from myengine root folder
rake test
=> NoMethodError: undefined method `users' for #<myengine::UsersControllerTest>
所以我试试这个:
cd test/dummy
rake myengine:install:migrations
rake db:migrate db:test:prepare
rake test # from within test/dummy
=> # nothing happens, no output
返回引擎的根文件夹
cd ../..
rake test
=> NoMethodError: undefined method `users' for #<myengine::UsersControllerTest>
我怀疑未定义的方法是指我的 UsersContrllerTest 顶部的以下行:
setup do
@user = users(:one)
end
我确实有固定装置,它们是与脚手架的其余部分一起生成的,而且我没有弄乱任何代码,只是完成了上面概述的步骤。