http://www.perlmonks.org?node_id=480984


in reply to Re: When test-driven development just won't do
in thread When test-driven development just won't do

xdg wrote:

no strict 'refs'; ok( defined *{$CLASS."::".$method}{CODE}, "$CLASS has $method")

That fails badly for a number of reasons. If you're just testing a function, it's OK. If you're really testing whether a class provides a given method, it fails. For example, if you have an inherited method, your test fails even though the class "has" the method. Further, the method might no be inherited but also not yet installed in the symbol table, yet can() might be overridden to supply the method (I've had to do this for "load on demand" services.) If you have OO code, use Perl's OO facilities to work with it. Just peeking into the namespace isn't enough.

Cheers,
Ovid

New address of my CGI Course.