# Strange error on mock proxy

**URL:** <https://www.ruby-forum.com/t/strange-error-on-mock-proxy/122446>\
**Category:** RSpec\
**Created:** [December 7, 2007, 5:44pm UTC](https://www.ruby-forum.com/t/strange-error-on-mock-proxy/122446 "2007-12-07T17:44:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![brandonpt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6f9a4e/32.png) [@brandonpt](https://www.ruby-forum.com/u/brandonpt)\
**Post date:** [December 7, 2007, 5:44pm UTC](https://www.ruby-forum.com/t/strange-error-on-mock-proxy/122446/1 "2007-12-07T17:44:21Z")

</div>

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:

1. 

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

---

<div class="post-metadata">

**Author:** ![brandonpt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6f9a4e/32.png) [@brandonpt](https://www.ruby-forum.com/u/brandonpt)\
**Post date:** [December 7, 2007, 6:57pm UTC](https://www.ruby-forum.com/t/strange-error-on-mock-proxy/122446/2 "2007-12-07T18:57:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![brandonpt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6f9a4e/32.png) [@brandonpt](https://www.ruby-forum.com/u/brandonpt)\
**Post date:** [December 11, 2007, 9:27am UTC](https://www.ruby-forum.com/t/strange-error-on-mock-proxy/122446/3 "2007-12-11T09:27:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![brandonpt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6f9a4e/32.png) [@brandonpt](https://www.ruby-forum.com/u/brandonpt)\
**Post date:** [December 11, 2007, 1:58pm UTC](https://www.ruby-forum.com/t/strange-error-on-mock-proxy/122446/4 "2007-12-11T13:58:15Z")

</div>

On 12/10/07 6:55 PM, “David C.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Dec 10, 2007 11:42 AM, Brandon K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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/](http://onestepback.org/software/flexmock/)

---

<div class="post-metadata">

**Author:** ![brandonpt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6f9a4e/32.png) [@brandonpt](https://www.ruby-forum.com/u/brandonpt)\
**Post date:** [December 11, 2007, 12:05pm UTC](https://www.ruby-forum.com/t/strange-error-on-mock-proxy/122446/5 "2007-12-11T12:05:33Z")

</div>

On Dec 10, 2007 11:42 AM, Brandon K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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?
