From: Mike Stok Date: 2006-05-14T07:39:45+09:00 Subject: Re: Forcing some code to run at the end of tests On 13-May-06, at 6:27 PM, Sy Ali wrote: > On 5/13/06, Mike Stok wrote: >> >> On 13-May-06, at 5:44 PM, Sy Ali wrote: >> >> > I'm playing with some test scripts, and I cannot for the life of me >> > ensure that a block of code is run after every test is run. I can >> > think of some ugly ways to do it.. but is there an elegant way >> which I >> > missed? >> >> Does every test mean every test case? If so you might look at >> Test::Unit::TestCase's teardown. > > No, not teardown.. I want to have some code executed after all testing > has concluded. > > You'd think it'd be a matter of running it all at the end of the .rb > file, but this is not true.. everything is run and _then_ the test > cases are run. > > I suppose I could wrap the entire test in another ruby file.. it just > seems strange to need to do this. Have you ever tried code like this: #!/usr/bin/env ruby foo = nil END { puts "end #{foo}" } puts "regular code" foo = 'bar' BEGIN { puts "begin" } Maybe an END block can help you (but be careful of bindings and visibility...) Mike -- Mike Stok http://www.stok.ca/~mike/ The "`Stok' disclaimers" apply.