本文介绍了如何解决FixtureClassNotFound:找不到要附加的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
运行测试时出现此错误:
When running my tests I get this error:
FixtureClassNotFound: No class attached to find
什么原因导致此错误以及如何解决?
What causes this error and how to fix it?
推荐答案
最有可能发生这种情况,因为自定义表名称用于模型(使用set_table_name)或模型在模块中.
Most likely this happens because a custom table name is used for a Model (using the set_table_name) or the model is in a module.
要解决此问题,您需要在fixtures :all
行之前的test_helper.rb
中添加set_fixture_class
行:
To solve, you need to add a set_fixture_class
line in the test_helper.rb
before the fixtures :all
line:
class ActiveSupport::TestCase
self.use_transactional_fixtures = true
.
.
.
set_fixture_class my_table_name: MyModule::MyClass
fixtures :all
end
在这种情况下,灯具文件应名为my_table_name.yml
In this case the fixtures file should be called my_table_name.yml
这篇关于如何解决FixtureClassNotFound:找不到要附加的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!