Strange error on mock proxy

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:ininclude?’
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:inoptions_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:ineach’
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:inoptions_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:inselect’
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:incompile_and_render_template’
vendor/rails/actionpack/lib/action_view/base.rb:366:in
render_template' vendor/rails/actionpack/lib/action_view/base.rb:316:inglobalize_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:inorig_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:inrender_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:inmeasure’
/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:inbenchmark’
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:inrender_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:inrender’
app/views//units/new.html.erb:6:in
_run_47app47views47units47new46html46erb' vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb: 248:infields_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:incompile_and_render_template’
vendor/rails/actionpack/lib/action_view/base.rb:366:in
render_template' vendor/rails/actionpack/lib/action_view/base.rb:316:inglobalize_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:inrender_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:inrender_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:inmeasure’
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:insend’
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:ininstance_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:ineach’
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:inrun_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:ineach’
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:inrun_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:inexecute’
/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:inexecute’
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:ineach’
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:inrun’
vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:
22:in run' vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb: 21:ineach’
vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:
21:in run' vendor/plugins/rspec/lib/spec/runner/options.rb:85:inrun_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

I’m away from my computer right now so I can’t give you details, but I
know that view examples use mocks under the hood for some things.

David,

Did you ever get a chance to look at this to see if I am missing
something obvious. I’m getting these errors randomly.

Brandon

On 12/10/07 6:55 PM, “David C.” [email protected] wrote:

On Dec 10, 2007 11:42 AM, Brandon K. [email protected] wrote:

David,

Did you ever get a chance to look at this to see if I am missing
something obvious. I’m getting these errors randomly.

Haven’t yet. Anybody else on this list having a similar experience?

I’ve also been getting very confused with specs failing with rake:spec
but
passing when running focused examples (e.g.from textmate). This is
without
fixtures but using mocks. It’s as if the mocks were somehow remembering
the
should_receive declarations between specs. They didn’t seem to get
updated.

Turned out I made a mistake a using partial mocks namely trying to set
should_receive on the real object instead of the mock. This mistakes
somehow only became apparent when running with rake:spec.

I’m using flexmock 0.8, rspec plugin 1.08 with rails 1.2.6

I’m pretty sure I still get some failures in a rake:spec but not in
isolation, I’ll post examples when I run into them again

Jeroen

P.s. I had to read this bit a few times before understanding partial
mocking
with flexmock:

“If you you give flexmock a real object in the argument list, it will
treat
that real object as a base for a partial mock object. The return value m
may
be used to set expectations. The real_object should be used in the
reference
portion of the test.”

http://onestepback.org/software/flexmock/

On Dec 10, 2007 11:42 AM, Brandon K. [email protected]
wrote:

David,

Did you ever get a chance to look at this to see if I am missing
something obvious. I’m getting these errors randomly.

Haven’t yet. Anybody else on this list having a similar experience?