首页 > 解决方案 > 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 退出。不知道我是否遗漏了什么或者我搞砸了什么。

标签: ruby-on-railsrspecstimulusjs

解决方案


尝试如下包装 TurboFailureApp

Rails.application.reloader.to_prepare do
  class TurboFailureApp < Devise::FailureApp
    def respond
      ...
    end
  class TurboController < ApplicationController
    ...
  end
end

推荐阅读