# Mocha stub for instance variable assignment

**URL:** <https://www.ruby-forum.com/t/mocha-stub-for-instance-variable-assignment/139780>\
**Category:** Rails\
**Created:** [June 6, 2008, 11:00pm UTC](https://www.ruby-forum.com/t/mocha-stub-for-instance-variable-assignment/139780 "2008-06-06T23:00:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mr\_tibs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/439d5e/32.png) [@mr\_tibs](https://www.ruby-forum.com/u/mr_tibs)\
**Post date:** [June 6, 2008, 11:00pm UTC](https://www.ruby-forum.com/t/mocha-stub-for-instance-variable-assignment/139780/1 "2008-06-06T23:00:08Z")

</div>

Hi,

I’m getting the following error when running spec on my controller:  
#Mock:core.core\_file=(#Mock:core\_file) - expected calls: 0, actual  
calls: 1

This is my mocha rspec setup:  
@core = mock(‘core’)  
core\_file = mock(‘core\_file’)  
Core.stubs(:new).returns(@core)

And this is the line in my controller on which it fails:  
@core.core\_file = @core\_file

I tried stubbing core\_file of @core, but that didn’t do anything (e.g.  
@core.stubs(‘core\_file’).returns(core\_file)). And it makes sense,  
because in the controller, I assign core\_file - I don’t access  
core\_file.

So, the question comes down to: how do I stub instance variable  
assignment?

Thanks,  
Tiberiu

---

<div class="post-metadata">

**Author:** ![mr\_tibs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/439d5e/32.png) [@mr\_tibs](https://www.ruby-forum.com/u/mr_tibs)\
**Post date:** [June 7, 2008, 12:13am UTC](https://www.ruby-forum.com/t/mocha-stub-for-instance-variable-assignment/139780/2 "2008-06-07T00:13:33Z")

</div>

I got it… @core.stubs(:core\_file=).
