I recently upgraded to Rails 5.1 from v4.3 and am now getting this error when running tests:
An error occurred while loading
./spec/controllers/admin/capac
My two-cents, as it may help someone else. I had this same issue when upgrading rails 4.2
to 5.0
I saw a thread post somewhere that suggested running one spec-test by itself / at a time. When I did that, I got a different error: superclass must be a Class
and pointed me to my new .../models/application_record.rb
file, in which I had made a syntax error by omission:
class ApplicationRecord < ActiveRecord
self.abstract_class = true
end
The above is missing ::Base
after ActiveRecord
-- first line.
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
Adding that back in fixed all my specs.
In case this helps anyone in future, it was database connection issue (Postgresql in my case). Head over to config/database.yml
file and supply username:
and password:
< default is toor>
Add this in the development:
group.
Sometimes this exception is also raised if you have a wrong class name inheritance in your Ruby classes. Remember that controllers, models, etc, are all constants in Ruby.
This is an example off the top-of-my-head of a situation I encountered. Actual syntax may be off, but this was the concept that caused my problem.
module Admin
class BaseController < ::ApplicationController
...
end
end
# throws error, referencing constant that does not exist.
# Should be < ::Admin::BaseController
class OtherController < ::BaseController
end
Like others, my entire rspec
suite would fail with the error can't modify a frozen Array
, which isn't a very helpful stacktrace in this instance, per se.
Hope this save someone else from spending hours hunting down everything else!
I tried to update from Rails 3 to Rails 5.
I just set config.eager_load
option and it helped. Either to false
or true
. Not nil
, please
In my case it was due to a git conflict message (the one like >>>> ... === ... <<<<
) that I missed to resolve, so there was a syntax error when Rspec has been trying to load that class.
--fail-fast
command line option does not help in this case as the error happens higher in the call stack, but you can see the actual error by just running any single spec file.
In my case recent rails_admin required some addition
RuntimeError: Required middlewares for RailsAdmin are not added
To fix tihs, addconfig.middleware.use ActionDispatch::Flash
to config/application.rb.
Then all rspecs became green again.