rails 5.0
(从 4.2 升级到 5.0)ruby 2.6.4
, rspec 3.6
我正在将 rails 应用程序从 rails 4.2 升级到 5.2。目前正在尝试达到 5.0。我正在修复弃用和测试,但目前在运行我的规范测试时遇到了这个错误。在此处列出一个规范以节省空间,但它们都失败并出现相同的错误(如下)。
我已经阅读了大量与此类似的线程,但没有关于如何修复它的真正答案 - 或者我的问题。
tests:
ruby-2.6.4 git:(upstream ⚡ rails5) 5M
jdc44@dev:~/apps/sha_student_services$ bx rspec spec/controllers/manage/course_reports_controller_spec.rb
DEPRECATION WARNING: The factory_girl gem is deprecated. Please upgrade to factory_bot. See https://github.com/thoughtbot/factory_bot/blob/v4.9.0/UPGRADE_FROM_FACTORY_GIRL.md for further instructions. (called from require at /usr/local/rvm/rubies/ruby-2.6.4/lib/ruby/site_ruby/2.6.0/bundler/runtime.rb:81)
An error occurred while loading ./spec/controllers/manage/course_reports_controller_spec.rb.
Failure/Error: require File.expand_path("../../config/environment", __FILE__)
NameError:
uninitialized constant Sprockets::Engines
# ./vendor/bundle/ruby/2.6.0/gems/less-rails-2.6.0/lib/less/rails/railtie.rb:17:in `block in <class:Railtie>'
# ./vendor/bundle/ruby/2.6.0/gems/activesupport-5.0.7.2/lib/active_support/lazy_load_hooks.rb:67:in `block in execute_hook'
# ./vendor/bundle/ruby/2.6.0/gems/activesupport-5.0.7.2/lib/active_support/lazy_load_hooks.rb:60:in `with_execution_control'
# ./vendor/bundle/ruby/2.6.0/gems/activesupport-5.0.7.2/lib/active_support/lazy_load_hooks.rb:65:in `execute_hook'
# ./vendor/bundle/ruby/2.6.0/gems/activesupport-5.0.7.2/lib/active_support/lazy_load_hooks.rb:50:in `block in run_load_hooks'
# ./vendor/bundle/ruby/2.6.0/gems/activesupport-5.0.7.2/lib/active_support/lazy_load_hooks.rb:49:in `each'
# ./vendor/bundle/ruby/2.6.0/gems/activesupport-5.0.7.2/lib/active_support/lazy_load_hooks.rb:49:in `run_load_hooks'
# ./vendor/bundle/ruby/2.6.0/gems/railties-5.0.7.2/lib/rails/application/bootstrap.rb:78:in `block in <module:Bootstrap>'
# ./vendor/bundle/ruby/2.6.0/gems/railties-5.0.7.2/lib/rails/initializable.rb:30:in `instance_exec'
# ./vendor/bundle/ruby/2.6.0/gems/railties-5.0.7.2/lib/rails/initializable.rb:30:in `run'
# ./vendor/bundle/ruby/2.6.0/gems/railties-5.0.7.2/lib/rails/initializable.rb:55:in `block in run_initializers'
# ./vendor/bundle/ruby/2.6.0/gems/railties-5.0.7.2/lib/rails/initializable.rb:54:in `run_initializers'
# ./vendor/bundle/ruby/2.6.0/gems/railties-5.0.7.2/lib/rails/application.rb:352:in `initialize!'
# ./vendor/bundle/ruby/2.6.0/gems/railties-5.0.7.2/lib/rails/railtie.rb:193:in `public_send'
# ./vendor/bundle/ruby/2.6.0/gems/railties-5.0.7.2/lib/rails/railtie.rb:193:in `method_missing'
# ./config/environment.rb:8:in `<top (required)>'
# ./spec/spec_helper.rb:8:in `require'
# ./spec/spec_helper.rb:8:in `<top (required)>'
# ./spec/controllers/manage/course_reports_controller_spec.rb:1:in `require'
# ./spec/controllers/manage/course_reports_controller_spec.rb:1:in `<top (required)>'
No examples found.
Finished in 0.00039 seconds (files took 3.49 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
FactoryGirl 弃用将升级到 FactoryBot,我只是还没有。
在上面的输出中,我看到了这些错误/线索:
# ./spec/controllers/manage/course_reports_controller_spec.rb:1:in `<top (required)>'
在该文件中,第 1 行是require 'spec_helper'
# ./spec/spec_helper.rb:8:in `<top (required)>'
在该文件中,第 8 行是: require File.expand_path("../../config/environment", __FILE__)
# ./config/environment.rb:8:in `<top (required)>'
在该文件中,第 8 行是:StudentServices::Application.initialize!
Gemfile:
...
gem 'sprockets'
gem 'sass-rails'
...
Gemfile.lock:
...
sprockets (4.0.0)
sprockets-rails (3.2.1)
sass-rails (6.0.0)
...
我列出了sass-rails
,因为我在 stackoverflow 上看到了一篇文章,提到这个问题在 sass-rails 中得到了解决。 rails 4 - rake 命令在我每次运行 rake db:migrate 命令时都会显示弃用警告 这些 gem 处于最新版本,但问题仍然存在。
我确实玩过将链轮降低到3.7.0
,这给了我一个不同的错误,但仍然涉及链轮:
ruby-2.6.4 git:(upstream ⚡ rails5) 5M
jdc44@dev:~/apps/sha_student_services$ bx rspec spec/controllers/manage/course_reports_controller_spec.rb
/home/STATLER/jdc44/apps/sha_student_services/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.0/lib/sprockets/digest_utils.rb:47: warning: constant ::Fixnum is deprecated
/home/STATLER/jdc44/apps/sha_student_services/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.0/lib/sprockets/digest_utils.rb:51: warning: constant ::Bignum is deprecated
/home/STATLER/jdc44/apps/sha_student_services/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.0/lib/sprockets/processor_utils.rb:110: warning: constant ::Fixnum is deprecated
/home/STATLER/jdc44/apps/sha_student_services/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.0/lib/sprockets/processor_utils.rb:111: warning: constant ::Bignum is deprecated
DEPRECATION WARNING: The factory_girl gem is deprecated. Please upgrade to factory_bot. See https://github.com/thoughtbot/factory_bot/blob/v4.9.0/UPGRADE_FROM_FACTORY_GIRL.md for further instructions. (called from require at /usr/local/rvm/rubies/ruby-2.6.4/lib/ruby/site_ruby/2.6.0/bundler/runtime.rb:81)
DEPRECATION WARNING: Sprockets method `register_engine` is deprecated.
Please register a mime type using `register_mime_type` then
use `register_compressor` or `register_transformer`.
https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
(called from block in <class:Railtie> at /home/STATLER/jdc44/apps/sha_student_services/vendor/bundle/ruby/2.6.0/gems/less-rails-2.6.0/lib/less/rails/railtie.rb:18)
An error occurred while loading ./spec/controllers/manage/course_reports_controller_spec.rb.
Failure/Error: require File.expand_path("../../config/environment", __FILE__)
NoMethodError:
undefined method `register_preprocessor' for nil:NilClass
# ./vendor/bundle/ruby/2.6.0/gems/less-rails-2.6.0/lib/less/rails/railtie.rb:22:in `block in <class:Railtie>'
# ./vendor/bundle/ruby/2.6.0/gems/railties-5.0.7.2/lib/rails/initializable.rb:30:in `instance_exec'
# ./vendor/bundle/ruby/2.6.0/gems/railties-5.0.7.2/lib/rails/initializable.rb:30:in `run'
# ./vendor/bundle/ruby/2.6.0/gems/railties-5.0.7.2/lib/rails/initializable.rb:55:in `block in run_initializers'
# ./vendor/bundle/ruby/2.6.0/gems/railties-5.0.7.2/lib/rails/initializable.rb:54:in `run_initializers'
# ./vendor/bundle/ruby/2.6.0/gems/railties-5.0.7.2/lib/rails/application.rb:352:in `initialize!'
# ./vendor/bundle/ruby/2.6.0/gems/railties-5.0.7.2/lib/rails/railtie.rb:193:in `public_send'
# ./vendor/bundle/ruby/2.6.0/gems/railties-5.0.7.2/lib/rails/railtie.rb:193:in `method_missing'
# ./config/environment.rb:8:in `<top (required)>'
# ./spec/spec_helper.rb:8:in `require'
# ./spec/spec_helper.rb:8:in `<top (required)>'
# ./spec/controllers/manage/course_reports_controller_spec.rb:1:in `require'
# ./spec/controllers/manage/course_reports_controller_spec.rb:1:in `<top (required)>'
No examples found.
Finished in 0.00053 seconds (files took 3.83 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
在此输出中,有一个指向 github 的 url 讨论了此弃用。我不确定如何将它应用于我的应用程序来解决这个问题,或者如果这甚至是问题。
我希望有人可以更多地了解导致此 sprockets 错误的原因以及如何解决它。
我很高兴编辑这篇文章并在需要时添加更多内容。
谢谢你看这个。
jc