rspec-rails: Rails 5: uninitialized constant ActionView::Template::Handlers::ERB::ENCODING_FLAG
I have the rails_helper.rb and the spec_helper.rb generated by the scaffolder. I have an empty controller test
require 'rails_helper'
RSpec.describe HomeController, type: :controller do
end
When I run either bundle exec rails spec or bundle exec rspec spec/controllers/home_controller_spec.rb I get
/home/me/.rvm/gems/ruby-2.3.1@global/gems/actionview-5.0.0/lib/action_view/template/handlers/erb.rb:90:in `<class:ERB>': uninitialized constant ActionView::Template::Handlers::ERB::ENCODING_FLAG (NameError)
Did you mean? Encoding
from /home/me/.rvm/gems/ruby-2.3.1@global/gems/actionview-5.0.0/lib/action_view/template/handlers/erb.rb:76:in `<module:Handlers>'
from /home/me/.rvm/gems/ruby-2.3.1@global/gems/actionview-5.0.0/lib/action_view/template/handlers/erb.rb:5:in `<class:Template>'
from /home/me/.rvm/gems/ruby-2.3.1@global/gems/actionview-5.0.0/lib/action_view/template/handlers/erb.rb:4:in `<module:ActionView>'
from /home/me/.rvm/gems/ruby-2.3.1@global/gems/actionview-5.0.0/lib/action_view/template/handlers/erb.rb:3:in `<top (required)>'
from /home/me/.rvm/gems/ruby-2.3.1@global/gems/actionview-5.0.0/lib/action_view/template/handlers.rb:12:in `require'
from /home/me/.rvm/gems/ruby-2.3.1@global/gems/actionview-5.0.0/lib/action_view/template/handlers.rb:12:in `extended'
from /home/me/.rvm/gems/ruby-2.3.1@global/gems/actionview-5.0.0/lib/action_view/template.rb:111:in `extend'
from /home/me/.rvm/gems/ruby-2.3.1@global/gems/actionview-5.0.0/lib/action_view/template.rb:111:in `<class:Template>'
from /home/me/.rvm/gems/ruby-2.3.1@global/gems/actionview-5.0.0/lib/action_view/template.rb:7:in `<module:ActionView>'
from /home/me/.rvm/gems/ruby-2.3.1@global/gems/actionview-5.0.0/lib/action_view/template.rb:5:in `<top (required)>'
from /home/me/.rvm/gems/ruby-2.3.1@global/gems/actionview-5.0.0/lib/action_view/template/resolver.rb:4:in `require'
from /home/me/.rvm/gems/ruby-2.3.1@global/gems/actionview-5.0.0/lib/action_view/template/resolver.rb:4:in `<top (required)>'
from /home/me/.rvm/gems/ruby-2.3.1@global/gems/actionview-5.0.0/lib/action_view/testing/resolvers.rb:1:in `require'
from /home/me/.rvm/gems/ruby-2.3.1@global/gems/actionview-5.0.0/lib/action_view/testing/resolvers.rb:1:in `<top (required)>'
from /home/me/.rvm/gems/ruby-2.3.1@my_app/gems/rspec-rails-3.5.1/lib/rspec/rails/view_rendering.rb:1:in `require'
from /home/me/.rvm/gems/ruby-2.3.1@my_app/gems/rspec-rails-3.5.1/lib/rspec/rails/view_rendering.rb:1:in `<top (required)>'
from /home/me/.rvm/gems/ruby-2.3.1@my_app/gems/rspec-rails-3.5.1/lib/rspec/rails.rb:9:in `require'
from /home/me/.rvm/gems/ruby-2.3.1@my_app/gems/rspec-rails-3.5.1/lib/rspec/rails.rb:9:in `<top (required)>'
from /home/me/my_app/my_app-web/spec/rails_helper.rb:2:in `require'
from /home/me/my_app/my_app-web/spec/rails_helper.rb:2:in `<top (required)>'
from /home/me/my_app/my_app-web/spec/controllers/home_controller_spec.rb:1:in `require'
from /home/me/my_app/my_app-web/spec/controllers/home_controller_spec.rb:1:in `<top (required)>'
from /home/me/.rvm/gems/ruby-2.3.1@my_app/gems/rspec-core-3.5.2/lib/rspec/core/configuration.rb:1435:in `load'
from /home/me/.rvm/gems/ruby-2.3.1@my_app/gems/rspec-core-3.5.2/lib/rspec/core/configuration.rb:1435:in `block in load_spec_files'
from /home/me/.rvm/gems/ruby-2.3.1@my_app/gems/rspec-core-3.5.2/lib/rspec/core/configuration.rb:1433:in `each'
from /home/me/.rvm/gems/ruby-2.3.1@my_app/gems/rspec-core-3.5.2/lib/rspec/core/configuration.rb:1433:in `load_spec_files'
from /home/me/.rvm/gems/ruby-2.3.1@my_app/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:100:in `setup'
from /home/me/.rvm/gems/ruby-2.3.1@my_app/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:86:in `run'
from /home/me/.rvm/gems/ruby-2.3.1@my_app/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:71:in `run'
from /home/me/.rvm/gems/ruby-2.3.1@my_app/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:45:in `invoke'
from /home/me/.rvm/gems/ruby-2.3.1@my_app/gems/rspec-core-3.5.2/exe/rspec:4:in `<top (required)>'
from /home/me/.rvm/gems/ruby-2.3.1@my_app/bin/rspec:23:in `load'
from /home/me/.rvm/gems/ruby-2.3.1@my_app/bin/rspec:23:in `<main>'
from /home/me/.rvm/gems/ruby-2.3.1@my_app/bin/ruby_executable_hooks:15:in `eval'
from /home/me/.rvm/gems/ruby-2.3.1@my_app/bin/ruby_executable_hooks:15:in `<main>'
The workaround is to add require "rails/all" at the beginning of rails_helper.rb or of spec_helper.rb but that wasn’t needed for Rails 4 and rspec-rails 3.1.
Did I miss something in the documentation?
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 29 (11 by maintainers)
Commits related to this issue
- Add additional rescue blocks to gem_loader Trying to run `srb rbi gems` would crash due to some missing requires of some gems that are broken. ex. https://github.com/rspec/rspec-rails/issues/1690 A... — committed to fzakaria/sorbet by fzakaria 7 years ago
- Add additional rescue blocks to gem_loader (#2260) * Add additional rescue blocks to gem_loader Trying to run `srb rbi gems` would crash due to some missing requires of some gems that are broken.... — committed to sorbet/sorbet by fzakaria 7 years ago
- Fix the tracer to work with JRuby (#2266) * Add additional rescue blocks to gem_loader Trying to run `srb rbi gems` would crash due to some missing requires of some gems that are broken. ex. h... — committed to sorbet/sorbet by fzakaria 7 years ago
- Get Rspec setup Fixes: #12 I finally got Rspec working. I made the first couple of specs for User.rb. I need to add lots of test coverage. I was getting this weird error: ActionView::Template::Hand... — committed to jaxonavena/Gymothy by jaxonavena 2 years ago
I got the same issue, but after I adding
require File.expand_path("../../config/environment", __FILE__)to myspec_help.rb, and it works.see http://stackoverflow.com/questions/4429068/getting-an-unitialized-constant-error-with-rspec-have-no-idea-whats-causing-it
I got around this by adding to my spec_helper.rb file
I came across this problem as well when creating a new Rails 5.1.1. app, with Rspec, Capybara and Factory Girl. Things worked once I placed expand_path at the top of the file.
My setup looks like:
I fixed this (on a fresh Rails 5 app, haven’t even added test yet) by changing the .rspec file from
--require spec_helperto
--require rails_helperDoes this seem ok to ppl?
Be aware that adding
require File.expand_path('../../config/environment', __FILE__)causes rails to be booted essentially so should only be added to files where thats expected to be the case (which is not normally needed for plain old ruby specs).Interesting! Thanks for the heads-up, @johnpitchko