I’m banging my head over this really strange error in a view test when
I run “rake spec”. The weird thing is that I don’t get the error when
I run the spec file by itself.
Here is the spec (I know, fixtures are the devil):
describe “/units/new.html.erb here” do
fixtures :units, :accounts, :groups
it_should_behave_like ‘/units/_form’
before do
login_as :cathy
assigns[:unit] = @unit = Unit.new
@groups = accounts(:dawson).groups
render “/units/new.html”
end
it “should render new form” do
response.should have_tag(“form[action=?][method=post]”, units_path)
end
end
And the error:
ActionView::TemplateError in ‘Spec::Rails::Example::ViewExampleGroup/
units/new.html.erb should render new form’
You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.include?
On line #13 of units/_form.html.erb
10: <% unless @unit.root? -%>
11: <li>
12: <label for="unit_parent_id"><%=h 'Parent Unit'.t %></label>
13: <%= f.select :parent_id, [1,2,3] %>
14: <%#= f.select :parent_id,
15: nested_set_options_for_select(current_account.units.root)
{|u| “#{‘—’ * u.level} #{u.name}”} %>
16:
vendor/plugins/rspec/lib/spec/mocks/proxy.rb:71:in `send'
vendor/plugins/rspec/lib/spec/mocks/proxy.rb:71:in
message_received' vendor/plugins/rspec/lib/spec/mocks/proxy.rb:100:in
include?’
vendor/rails/actionpack/lib/action_view/helpers/
form_options_helper.rb:304:in option_value_selected?' vendor/rails/actionpack/lib/action_view/helpers/ form_options_helper.rb:163:in
options_for_select’
vendor/rails/actionpack/lib/action_view/helpers/text_helper.rb:
29:in inject' vendor/rails/actionpack/lib/action_view/helpers/ form_options_helper.rb:161:in
each’
vendor/rails/actionpack/lib/action_view/helpers/
form_options_helper.rb:161:in inject' vendor/rails/actionpack/lib/action_view/helpers/ form_options_helper.rb:161:in
options_for_select’
vendor/rails/actionpack/lib/action_view/helpers/
form_options_helper.rb:358:in to_select_tag' vendor/rails/actionpack/lib/action_view/helpers/ form_options_helper.rb:84:in
select’
vendor/rails/actionpack/lib/action_view/helpers/
form_options_helper.rb:409:in select' app/views//units/_form.html.erb:13:in
_run_47app47views47units47_form46html46erb’
vendor/rails/actionpack/lib/action_view/base.rb:390:in send' vendor/rails/actionpack/lib/action_view/base.rb:390:in
compile_and_render_template’
vendor/rails/actionpack/lib/action_view/base.rb:366:in
render_template' vendor/rails/actionpack/lib/action_view/base.rb:316:in
globalize_old_render_file’
vendor/plugins/globalize/lib/globalize/rails/action_view.rb:18:in
render_file' vendor/rails/actionpack/lib/action_view/base.rb:331:in
orig_render’
vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/
action_view/base.rb:22:in render' vendor/rails/actionpack/lib/action_view/partials.rb:117:in
render_partial’
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:
26:in benchmark' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/1.8/benchmark.rb:293:in
measure’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/1.8/benchmark.rb:307:in realtime' vendor/rails/actionpack/lib/action_controller/benchmarking.rb: 26:in
benchmark’
vendor/rails/actionpack/lib/action_view/partials.rb:116:in
render_partial' vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/ action_view/base.rb:13:in
render_partial’
vendor/rails/actionpack/lib/action_view/base.rb:352:in
orig_render' vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/ action_view/base.rb:22:in
render’
app/views//units/new.html.erb:6:in
_run_47app47views47units47new46html46erb' vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb: 248:in
fields_for’
vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:
184:in form_for' app/views//units/new.html.erb:5:in
_run_47app47views47units47new46html46erb’
vendor/rails/actionpack/lib/action_view/base.rb:390:in send' vendor/rails/actionpack/lib/action_view/base.rb:390:in
compile_and_render_template’
vendor/rails/actionpack/lib/action_view/base.rb:366:in
render_template' vendor/rails/actionpack/lib/action_view/base.rb:316:in
globalize_old_render_file’
vendor/plugins/globalize/lib/globalize/rails/action_view.rb:18:in
render_file' vendor/rails/actionpack/lib/action_controller/base.rb:1109:in
render_for_file’
vendor/rails/actionpack/lib/action_controller/base.rb:861:in
render_with_no_layout' vendor/rails/actionpack/lib/action_controller/layout.rb:269:in
render_without_benchmark’
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:
51:in render' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/1.8/benchmark.rb:293:in
measure’
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:
51:in render' vendor/plugins/rspec_on_rails/lib/spec/rails/example/ view_example_group.rb:129:in
send’
vendor/plugins/rspec_on_rails/lib/spec/rails/example/
view_example_group.rb:129:in render' spec/views/units/new.html.erb_spec.rb:11 vendor/plugins/rspec/lib/spec/example/example_methods.rb:42:in
instance_eval’
vendor/plugins/rspec/lib/spec/example/example_methods.rb:42:in
eval_each_fail_fast' vendor/plugins/rspec/lib/spec/example/example_methods.rb:41:in
each’
vendor/plugins/rspec/lib/spec/example/example_methods.rb:41:in
eval_each_fail_fast' vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: 216:in
run_before_each’
vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:
316:in execute_in_class_hierarchy' vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: 315:in
each’
vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:
315:in execute_in_class_hierarchy' vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: 215:in
run_before_each’
vendor/plugins/rspec/lib/spec/example/example_methods.rb:65:in
before_example' vendor/plugins/rspec/lib/spec/example/example_methods.rb:13:in
execute’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/1.8/timeout.rb:48:in timeout' vendor/plugins/rspec/lib/spec/example/example_methods.rb:11:in
execute’
vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:
256:in execute_examples' vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: 254:in
each’
vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:
254:in execute_examples' vendor/plugins/rspec/lib/spec/example/example_group_methods.rb: 115:in
run’
vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:
22:in run' vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb: 21:in
each’
vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:
21:in run' vendor/plugins/rspec/lib/spec/runner/options.rb:85:in
run_examples’
vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in `run’
vendor/plugins/rspec/bin/spec:3
I’m not sure why the error is in the mock proxy because this spec
isn’t using mocking at all.
Any ideas?
Brandon