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.

smargh
  • 876
  • 9
  • 19
Mateusz Urbański
  • 7,352
  • 15
  • 68
  • 133
  • 3
    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 ? – pimpin Sep 15 '17 at 12:53
  • @pimpin I updated question. – Mateusz Urbański Sep 15 '17 at 13:03
  • Share `spec/views/surveys/results.html.haml_spec.rb` at least. – Aleksei Matiushkin Sep 15 '17 at 16:44
  • Did you manage to fix this? I have this issue with circleci build. – Aleksander Lopez Oct 07 '17 at 00:55
  • 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. – smargh Oct 26 '17 at 15:12
  • Did you fix it? i got the same problem. – HFX Oct 31 '17 at 11:29
  • Unfortunately no. I decided to not update my app to Rails 5.1.4 now. – Mateusz Urbański Oct 31 '17 at 11:31
  • 17
    @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. – HFX Nov 01 '17 at 04:26
  • 3
    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! – K M Rakibul Islam Jan 25 '18 at 01:52
  • I had a similar problem, possibly the same with solution here: https://stackoverflow.com/a/49680076/1701430 – Pierre-Francoys Brousseau Apr 05 '18 at 19:56
  • 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`. – Yuki Matsukura Oct 22 '18 at 06:25
  • 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. – Chris Lewis Feb 17 '19 at 10:57
  • 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" – Nezir Mar 13 '19 at 21:42
  • 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://stackoverflow.com/a/47344580/2832282 – Cyril Duchon-Doris Mar 29 '19 at 12:59

0 Answers0