Forum: Ruby on Rails assert_equal - problems returning value from controller

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
88d46135d21ed3b5f4c6d6bce59220ce?d=identicon&s=25 Mark (Guest)
on 2007-07-06 11:00
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
36feb4959db6ab8259a44962f0fa761f?d=identicon&s=25 Jens Kraemer (Guest)
on 2007-07-06 11:12
(Received via mailing list)
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/ - Blog
http://www.omdb.org/     - The new free film database
88d46135d21ed3b5f4c6d6bce59220ce?d=identicon&s=25 Mark (Guest)
on 2007-07-06 16:07
thanks
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2007-07-07 01:41
(Received via mailing list)
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
  http://www.oreilly.com/catalog/9780596510657/
  "Test Driven Ajax (on Rails)"
  assert_xpath, assert_javascript, & assert_ajax
This topic is locked and can not be replied to.