While upgrading from Ruby 2.6.6 to Ruby 3.1.3 and from Rails 5.2.6 to Rails 6.0.6, I made sure that I followed and incorporated all the changes between these 2 rails versions. I am not sure why I am getting the following error.
mw@2981eebea820:/workspaces/mw$ bundle exec rspec spec
DEPRECATION WARNING: Logger don't need to call #after_initialize directly anymore. It will be deprecated without replacement in Rails 6.1. (called from new at /workspaces/mw/config/application.rb:53)
An error occurred while loading ./spec/controllers/basic_controller_spec.rb.
Failure/Error: require 'rspec/rails'
NameError:
uninitialized constant ActiveRecord::Railtie::ActiveRecord
include ActiveRecord::Railties::ControllerRuntime
^^^^^^^^^^^^
# /usr/local/bundle/gems/activerecord-6.0.6/lib/active_record/railtie.rb:209:in `block (2 levels) in <class:Railtie>'
# /usr/local/bundle/gems/activesupport-6.0.6/lib/active_support/lazy_load_hooks.rb:71:in `class_eval'
# /usr/local/bundle/gems/activesupport-6.0.6/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
# /usr/local/bundle/gems/activesupport-6.0.6/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
# /usr/local/bundle/gems/activesupport-6.0.6/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
# /usr/local/bundle/gems/activesupport-6.0.6/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
# /usr/local/bundle/gems/activesupport-6.0.6/lib/active_support/lazy_load_hooks.rb:51:in `each'
# /usr/local/bundle/gems/activesupport-6.0.6/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
# /usr/local/bundle/gems/actionpack-6.0.6/lib/action_controller/base.rb:269:in `<class:Base>'
# /usr/local/bundle/gems/actionpack-6.0.6/lib/action_controller/base.rb:166:in `<module:ActionController>'
# /usr/local/bundle/gems/actionpack-6.0.6/lib/action_controller/base.rb:7:in `<main>'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/actionview-6.0.6/lib/action_view/test_case.rb:13:in `<class:TestCase>'
# /usr/local/bundle/gems/actionview-6.0.6/lib/action_view/test_case.rb:12:in `<module:ActionView>'
# /usr/local/bundle/gems/actionview-6.0.6/lib/action_view/test_case.rb:10:in `<main>'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# ./spec/spec_helper.rb:5:in `<main>'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# ./spec/rails_helper.rb:10:in `<top (required)>'
# ./spec/controllers/basic_controller_spec.rb:1:in `require'
# ./spec/controllers/basic_controller_spec.rb:1:in `<top (required)>'
CodePudding user response:
Did you make any huge jumps between Rubies? You should have moved to 2.7 first, then when that works okay, you go to 3.0 and so on. That was what I did after a huge jump broke and I did not even know where the problem is coming from. I rolled back and made little jumps and it all worked out. I understand this is not a code solution but I hope it helps anyway.
CodePudding user response:
So, it turned out that the project did not have any dependency on the database so require "active_record/railtie"
was dropped in the application.rb but there was an explicit call in the spec/rails_helper.rb
that was referring to ActiveRecord - Object.send(:remove_const, :ActiveRecord)
. After dropping that call, it started working. I am not sure why this was working previously in the first place. Thanks for all the help!