Shoulda-matchers: render_with_layout does not work without rails-controller-testing gem in Rails 5

Created on 18 Jan 2017  路  5Comments  路  Source: thoughtbot/shoulda-matchers

Getting the error message:
NoMethodError: undefined method `keys' for nil:NilClass # /home/mustermann/.rvm/gems/ruby-2.3.3@foo/gems/shoulda-matchers-3.1.1/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb:121:in `rendered_layouts' # /home/mustermann/.rvm/gems/ruby-2.3.3@foo/gems/shoulda-matchers-3.1.1/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb:109:in `rendered_with_layout?' # /home/mustermann/.rvm/gems/ruby-2.3.3@foo/gems/shoulda-matchers-3.1.1/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb:85:in `matches?' # ./spec/controllers/application_controller_spec.rb:20:in `block (3 levels) in <top (required)>'
When trying to run a render_with_layout spec without the rails-controller-testing gem in Rails 5.0.1.

Bug 馃洡 Rails 5

All 5 comments

Add the rails-controller-testing gem to your Gemfile

Yeah, we should definitely add this to the gemspec, I think.

rails-controller-testing gem requires Rails 5, so we can't add it to gemspec while supporting Rails 4.2.
I will add a note about it to tREADME.md

@guialbuk Ah, very good point. 馃憤

If you're using rspec-rails 3.5.0+ then you'll get rails-controller-testing for free: https://github.com/rspec/rspec-rails/issues/1393. Otherwise, you'll have to add it yourself. I added a note about this here: 43f4d05a18a2c2c0f57bc4b231fc2ed59590bc6b.

Was this page helpful?
0 / 5 - 0 ratings