停止 Rails Console 加载 Test::Unit

发布于 2024-11-30 07:30:35 字数 401 浏览 2 评论 0原文

我有一个名为“Test”的模型(我注释了该模型中的所有内容,因此剩下的就是用于调试目的的 class Test end ),每次我尝试实例化它时Rails 控制台出现错误,指出 Test:Module 不存在“新”方法。实例化我的任何其他模型时不会发生此错误,我认为这与 Rails 控制台正在加载 Test::Unit 或类似的东西有关(凭直觉我运行了 Test.constants 并且控制台返回了 [:Unit],所以我很确定这就是问题所在)。无论如何,毫无疑问,rails 控制台正在运行一些名为 Test 的模块,我不希望这种情况发生。我该如何避免这种情况?将类名更改为不同的值对我来说非常不方便,所以如果有任何方法可以解决这个问题那就太好了~!

I have a model named "Test" (I commented everything out of that model so all that's left is class Test end for debugging purposes) and every time I try instantiating it in the rails console I get an error that the "new" method does not exist for Test:Module. This error does not occur when instantiating any of my other models, and I think it has to do with the fact that the rails console is loading up Test::Unit or something like that (on a hunch I ran Test.constants and the console returned [:Unit], so I am pretty sure that's the issue). At any rate, there is no question that some module named Test is being run by the rails console, and I don't want this to happen. How do I avoid this? It would be highly inconvenient for me to change me class name to a different value, so if there is any way to resolve this issue that would be great~!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那伤。 2024-12-07 07:30:35

您可以添加一个模块并将测试类放入其中以避免该问题。然后,您需要像 module::class 一样对您的类进行寻址。

You could add a module and have your test class inside of it to avoid that issue. You will then need to address your class like module::class.

郁金香雨 2024-12-07 07:30:35

我只是使用了一个简单的解决方法,将我的类称为“考试”而不是“测试”,但我想知道如何在不解决问题的情况下正确解决此问题。

I just used a simple work-around of calling my class "Exam" instead of Test, but I would like to know how to resolve this correctly without working around the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文