Testing How To Question


#1

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?


#2

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),

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


#3

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


#4

Thanks, I didn’t see that in Agile.