views:

84

answers:

4

In a Rails application I have a Test::Unit functional test that's failing, but the output on the console isn't telling me much.

How can I view the request, the response, the flash, the session, the variables set, and so on?

Is there something like...

rake test specific_test_file --verbose
+1  A: 

in the failing test use p @request etc. its ugly, but it can work

Ben Hughes
+3  A: 

You can add puts statements to your test case as suggested, or add calls to Rails.logger.debug() to your application code and watch your log/development.log to trace through what's happening.

Tony Collen
+2  A: 

In your test you have access to a bunch of resources you can user to debug your test.

 p @request
 p @response
 p @controller
 p flash
 p cookie
 p session

Also, remember that your action should be as simple as possibile and all the specific action execution should be tested by single Unit test. Functional test should be reserved to the the overall action execution.

What does it mean in practice? If something doesn't work in your action, and your action calls 3 Model methods, you should be able to easily isolate the problem just looking at the unit tests. If one (or more) unit test fails, then you know which method is the guilty. If all the unit tests pass, then the problem is the action itself but it should be quite easy to debug since you already tested the methods separately.

Simone Carletti
A: 

An answer to a separate question suggested

rake test TESTOPTS=-v
Andrew Grimm