[英]NoMethodError: undefined method `new' for BigDecimal:Class
Recently I have updated Ruby(2.5.3 to 2.7.1) and Ruby on rails(5.2.2 to 6.1.1) version.最近我更新了 Ruby(2.5.3 到 2.7.1)和Ruby on rails(5.2.2 到 6.1.1)版本。
After that when I run rspec , I got this error:之后,当我运行rspec时,出现此错误:
Failure/Error: require File.expand_path("../../config/environment", __FILE__)
NoMethodError:
undefined method `new' for BigDecimal:Class
# ./config/application.rb:11:in `<top (required)>'
# ./config/environment.rb:2:in `<top (required)>'
An error occurred in spec_helper.rb How to debug spec_helper's code which is: spec_helper.rb 中发生错误如何调试 spec_helper 的代码是:
require File.expand_path("../../config/environment", __FILE__)
how to resolve the above error?如何解决上述错误? I'm not sure which gem/file trying to do
BigDecimal.new
我不确定哪个 gem/file 试图做
BigDecimal.new
As suggested by @Tom Lord in the comments updating shoulda matcher to 3.1.3 worked for me正如@Tom Lord 在将should matcher 更新为3.1.3 的评论中所建议的那样为我工作
Requiring config/environment.rb
is just loading rails and your app.需要
config/environment.rb
只是加载 rails 和您的应用程序。 Most likely one of your dependencies is not compatible with ruby 2.6 (for this exact error with BigDecimal.new
there's explanation in this answer here , but it is not guaranteed to be the only one), rails by default filters gems from backtraces.很可能您的一个依赖项与 ruby 2.6 不兼容(对于
BigDecimal.new
的这个确切错误,此处的答案中有解释,但不能保证是唯一的一个),rails 默认情况下会从回溯中过滤宝石。
To debug this you need unfiltered error trace.要调试它,您需要未经过滤的错误跟踪。 To get that you can wrap
Bundler.require(*Rails.groups)
and Application.initialize!
为此,您可以包装
Bundler.require(*Rails.groups)
和Application.initialize!
(most likely the error will be in an initializer) with a rescue
and get the backtrace from exception directly. (很可能错误将在初始化程序中)通过
rescue
并直接从异常中获取回溯。
Other approach is to upgrade everything reported by bundle outdated
since you're already taking the risk of jumping over multiple rails versions and hope that all used gems already released a compatible version.其他方法是升级
bundle outdated
报告的所有内容,因为您已经冒着跳过多个 rails 版本的风险,并希望所有使用的 gem 都已经发布了兼容版本。
PS. PS。 usually it's not recommended to skip minor rails and ruby versions during upgrade, because this way you can skip some important deprecations and get unexpected behavior
通常不建议在升级过程中跳过次要导轨和 ruby 版本,因为这样您可以跳过一些重要的弃用并获得意外行为
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.