Forum: Ruby on Rails Testing How To Question

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.
Richard W. (Guest)
on 2006-05-16 21:51
(Received via mailing list)
I'm using the functional test for a method like this:

def test_create

  post :create, :phase => 'copynew', :id => 1
  assert_response :success
  assert_template 'create'
  assert_tag :content => 'New Item'

  assert_not_nil @item
end

This posts a request to the create method in the controller.  Is there
any way to look at the variables and objects that were created in the
controller by this post?  It looks like you are only able to examine the
resulting html output.

Is that more of a unit test thing rather than a functional test thing?

And finally, if it is a unit test thing, how do I pass a set of params
to a controller method call from a unit test?
unknown (Guest)
on 2006-05-16 23:38
(Received via mailing list)
On May 16, 2006, at 12:49 PM, Richard W. wrote:

>   assert_not_nil @item
> end
>
> This posts a request to the create method in the controller.  Is there
> any way to look at the variables and objects that were created in the
> controller by this post?  It looks like you are only able to
> examine the
> resulting html output.

I'm just starting out myself, but I think this is covered in the
AgileWDR book on pages 162 and 164. Take a look at the #assigns
method call.

Ex.
	assert_equal assigns(:some_var), <what the value should be>

> Is that more of a unit test thing rather than a functional test thing?

You can examine variables in either kind of test. It's not limited to
one or the other.

> And finally, if it is a unit test thing, how do I pass a set of params
> to a controller method call from a unit test?

I've never done this but I assume it works the same way as the
opposite (func test to unit test param passing). Maybe someone else
can chime in here.

cr
Dj T@l (Guest)
on 2006-05-17 16:07
>> And finally, if it is a unit test thing, how do I pass a set of params
>> to a controller method call from a unit test?
>
> I've never done this but I assume it works the same way as the
> opposite (func test to unit test param passing). Maybe someone else
> can chime in here.
>
> cr

In unit test you never call the controller. Unit test are used to test
the model only. For controller testing, use functionnall test instead.

HTH
Richard W. (Guest)
on 2006-05-17 17:06
(Received via mailing list)
Thanks, I didn't see that in Agile.
This topic is locked and can not be replied to.