尝试运行控制台时出现“无法修改不可变的缓存环境”错误:
11: from /.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `instance_exec'
10: from /.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/application/finisher.rb:75:in `block in <module:Finisher>'
9: from /.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
8: from /.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:51:in `each'
7: from /.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
6: from /.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook'
5: from /.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control'
4: from /.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:69:in `block in execute_hook'
3: from /.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/xray-rails-0.3.2/lib/xray/engine.rb:77:in `block in <class:Engine>'
2: from /.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processing.rb:51:in `register_preprocessor'
1: from /.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processing.rb:211:in `register_config_processor'
/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:66:in `config=': can't modify immutable cached environment (RuntimeError)
我使用以下解决方案解决了此问题(某个宝石引起了该问题)。
答案 0 :(得分:0)
问题是由xray-rails gem引起的:
gem 'xray-rails'
删除已修复的错误。
答案 1 :(得分:0)
我在Docker容器上运行测试时遇到此错误,并且其中一个工厂发生了错误。修复该错误将允许运行规范
An error occurred while loading rails_helper.
Failure/Error: require File.expand_path('../../config/environment', __FILE__)
SyntaxError:
/spec/factories/apk_snapshots.rb:4: syntax error, unexpected ':', expecting keyword_end
scan_status: ApkSnapshot.scan_statuses['sc
^
/spec/factories/apk_snapshots.rb:7: syntax error, unexpected keyword_end, expecting end-of-input