# Assert\_equal - problems returning value from controller

**URL:** <https://www.ruby-forum.com/t/assert-equal-problems-returning-value-from-controller/108722>\
**Category:** Rails\
**Created:** [July 6, 2007, 11:00am UTC](https://www.ruby-forum.com/t/assert-equal-problems-returning-value-from-controller/108722 "2007-07-06T11:00:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mark](https://www.ruby-forum.com/u/mark)\
**Post date:** [July 6, 2007, 11:00am UTC](https://www.ruby-forum.com/t/assert-equal-problems-returning-value-from-controller/108722/1 "2007-07-06T11:00:51Z")

</div>

Hi,

I have the following assert\_equal that is returning false.  
@q seems to be returning niil, but is set in the controller, how can I  
get hold of this value in my tests?

assert\_equal ‘derby’, @q

Thanks  
Mark

---

<div class="post-metadata">

**Author:** ![mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mark](https://www.ruby-forum.com/u/mark)\
**Post date:** [July 6, 2007, 11:12am UTC](https://www.ruby-forum.com/t/assert-equal-problems-returning-value-from-controller/108722/2 "2007-07-06T11:12:05Z")

</div>

On Fri, Jul 06, 2007 at 11:00:51AM +0200, Mark wrote:

> Hi,
> 
> I have the following assert\_equal that is returning false.  
> @q seems to be returning niil, but is set in the controller, how can I  
> get hold of this value in my tests?
> 
> assert\_equal ‘derby’, @q

assert\_equal ‘derby’, assigns(:q)

Jens

–  
Jens Krämer  
[http://www.jkraemer.net/](http://www.jkraemer.net/) - Blog  
[http://www.omdb.org/](http://www.omdb.org/) - The new free film database

---

<div class="post-metadata">

**Author:** ![mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mark](https://www.ruby-forum.com/u/mark)\
**Post date:** [July 7, 2007, 1:41am UTC](https://www.ruby-forum.com/t/assert-equal-problems-returning-value-from-controller/108722/3 "2007-07-07T01:41:53Z")

</div>

Mark wrote:

> I have the following assert\_equal that is returning false.  
> @q seems to be returning niil, but is set in the controller, how can I  
> get hold of this value in my tests?
> 
> assert\_equal ‘derby’, @q

assert\_equal ‘derby’, assigns[‘q’]

The deal is simply that ‘self’ in your tests is a different object than  
the  
‘self’ in your controllers. ‘self’ is the thing @ bonds to.

The test system knows this, so it passes all @ variables back to the  
tests  
in a hash called ‘assigns’.

Question for the crew - does this hash use .with\_indifferent\_access? If  
not,  
why not?

–  
Phlip  
[Test Driven Ajax (on Rails) [Book]](http://www.oreilly.com/catalog/9780596510657/)  
“Test Driven Ajax (on Rails)”  
assert\_xpath, assert\_javascript, & assert\_ajax

---

<div class="post-metadata">

**Author:** ![mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mark](https://www.ruby-forum.com/u/mark)\
**Post date:** [July 6, 2007, 4:07pm UTC](https://www.ruby-forum.com/t/assert-equal-problems-returning-value-from-controller/108722/4 "2007-07-06T16:07:57Z")

</div>

thanks
