RuntimeError: can't modify frozen Array (Rollbar, Rails 5.1 upgrade)
Asked Answered
C

2

5

Unable to use rspec and rollbar after upgrading to rails 5.

  1. Create a Rails 4 app
  2. Upgrade gemfile to use rails 5
  3. Try adding rollbar gem/support

Standard config/environment.rb:

 # Load the Rails application.
require_relative 'application'

# Initialize the Rails application.
Rails.application.initialize!

Error when running rspec:

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:5:in `<top (required)>'
...
No examples found.
Costermansville answered 5/4, 2018 at 19:27 Comment(0)
P
35

In most cases, that error is a red herring for something else.

When encountering it, don't get overwhelmed with the recurrent can't modify frozen Array error messages, and instead check the very first error that appears when running a spec.

For example:

Failure/Error: validate :uniqueness, if: 'should_be_unique?'

ArgumentError: Passing string to be evaluated in :if and :unless conditional options is not supported. Pass a symbol for an instance method, or a lambda, proc or block, instead.

Persecute answered 16/5, 2018 at 13:0 Comment(4)
Thanks for posting the answer. How did you find the first error. I am seeing the same error but can't see any other errors.Copybook
Thank you, you saved me likely hours of head-desk interactions.Lobster
Bless you. :raised_hands:Sitra
Thank you. Upvote for you. FWIW rspec --fail-early didn't show the first error. I ran rspec > output.txt and viewed the top of the txt file to see the first errorCammycamomile
I
8

Just to add one tip on top of Maxximo Mussini's answer.

If anyone can't find the first error on the terminal, please try to run RSpec on one file, i.e. rspec spec/models/user_spec.rb

You should be able to find the root case.

In my case, I haven't updated my local .env variables that is required by User model

Hope it helps

Imperfect answered 20/5, 2020 at 5:27 Comment(2)
This is helpful, but should probably be a comment on the answer you're referring to, not its own answer.Lobster
Thanks for the comment @GregJackson but I don't have 50 reputation to comment on Maximo answer. Really sorry for thisImperfect

© 2022 - 2024 — McMap. All rights reserved.