Skip to content

Instantly share code, notes, and snippets.

@brandonhilkert
Created December 28, 2014 01:58
Show Gist options
  • Save brandonhilkert/2f39218578b27e264efe to your computer and use it in GitHub Desktop.
Save brandonhilkert/2f39218578b27e264efe to your computer and use it in GitHub Desktop.

I'm upgrading a 4.1.8 app. It has a bunch of controller tests. After the upgrade to 4.2, every test fails with:

 61) Error:
StripeEventsControllerTest#test_handles_known_class:
NoMethodError: undefined method `clear' for nil:NilClass
    test/controllers/stripe_events_controller_test.rb:14:in `block in <class:StripeEventsControllerTest>'

Digging in to Rails, it appears that it's due to this line: https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/test_case.rb#L70

It flows like this:

https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/test_case.rb#L506 https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/test_case.rb#L64

Some debugging before the request is made in the test:

[1] pry(#<MarketingControllerTest>)> RENDER_TEMPLATE_INSTANCE_VARIABLES.each { |i| puts i }
partials
templates
layouts

[3] pry(#<MarketingControllerTest>)> RENDER_TEMPLATE_INSTANCE_VARIABLES.each { |i| puts instance_variable_get("@_#{i}").nil? }
true
true
true
true

It's like the setup block isn't being called:

    def setup_subscriptions
      RENDER_TEMPLATE_INSTANCE_VARIABLES.each do |instance_variable|
        instance_variable_set("@_#{instance_variable}", Hash.new(0))
      end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment