Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.
like image 620
Pierre-Francoys Brousseau Avatar asked Nov 28 '22 06:11

Pierre-Francoys Brousseau


2 Answers

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.

like image 178
Maximo Mussini Avatar answered Dec 05 '22 14:12

Maximo Mussini


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

like image 44
Andre Suchitra Avatar answered Dec 05 '22 14:12

Andre Suchitra