ruby-on-rails - Rspec rails 在使用 Stimulus.js 自动加载弃用警告后挂起
问题描述
在尝试使用 Stimulus.js 在 rails 6.1.0 中运行 RSpec 测试时,我遇到了一个问题,即我从终端获得的唯一输出
EPRECATION WARNING: Initialization autoloaded the constants ApplicationHelper, DashboardHelper, WelcomeHelper, FontAwesome5, FontAwesome5::Rails, FontAwesome5::Rails::IconHelper, Stimulus::StimulusHelper, DeviseHelper, ApplicationController, ActionText::ContentHelper, and ActionText::TagHelper.
Being able to do this is deprecated. Autoloading during initialization is going
to be an error condition in future versions of Rails.
Reloading does not reboot the application, and therefore code executed during
initialization does not run again. So, if you reload ApplicationHelper, for example,
the expected changes won't be reflected in that stale Module object.
These autoloaded constants have been unloaded.
In order to autoload safely at boot time, please wrap your code in a reloader
callback this way:
Rails.application.reloader.to_prepare do
# Autoload classes and modules needed at boot time here.
end
That block runs when the application boots, and every time there is a reload.
For historical reasons, it may run twice, so it has to be idempotent.
Check the "Autoloading and Reloading Constants" guide to learn more about how
Rails autoloads and reloads.
(called from <top (required)> at /Users/user/freelance/OneHR/config/environment.rb:5)
^C
RSpec is shutting down and will print the summary report... Interrupt again to force quit.
我已经通过不同的站点进行了一些搜索,但没有任何运气来运行我的测试。
我认为我必须在我的测试环境文件中添加带有我的类的代码块,但还没有任何结果。在此错误输出到控制台后,RSpec 挂起,我必须使用 Command + C 退出。不知道我是否遗漏了什么或者我搞砸了什么。
解决方案
尝试如下包装 TurboFailureApp
Rails.application.reloader.to_prepare do
class TurboFailureApp < Devise::FailureApp
def respond
...
end
class TurboController < ApplicationController
...
end
end
推荐阅读
- java - 从 json 对象字符串转换为 Java 对象 om.google.gson.JsonSyntaxException
- python - CSV 输出到多列而不是 1 列
- dns - 添加 CNAME 后,WWW 版本的域不起作用。任何想法为什么?
- regex - Visual Studio 中的一行或多行 RegEx 查找 + 替换
- html - 如何在 Django 环境中仅刷新包含表单的子页面
- javascript - 如何在 laravel 的 js 文件中访问 env veriables
- javascript - 如何防止在 Android 上的 Chrome 中长按时焦点变化?
- django - 在 Django 的 views.py 中将 content_type 添加到 render_to_response 导致“服务器错误 (500)”
- excel - 数据按一列排序
- python - Python 多播未在 BusyBox 上接收数据