ruby-on-railsrspecrspec-railsruby-on-rails-5sendgrid-rails

(Bundler::GemRequireError) Gem Load Error is: uninitialized constant AbstractController::Rendering


I'm using Rails 5.0.0.beta3, everything works well, after I integrated sendgrid-rails I got this exception when running rspec

There was an error while trying to load the gem 'sendgrid-rails'. (Bundler::GemRequireError)
Gem Load Error is: uninitialized constant AbstractController::Rendering
Backtrace for gem load error is:
/Users/hieupham/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.beta3/lib/action_controller/base.rb:204:in `<class:Base>'
/Users/hieupham/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.beta3/lib/action_controller/base.rb:164:in `<module:ActionController>'
/Users/hieupham/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.beta3/lib/action_controller/base.rb:5:in `<top (required)>'
/Users/hieupham/.rvm/gems/ruby-2.3.0/gems/actionview-5.0.0.beta3/lib/action_view/test_case.rb:11:in `<class:TestCase>'
/Users/hieupham/.rvm/gems/ruby-2.3.0/gems/actionview-5.0.0.beta3/lib/action_view/test_case.rb:10:in `<module:ActionView>'
/Users/hieupham/.rvm/gems/ruby-2.3.0/gems/actionview-5.0.0.beta3/lib/action_view/test_case.rb:8:in `<top (required)>'
/Users/hieupham/.rvm/gems/ruby-2.3.0/gems/rails-controller-testing-0.1.1/lib/rails-controller-testing.rb:16:in `block in <top (required)>'
/Users/hieupham/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.beta3/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
/Users/hieupham/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.beta3/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
/Users/hieupham/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.beta3/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'

I think this only happens with Rails 5, Do you have any experience with this kind of issue?

How to fix this? Btw, I raised an issue for the author as well

Thanks


Solution

  • I just solved this issue by:

    Add require false to gemfile

    group :test do
      gem 'rails-controller-testing', :require => false
    end
    

    Require the gem in the test_helper.rb or rails_helper.rb after others

    # Other configs
    require 'rails-controller-testing'
    

    Ref to this recommendation