弃用警告:使用 Rspec 运行 Rails 测试时,“不推荐使用位置布尔值加粗日志文本”

问题描述 投票:0回答:1

在 Rails 应用程序中运行测试时,我多次看到以下弃用警告:

DEPRECATION WARNING: Bolding log text with a positional boolean is deprecated and will be removed in Rails 7.2. Use an option hash instead (eg. `color("my text", :red, bold: true)`). (called from tap at <internal:kernel>:90)
DEPRECATION WARNING: Bolding log text with a positional boolean is deprecated and will be removed in Rails 7.2. Use an option hash instead (eg. `color("my text", :red, bold: true)`). (called from tap at <internal:kernel>:90)
DEPRECATION WARNING: Bolding log text with a positional boolean is deprecated and will be removed in Rails 7.2. Use an option hash instead (eg. `color("my text", :red, bold: true)`). (called from tap at <internal:kernel>:90)
DEPRECATION WARNING: Bolding log text with a positional boolean is deprecated and will be removed in Rails 7.2. Use an option hash instead (eg. `color("my text", :red, bold: true)`). (called from tap at <internal:kernel>:90)
DEPRECATION WARNING: Bolding log text with a positional boolean is deprecated and will be removed in Rails 7.2. Use an option hash instead (eg. `color("my text", :red, bold: true)`). (called from tap at <internal:kernel>:90)
DEPRECATION WARNING: Bolding log text with a positional boolean is deprecated and will be removed in Rails 7.2. Use an option hash instead (eg. `color("my text", :red, bold: true)`). (called from tap at <internal:kernel>:90)
DEPRECATION WARNING: Bolding log text with a positional boolean is deprecated and will be removed in Rails 7.2. Use an option hash instead (eg. `color("my text", :red, bold: true)`). (called from tap at <internal:kernel>:90)
DEPRECATION WARNING: Bolding log text with a positional boolean is deprecated and will be removed in Rails 7.2. Use an option hash instead (eg. `color("my text", :red, bold: true)`). (called from tap at <internal:kernel>:90)
DEPRECATION WARNING: Bolding log text with a positional boolean is deprecated and will be removed in Rails 7.2. Use an option hash instead (eg. `color("my text", :red, bold: true)`). (called from tap at <internal:kernel>:90)

但是,我的应用程序中没有任何使用颜色、粗体或与格式化日志文本相关的任何代码。该警告并未指向我的代码中的特定文件或行,因此我不确定是什么触发了它。

这里有一些额外的背景信息:

Rails 版本:7.1.4.1,Rspec

在这些 Rails 版本中运行测试时,有没有人找到解决此问题的方法,而无需升级 Rails gem?

提前谢谢您!

ruby-on-rails ruby rspec
1个回答
0
投票

您在使用 Kredis 吗?如果是这样,这可能在管道中,您可能需要在合并时更新此依赖项:https://github.com/rails/kredis/issues/108

无论如何,这看起来很棘手,因为堆栈跟踪不是很有用。至少有两种方法可以引导您找到来源:

  1. 在你的

    ActiveSupport::Deprecation.debug = true
    中设置
    config/environments/test.rb
    ,这应该抛出异常而不是弃用警告,也许堆栈跟踪更有用(这应该足够了,不需要其他建议,除非发生了非常奇怪的事情) (感谢如何配置 Rails 在遇到弃用警告时引发错误?

  2. 在您的项目中,尝试找到发出弃用的位置(查找
  3. bundle open rails

    或只是

    ActiveSupport::Deprecation
    Deprecation
    ),设置断点,运行规范并在调试器暂停时探索帧。
    
    
    将您的捆绑器设置为在本地安装 gem(使用 BUNDLE_PATH)并 grep 目录以查找 

    deprecate
  4. 的用法,并查看是否有任何看起来像使用旧方法的
  5. ActiveSupport::LogSubscriber

    方法。

    
    
        

© www.soinside.com 2019 - 2024. All rights reserved.