# Testing - how to get access to an instance variable

**URL:** <https://www.ruby-forum.com/t/testing-how-to-get-access-to-an-instance-variable/96248>\
**Category:** Rails\
**Created:** [June 27, 2006, 5:56pm UTC](https://www.ruby-forum.com/t/testing-how-to-get-access-to-an-instance-variable/96248 "2006-06-27T17:56:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nekapoor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ea666f/32.png) [@nekapoor](https://www.ruby-forum.com/u/nekapoor)\
**Post date:** [June 27, 2006, 5:56pm UTC](https://www.ruby-forum.com/t/testing-how-to-get-access-to-an-instance-variable/96248/1 "2006-06-27T17:56:04Z")

</div>

inside controller

def foo  
@city = City.find(@params[:id])  
@city.bar = 1234  
end

While writing functional tests how do I ensure that the @city.bar is  
1234?

def test\_edit  
get :edit, :id =\> 1  
assert\_not\_nil assigns(:city)  
#?? how to assert that city.bar is 1234  
end

Thanks

---

<div class="post-metadata">

**Author:** ![nekapoor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ea666f/32.png) [@nekapoor](https://www.ruby-forum.com/u/nekapoor)\
**Post date:** [June 27, 2006, 7:04pm UTC](https://www.ruby-forum.com/t/testing-how-to-get-access-to-an-instance-variable/96248/2 "2006-06-27T19:04:46Z")

</div>

Neeraj K. wrote:

> While writing functional tests how do I ensure that the @city.bar is  
> 1234?
> 
> def test\_edit  
> get :edit, :id =\> 1  
> assert\_not\_nil assigns(:city)  
> assert\_equal 1234, assigns(‘city’).bar  
> end

And in general [Peak Obsession](http://manuals.rubyonrails.com/read/chapter/28) is very  
helpful 🙂

Cheers,  
Åukasz Piestrzeniewicz

---

<div class="post-metadata">

**Author:** ![nekapoor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ea666f/32.png) [@nekapoor](https://www.ruby-forum.com/u/nekapoor)\
**Post date:** [June 27, 2006, 8:16pm UTC](https://www.ruby-forum.com/t/testing-how-to-get-access-to-an-instance-variable/96248/3 "2006-06-27T20:16:39Z")

</div>

thanks
