From: Nathaniel Talbott Date: 2001-10-16T07:12:25+09:00 Subject: [ruby-talk:22589] Re: [ANN] Lapidary 0.2.1 Matt Armstrong [mailto:matt@lickey.com] wrote: > > Using Lapidary, is there an easy way for teardown() methods > to know if the test failed? It's easy to add for yourself (beware; untested code ahead)... class MattsTestCase < Lapidary::TestCase def initialize(*args) @failed = false super end def addFailedAssertion @failed = true end end Now you can just sublcass MattsTestCase and check @failed in your tearDown method. I'll consider adding such functionality to Lapidary, if you truly find it useful. See comments below... > Why? My tests are verifying the contents of various > dynamically built files on disk. They are all put into a > temporary directory and when the test is done the directory > is removed. But having that directory hang around for > post-mortem analysis is handy when the test fails. [snip code] > But it seems like a hack. And I notice Lapidary uses > throw/catch to process failed assertions *before* calling > teardown, which I think prevents even this hack from working. :-) If it feels like a hack, I find that it often is a hack ;-) There is a possibility that you could restructure your tests so that they don't have to worry about removing things from the disk. One way of doing this would be to use a MockObject to represent the file system, a practice you can find out more about here: http://www.mockobjects.com/endotesting.html. There is a Ruby/Mock package, which I am currently working with Nat Pryce to integrate with (and distribute with) Lapidary. So I guess this is just a suggestion to reconsider the practice of writing out files to disk during unit testing. There are times to do it, but I think they are less common than is often practiced (myself included; I just discovered mock objects recently). Sorry the reply took so long; I've been at the RubyConf (which I greatly enjoyed). Have fun, and let me know if you have any more questions. Nathaniel <:((>< + - - | RoleModel Software, Inc. | EQUIP VI