Printing/logging during tests


#1

Hi all,

I’m trying to output some info to see what’s happening in a controller
during functional tests.
Problem: ‘print’ only works in the test code, but not in the production
code that’s being called by the tests.

Example:

In FooControllerTest:

def test_list
  print "1: starting"               <<----- WORKS FINE
  get :list
end

In FooController

def list
    print "2: inside"     		<<----- DOESN'T WORK
    logger.error "2: inside too"     <<----- DOESN'T WORK : nothing

reached test.log

end

Any idea?

Alain


#2

Duane

Hmm, strange that you’re not seeing anything inside of test.log.

Oups. it was not the case actually: I hadn’t noticed a ‘before_filter’
that prevented the spyed - *1 - code from being executed

Thanks for your patience

Alain - my_face_isâ??so_red - Ravet.

*1: I’m at war with bad code, so I can spy as much as I want.


#3

On Dec 20, 2005, at 12:16 PM, Alain R. wrote:

In FooControllerTest:
print “2: inside” <<----- DOESN’T WORK
logger.error “2: inside too” <<----- DOESN’T WORK :
nothing reached test.log

end

Hmm, strange that you’re not seeing anything inside of test.log. An
alternative that I use for this sort of thing is STDERR <<, e.g.:

STDERR << “2: inside\n”

Duane J.
(canadaduane)
http://blog.inquirylabs.com/