rspec-rails: NoMethodError: undefined method `example_group' for nil:NilClass

I’m not sure what’s triggering this, yet.

        # @private
        class LogSubscriber < ::ActiveSupport::LogSubscriber
          def current_example_group
            RSpec.current_example.example_group
          end

          def render_template(_event)
            return if current_example_group.render_views?
            info("  Template rendering was prevented by rspec-rails. Use `render_views` to verify rendered view contents if necessary.")
          end
        end
[127.0.0.1] [bc765ac7-e5e6-4d8f-894f-707b2ce4b309]   Rendered layouts/authentication.html.haml (17.1ms)
[127.0.0.1] [bc765ac7-e5e6-4d8f-894f-707b2ce4b309] Could not log "render_template.action_view" event. NoMethodError: undefined method `render_views?' for RSpec::ExampleGroups::OAuth2Authorization:Class 
 Could not log "render_template.action_view" event. NoMethodError: undefined method `example_group' for nil:NilClass
[
    "/Users/kain/.rvm/gems/ruby-2.4.1/gems/rspec-rails-3.6.0.beta2/lib/rspec/rails/view_rendering.rb:67:in `current_example_group'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/gems/rspec-rails-3.6.0.beta2/lib/rspec/rails/view_rendering.rb:71:in `render_template'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/activesupport/lib/active_support/subscriber.rb:95:in `finish'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/activesupport/lib/active_support/log_subscriber.rb:83:in `finish'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/activesupport/lib/active_support/notifications/fanout.rb:102:in `finish'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/activesupport/lib/active_support/notifications/fanout.rb:46:in `block in finish'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/activesupport/lib/active_support/notifications/fanout.rb:46:in `each'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/activesupport/lib/active_support/notifications/fanout.rb:46:in `finish'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/activesupport/lib/active_support/notifications/instrumenter.rb:42:in `finish_with_state'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/activesupport/lib/active_support/notifications/instrumenter.rb:27:in `instrument'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/activesupport/lib/active_support/notifications.rb:164:in `instrument'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/actionview/lib/action_view/renderer/abstract_renderer.rb:41:in `instrument'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/actionview/lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/actionview/lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/actionview/lib/action_view/renderer/template_renderer.rb:52:in `render_template'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/actionview/lib/action_view/renderer/template_renderer.rb:14:in `render'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/actionview/lib/action_view/renderer/renderer.rb:42:in `render_template'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/actionview/lib/action_view/renderer/renderer.rb:23:in `render'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/actionview/lib/action_view/rendering.rb:104:in `_render_template'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/actionpack/lib/action_controller/metal/streaming.rb:217:in `_render_template'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/actionview/lib/action_view/rendering.rb:83:in `render_to_body'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/actionpack/lib/action_controller/metal/rendering.rb:52:in `render_to_body'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/actionpack/lib/action_controller/metal/renderers.rb:142:in `render_to_body'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/actionpack/lib/abstract_controller/rendering.rb:26:in `render'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/actionpack/lib/action_controller/metal/rendering.rb:36:in `render'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/actionpack/lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/activesupport/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'",
    "/Users/kain/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/benchmark.rb:308:in `realtime'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/activesupport/lib/active_support/core_ext/benchmark.rb:12:in `ms'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/actionpack/lib/action_controller/metal/instrumentation.rb:44:in `block in render'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/actionpack/lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/activerecord/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/bundler/gems/rails-ec9b4d39108d/actionpack/lib/action_controller/metal/instrumentation.rb:43:in `render'",
    "/Users/kain/.rvm/gems/ruby-2.4.1/gems/high_voltage-3.0.0/app/controllers/concerns/high_voltage/static_page.rb:19:in `show'",

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 15
  • Comments: 19 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I can confirm that this is also an issue in my application. With rspec 3.6.0, I get undefined method render_views?, but not with 3.5.4.

I was using config.infer_spec_type_from_file_location!, but disabling that and explicitly adding type: :feature doesn’t change anything.

I am getting this also.

Hope that helps - I am still not sure what the issue is. I started seeing the issue after the Rails 5.1 upgrade.

@samphippen I think you’ll be able to see the error by adding the following line to your config/environments/test.rb:

config.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))

This is an app that reproduces the issue: github.com/lucascaton/rspec-rails-issue-1800.

@lucascaton @marktran @masterkain Thanks for the issue. We need a little more detail to be able to reproduce this.

Could you please provide us with a rails app that we can clone that demonstrates the issue. Specifically it’d be great if

  1. you could rails new an application and commit
  2. make all the changes necessary to reproduce the issue and commit

then, provide us with a description of how to clone your application and reproduce the issue.

Thanks 😃