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.

3 Answers3

29

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.

Community
  • 1
  • 1
Maximo Mussini
  • 1,030
  • 11
  • 19
6

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

Andre Suchitra
  • 143
  • 2
  • 8
-3

Debugging this is not easy but one possible solution is simple. It could be a naming conflict with Rollbar, possibly something getting monkey-patched. If you're seeing this RuntimeError but not using Rollbar, see other answer.

Add a Module ("namespace" of your choice) around your app class definition in config/application.rb.

The module won't affect much. The only difference I could find is when printing out your app it will now appear as (that's how we found the fix vs a new working app):

<MyTestAPP::Application ...> instead of <Application ...>

Change:

class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 5.1
  end

To:

Module MyTestApp
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 5.1
  end
end