# Testing How To Question

**URL:** <https://www.ruby-forum.com/t/testing-how-to-question/60686>\
**Category:** Rails\
**Created:** [May 16, 2006, 7:51pm UTC](https://www.ruby-forum.com/t/testing-how-to-question/60686 "2006-05-16T19:51:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rrwhite](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@rrwhite](https://www.ruby-forum.com/u/rrwhite)\
**Post date:** [May 16, 2006, 7:51pm UTC](https://www.ruby-forum.com/t/testing-how-to-question/60686/1 "2006-05-16T19:51:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rrwhite](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@rrwhite](https://www.ruby-forum.com/u/rrwhite)\
**Post date:** [May 16, 2006, 9:38pm UTC](https://www.ruby-forum.com/t/testing-how-to-question/60686/2 "2006-05-16T21:38:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rrwhite](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@rrwhite](https://www.ruby-forum.com/u/rrwhite)\
**Post date:** [May 17, 2006, 2:07pm UTC](https://www.ruby-forum.com/t/testing-how-to-question/60686/3 "2006-05-17T14:07:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rrwhite](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@rrwhite](https://www.ruby-forum.com/u/rrwhite)\
**Post date:** [May 17, 2006, 3:06pm UTC](https://www.ruby-forum.com/t/testing-how-to-question/60686/4 "2006-05-17T15:06:44Z")

</div>

Thanks, I didn’t see that in Agile.
