From: Mohammad Khan Date: 2004-11-16T02:37:56+09:00 Subject: Re: Starter question on Test::Unit On Mon, 2004-11-15 at 12:08, Brian Schræ—¦der wrote: > On Tue, 16 Nov 2004 00:36:25 +0900 > Mohammad Khan wrote: > > > Hello, > > > > I am using Test::Unit for couple of days. > > > > I have a script something like this: > > > > class TestClass < Test::Unit::TestCase > > > > def setup > > @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 > Brian, It didn't work. [mkhan@localhost temp]$ cat a.rb #!/usr/bin/env ruby require 'test/unit' class TestClass < Test::Unit::TestCase def initialize super puts "in setup" end def test_run assert_equal(true, true) end def test_rerun assert_equal(true, true) end def test_rererun assert_equal(true, true) end end [mkhan@localhost temp]$ ruby a.rb /usr/local/lib/ruby/1.8/test/unit/testcase.rb:51:in `initialize': wrong number of arguments(1 for 0) (ArgumentError) from /usr/local/lib/ruby/1.8/test/unit/testcase.rb:51:in `new' from /usr/local/lib/ruby/1.8/test/unit/testcase.rb:51:in `suite' from /usr/local/lib/ruby/1.8/test/unit/testcase.rb:50:in `catch' from /usr/local/lib/ruby/1.8/test/unit/testcase.rb:50:in `suite' from /usr/local/lib/ruby/1.8/test/unit/testcase.rb:48:in `each' from /usr/local/lib/ruby/1.8/test/unit/testcase.rb:48:in `suite' from /usr/local/lib/ruby/1.8/test/unit/collector/objectspace.rb:25:in `collect' from /usr/local/lib/ruby/1.8/test/unit/collector/objectspace.rb:23:in `each_object' from /usr/local/lib/ruby/1.8/test/unit/collector/objectspace.rb:23:in `collect' from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:52 from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:48:in `[]' from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:183:in `run' from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:13:in `run' from /usr/local/lib/ruby/1.8/test/unit.rb:275 from /usr/local/lib/ruby/1.8/test/unit.rb:275 -- Mohammad > 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. > > Regards, > > Brian -- [mkhan@localhost local]$ rm -Rf /bin/laden