Ruby 2.4 => 2.7: nometoderror: неопределенный метод «новый» для класса BigDecimal:

#ruby-on-rails #ruby #rspec

Вопрос:

Я обновил свой Ruby с 2.4 до 2.7 для существующего проекта и теперь rspec выдаю эту ошибку для каждой отдельной спецификации. Я не могу найти источник ошибки. BigDecimal В моем проекте такого нет. Я не писал тесты. Как мне найти драгоценный камень, который вызывает проблему?

 An error occurred while loading ./spec/views/terms_users/new.html.erb_spec.rb.
Failure/Error: require File.expand_path('../../config/environment', __FILE__)

NoMethodError:
  undefined method `new' for BigDecimal:Class
# ./config/application.rb:17:in `<top (required)>'
# ./config/environment.rb:2:in `<top (required)>'
# ./spec/rails_helper.rb:4:in `<top (required)>'
# ./spec/views/terms_users/new.html.erb_spec.rb:1:in `<top (required)>'
C:/ruby27/lib/ruby/gems/2.7.0/bundler/gems/shoulda-matchers-4b160bd19ecc/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb:271: warning: already initialized constant Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher::ARBITRARY_OUTSIDE_STRING
C:/ruby27/lib/ruby/gems/2.7.0/bundler/gems/shoulda-matchers-4b160bd19ecc/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb:271: warning: previous definition of ARBITRARY_OUTSIDE_STRING was here
C:/ruby27/lib/ruby/gems/2.7.0/bundler/gems/shoulda-matchers-4b160bd19ecc/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb:272: warning: already initialized constant Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher::ARBITRARY_OUTSIDE_FIXNUM
C:/ruby27/lib/ruby/gems/2.7.0/bundler/gems/shoulda-matchers-4b160bd19ecc/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb:272: warning: previous definition of ARBITRARY_OUTSIDE_FIXNUM was here
 

Это application.rb:17 :

 Bundler.require(*Rails.groups)
 

Это мой файл с драгоценными камнями для :test :

 ruby '~>2.7.0'
gem 'rails', '~> 5.0.2'

group :test do
  # Acceptance test framework for web applications
  gem 'capybara'
  # Strategies for cleaning databases
  gem 'database_cleaner'#, '~> 1.6.1.0'
  # Factories
  gem 'fabrication'#, '~> 2.16.1'
  # Tool for writing automated tests of websites
  gem 'selenium-webdriver'#, '~> 3.4'
  # Code coverage
  gem 'simplecov', require: false
  # One-liners that test common Rails functionality
  gem 'shoulda-matchers', git: 'https://github.com/thoughtbot/shoulda-matchers.git', branch: 'rails-5'
  # Stubbing and setting expectations on HTTP requests
  gem 'webmock', require: false
end

group :development, :test do
  # Annotate Rails classes with schema and routes info
  gem 'annotate', '~> 2.7'
  # Call 'byebug' anywhere to stop execution and get a debugger console
  gem 'byebug' #, platform: :mri
  # Load environment variables from `.env`
  gem 'dotenv-rails', '~> 2.2'
  # `rails c` alternative and runtime developer console
  gem 'pry-rails', '~> 0.3'
  # Launch a pry session when a test fails
  gem 'pry-rescue'
  # Move up and down the stack with pry
  gem 'pry-stack_explorer'
  # Testing
  gem 'rspec-rails'#, '~> 3.5'
  # Ruby static code analyzer
  gem 'rubocop', '~> 0.49.1', require: false
  gem 'rubocop-rspec'#, '~> 1.15', require: false
end
 

Приложение запускается, загружается и работает.

Ответ №1:

Это отследило его:

 >set RAILS_ENV=test

>echo %RAILS_ENV%
test

>rails console
Traceback (most recent call last):
        58: from bin/rails:9:in `<main>'
        57: from C:/ruby27/lib/ruby/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
...
         1: from C:/ruby27/lib/ruby/gems/2.7.0/bundler/gems/shoulda-matchers-4b160bd19ecc/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb:270:in `<module:ActiveModel>'
C:/ruby27/lib/ruby/gems/2.7.0/bundler/gems/shoulda-matchers-4b160bd19ecc/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb:273:in `<class:ValidateInclusionOfMatcher>': undefined method `new' for BigDecimal:Class (NoMethodError)
 

Это решило проблему:

 `Gemfile`
gem 'shoulda-matchers'#, git: 'https://github.com/thoughtbot/shoulda-matchers.git', branch: 'rails-5'

> bundle update
Installing shoulda-matchers 4.5.1 (was 3.1.2)
> rails console
[1] pry(main)>