This project is archived and is in readonly mode.
@layouts in TemplateAssertions is +nil+
Reported by Lawrence Pit | May 26th, 2010 @ 10:00 AM
Using rails 3 edge.
Spec'ing a controller that's dead simple:
def show
@company = Company.find(params[:id])
respond_with(@company)
end
It has a app/views/companies/show.xml.builder
template.
When running the spec I get errors such as the one below.
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/test_case.rb:21
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/notifications/fanout.rb:88:in `call'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/notifications/fanout.rb:88:in `push'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/notifications/fanout.rb:64:in `publish'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/notifications/fanout.rb:30:in `publish'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/notifications/fanout.rb:30:in `select'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/notifications/fanout.rb:30:in `publish'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/notifications.rb:65:in `publish'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/notifications/instrumenter.rb:25:in `instrument'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/notifications.rb:48:in `__send__'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/notifications.rb:48:in `instrument'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_view/render/rendering.rb:55:in `_render_template'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_view/render/rendering.rb:25:in `render'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/abstract_controller/rendering.rb:113:in `_render_template'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/abstract_controller/rendering.rb:107:in `render_to_body'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/renderers.rb:47:in `render_to_body'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/compatibility.rb:55:in `render_to_body'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/abstract_controller/rendering.rb:100:in `render_to_string'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/abstract_controller/rendering.rb:91:in `render'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/rendering.rb:17:in `render'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/instrumentation.rb:39:in `render'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/core_ext/benchmark.rb:5:in `ms'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/core_ext/benchmark.rb:5:in `ms'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/instrumentation.rb:39:in `render'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/instrumentation.rb:77:in `cleanup_view_runtime'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activerecord/lib/active_record/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/instrumentation.rb:38:in `render'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/implicit_render.rb:10:in `default_render'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/mime_responds.rb:258
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/responder.rb:186:in `call'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/responder.rb:186:in `default_render'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/responder.rb:136:in `to_format'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/responder.rb:119:in `respond'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/responder.rb:112:in `call'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/mime_responds.rb:229:in `respond_with'
# ./app/controllers/companies_controller.rb:15:in `show'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/abstract_controller/base.rb:144:in `process_action'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/rendering.rb:11:in `process_action'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/notifications.rb:48:in `__send__'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/notifications.rb:48:in `instrument'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/instrumentation.rb:28:in `process_action'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/abstract_controller/callbacks.rb:18:in `process_action'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/callbacks.rb:440:in `_run__977566202__process_action__453433196__callbacks'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/callbacks.rb:405:in `send'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/callbacks.rb:405:in `_run_process_action_callbacks'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/callbacks.rb:88:in `send'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/callbacks.rb:88:in `run_callbacks'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/abstract_controller/callbacks.rb:17:in `process_action'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/rescue.rb:8:in `process_action'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/abstract_controller/base.rb:113:in `process'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/abstract_controller/rendering.rb:39:in `process'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/testing.rb:12:in `process_with_new_base_test'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/gems/rspec-rails-2.0.0.beta.8/lib/rspec/rails/monkey/action_controller/test_case.rb:121:in `process'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/gems/rspec-rails-2.0.0.beta.8/lib/rspec/rails/monkey/action_controller/test_case.rb:59:in `get'
# ./spec/controllers/companies_controller_spec.rb:89
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/dependencies.rb:209:in `inject'
# /Users/copa/.rvm/gems/ree-1.8.7-2010.01/gems/rspec-1.3.0/lib/spec/runner/options.rb:158
Comments and changes to this ticket
-
Lawrence Pit May 27th, 2010 @ 12:31 AM
require 'spec_helper' describe CompaniesController do before(:each) do @company = Company.first end it "should render a company as xml" do request.env["HTTP_ACCEPT"] = "application/xml" get :show, :id => @company.id response.code.should == "200" response.content_type.should == "application/xml" should_equal_xml(response.body, %( <?xml version="1.0" encoding="UTF-8"?> <company> <name>Foo</name> <id type="integer">1</id> </company> )) end end
The trace is generated when the +get+ method is called.
As you may have noticed, I'm using rspec 2.0.0.beta.8, but I don't think it has anything to do with this. Probably I'd get the same result when using a plain unit test.
-
Lawrence Pit May 27th, 2010 @ 01:40 AM
I've recreated this situation as simple as possible in a new rails app. The app can be cloned from http://github.com/lawrencepit/layoutsnil. Run:
bundle install rake db:migrate:reset rake spec
A few points of interest I found out while trying to recreate this situation:
-
In the Gemfile it points to the rails edge code. If however you use the rails 3.0.0.beta3 code the specs succeed.
-
While rake spec fails, I've also created two unit tests that are similar, and they succeed.
-
The sample shows two controller specs. This seems essential to recreate the bug. Have only one controller spec, and the specs succeed.
-
Rename /app/views/companies to e.g. /app/views/companies.bak, and the specs succeed.
-
-
Santiago Pastorino February 2nd, 2011 @ 04:52 PM
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino February 2nd, 2011 @ 04:52 PM
- State changed from open to stale
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>