RuntimeError: can't modify frozen Array [closed]
Asked Answered
M

0

21

I updated my Ruby on Rails app to Ruby on Rails 5.1.4. When I run my tests, every test returns the following error:

An error occurred while loading {path to specific spec file}
Failure/Error: require File.expand_path('../../config/environment', __FILE__)

RuntimeError:
  can't modify frozen Array
# ./config/environment.rb:6:in `<top (required)>'
# ./spec/rails_helper.rb:4:in `<top (required)>'

How can I fix that?

EDIT:

I was updating from 5.0.0.1 to 5.1.4.

Mutation answered 15/9, 2017 at 12:41 Comment(14)
We are missing context. From which version did you update Rails ? Is there other unexpected changed ? Can you launch your server, or at leat a console ? Is there any backtrace you could give please ?Gablet
@Gablet I updated question.Mohandis
Share spec/views/surveys/results.html.haml_spec.rb at least.Denesedengue
Did you manage to fix this? I have this issue with circleci build.Sandhi
In my case, the problem came from also updating the app's Ruby version. The repo's .ruby-version file had been updated to a Ruby 2.4.x version, and my local rbenv was still using a Ruby 2.3.x version. When I updated the rbenv Ruby version to match the .ruby-version, things were fixed.Dippold
Did you fix it? i got the same problem.Ultramontanism
Unfortunately no. I decided to not update my app to Rails 5.1.4 now.Mohandis
@MateuszUrbański I solved it. When I run bundle exec rails c, the real error messages are shown. Not sure why the irrelative RuntimeError: can't modify frozen Array is thrown when running test.Ultramontanism
To see the real problem, you can try to run the rails server: rails s and it will show you the problems, fix them and run your tests again after the rails server run successfully :-) It worked for me. Should work for you too!Whiffet
I had a similar problem, possibly the same with solution here: https://mcmap.net/q/661526/-runtimeerror-can-39-t-modify-frozen-array-rollbar-rails-5-1-upgradeIcbm
I got this error if I have ruby syntax error on spec file. I got a lot of error but the first error message says syntax error.Pella
In my case, there was a database table but I had removed the app/models file because it was no longer required. I needed to either delete the table or re-instate its associated model. As HFX mentioned, running rails c was the key to seeing the real error.Epigeal
I had the same problem when tried to upgrade from rails 5.2.0 to 5.2.2.1 using bundle update rails command, its also updated many other gems one of them was factory_bot from 4.10.0 to 5.0.2 so solution was to downgrade to 4.10.0 by specifying the version number for factory_bot to gem "factory_bot_rails", "~> 4.10.0"Vladamir
This answer saved me : "Turns out this was caused by test failures higher in the stack trace. It was hard to see what the root cause was because there was so much in the console". credits to https://mcmap.net/q/320615/-rails-runtimeerror-can-39-t-modify-frozen-array-when-running-rspec-in-railsLager

© 2022 - 2024 — McMap. All rights reserved.