NoMethodError: undefined method `new' for BigDecimal:Class

Viewed 3199

Recently I have updated Ruby(2.5.3 to 2.7.1) and Ruby on rails(5.2.2 to 6.1.1) version.

After that when I run rspec, I got this error:

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:

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

2 Answers

As suggested by @Tom Lord in the comments updating shoulda matcher to 3.1.3 worked for me

Requiring config/environment.rb is just loading rails and your app. 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.

To debug this you need unfiltered error trace. To get that you can wrap Bundler.require(*Rails.groups) and Application.initialize! (most likely the error will be in an initializer) with a rescue and get the backtrace from exception directly.

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.

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

Related