From: Mohammad Khan Date: 2004-11-16T03:38:06+09:00 Subject: Re: Starter question on Test::Unit On Mon, 2004-11-15 at 13:31, Nathaniel Talbott wrote: > On Nov 15, 2004, at 12:08, Brian Schræ—¦der wrote: > > > If you want to setup the variables once for the test case, you should > > use: > > > > class TestClass < Test::Unit::TestCase > > def initialize > > super > > @foo = Foo.new > > @run = Foo.run(@foo.key) > > @rerun = Foo.rerun(@run.key) > > end > > > > def test_run > > assert_equal(@foo.key, @run.key) > > end > > > > def test_rerun > > assert_equal(@run.key, @rerun.key) > > end > > end > > > > Would fill each variable only once. > > That actually doesn't work, because the test class is instantiated once > for each run. One way to solve this is like so: > > class TestClass < Test::Unit::TestCase > @@foo = Foo.new > @@run = Foo.run(@@foo.key) > @@rerun = Foo.rerun(@run.key > > def test_run > assert_equal(@@foo.key, @@run.key) > end > > def test_rerun > assert_equal(@run.key, @rerun.key) > end > end > > Now, while I won't claim there's never a reason to do this, it seems > like a major code smell to me. Might be time to break out the air > freshener :-) > > HTH, > > > Nathaniel > Terralien, Inc. > > <:((>< Thanks a lot, Brian and Nathaniel. -- MOhammad