[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

how do I create a TestSuite

Rasputin

12/1/2003 3:27:00 PM

This code used to work under 1.6.8 with Test::Unit 0.1.8:

0rasputin@lb:stickyfingers$ cat test/all.rb
#! /usr/local/bin/ruby -w

require 'test/unit'

require 'test/chaintest'
require 'test/chunkertest'
require 'test/filestoretest'

class Daddy < Test::Unit::TestSuite
self << ChainTest.new
self << ChunkerTest.new
self << FilestoreTest.new
end

0rasputin@lb:stickyfingers$

(The classes listed are just bog standard
class ChunkerTest < Test::Unit::TestCase' affairs).

It now gives errors under CVS Ruby - looks like a change in the TestCase
constructor. How do I create a testsuite now?


0rasputin@lb:stickyfingers$ /usr/local/bin/ruby -v
ruby 1.8.1 (2003-11-21) [i386-netbsdelf]
0rasputin@lb:stickyfingers$ /usr/local/bin/ruby test/all.rb
test/all.rb:10:in `initialize': wrong number of arguments(0 for 1) (ArgumentError)
from test/all.rb:10:in `new'
from test/all.rb:10

--
BASIC, n.:
A programming language. Related to certain social diseases in
that those who have it will not admit it in polite company.
Rasputin :: Jack of All Trades - Master of Nuns


4 Answers

Nathaniel Talbott

12/1/2003 5:10:00 PM

0

On Dec 1, 2003, at 10:26, Rasputin wrote:

> This code used to work under 1.6.8 with Test::Unit 0.1.8:

Are you sure? I don't think creating a TestCase without a test to run
has ever worked. I think what you want is:


> 0rasputin@lb:stickyfingers$ cat test/all.rb
> #! /usr/local/bin/ruby -w
>
> require 'test/unit'
>
> require 'test/chaintest'
> require 'test/chunkertest'
> require 'test/filestoretest'
>
> class Daddy < Test::Unit::TestSuite
> self << ChainTest.new
> self << ChunkerTest.new
> self << FilestoreTest.new
self << ChainTest.suite
self << ChunkerTest.suite
self << FilestoreTest.suite
> end


> It now gives errors under CVS Ruby - looks like a change in the
> TestCase
> constructor. How do I create a testsuite now?

As I said, I don't think the code above would have ever worked. You
might like to know, though, that you don't have to create your own
TestSuite; try this:

#! /usr/local/bin/ruby -w

require 'test/unit'

require 'test/chaintest'
require 'test/chunkertest'
require 'test/filestoretest'

I think you'll find that's all you need.

HTH,


Nathaniel

<:((><


Rasputin

12/1/2003 5:34:00 PM

0

* Nathaniel Talbott <nathaniel@talbott.ws> [1210 17:10]:
> On Dec 1, 2003, at 10:26, Rasputin wrote:
>
> >This code used to work under 1.6.8 with Test::Unit 0.1.8:
>
> Are you sure? I don't think creating a TestCase without a test to run
> has ever worked. I think what you want is:

Hmm,looks like you might be right. It definitely worked with no
errors last week, possibly under the CVS code?

> >0rasputin@lb:stickyfingers$ cat test/all.rb
> >#! /usr/local/bin/ruby -w
> >
> >require 'test/unit'
> >
> >require 'test/chaintest'
> >require 'test/chunkertest'
> >require 'test/filestoretest'
> >
> >class Daddy < Test::Unit::TestSuite
> > self << ChainTest.new
> > self << ChunkerTest.new
> > self << FilestoreTest.new
> self << ChainTest.suite
> self << ChunkerTest.suite
> self << FilestoreTest.suite
> >end
>
>
> >It now gives errors under CVS Ruby - looks like a change in the
> >TestCase
> >constructor. How do I create a testsuite now?
>
> As I said, I don't think the code above would have ever worked.

God knows where I got that from then! I cut and pasted from somewhere...

> might like to know, though, that you don't have to create your own
> TestSuite; try this:
>
> #! /usr/local/bin/ruby -w
>
> require 'test/unit'
>
> require 'test/chaintest'
> require 'test/chunkertest'
> require 'test/filestoretest'

Thats great , thanks.

--
Disclaimer: "These opinions are my own, though for a small fee they be
yours too."
-- Dave Haynie
Rasputin :: Jack of All Trades - Master of Nuns

Simon Strandgaard

12/1/2003 8:18:00 PM

0

On Tue, 02 Dec 2003 02:34:02 +0900, Rasputin wrote:

> * Nathaniel Talbott <nathaniel@talbott.ws> [1210 17:10]:
>> On Dec 1, 2003, at 10:26, Rasputin wrote:
>>
>> >This code used to work under 1.6.8 with Test::Unit 0.1.8:
[snip]
>> >class Daddy < Test::Unit::TestSuite
>> > self << ChainTest.new
>> > self << ChunkerTest.new
>> > self << FilestoreTest.new
>> self << ChainTest.suite
>> self << ChunkerTest.suite
>> self << FilestoreTest.suite
>> >end


How about a 'test_all.rb' which simply just appends all testsuites it
finds in current dir ?


server> expand -t2 test_all.rb
require 'test/unit'

class TestAll
def TestAll.suite
suite = Test::Unit::TestSuite.new
Object.constants.sort.each do |k|
next if /^Test/ !~ k
constant = Object.const_get(k)
if constant.kind_of?(Class) &&
constant.superclass == Test::Unit::TestCase
suite << constant.suite
end
end
suite
end
end

if __FILE__ == $0
Dir.glob("test_*.rb").each do |file|
require "#{file}"
end
require 'test/unit/ui/console/testrunner'
Test::Unit::UI::Console::TestRunner.run(TestAll)
end
server>

--
Simon Strandgaard

Rasputin

12/2/2003 9:55:00 AM

0

* Simon Strandgaard <neoneye@adslhome.dk> [1223 20:23]:
>
> How about a 'test_all.rb' which simply just appends all testsuites it
> finds in current dir ?


Sweet! Thanks a lot!

> server> expand -t2 test_all.rb
> require 'test/unit'
>
> class TestAll
> def TestAll.suite
> suite = Test::Unit::TestSuite.new
> Object.constants.sort.each do |k|
> next if /^Test/ !~ k
> constant = Object.const_get(k)
> if constant.kind_of?(Class) &&
> constant.superclass == Test::Unit::TestCase
> suite << constant.suite
> end
> end
> suite
> end
> end
>
> if __FILE__ == $0
> Dir.glob("test_*.rb").each do |file|
> require "#{file}"
> end
> require 'test/unit/ui/console/testrunner'
> Test::Unit::UI::Console::TestRunner.run(TestAll)
> end
> server>
>
> --
> Simon Strandgaard
>

--
All my friends and I are crazy. That's the only thing that keeps us sane.
Rasputin :: Jack of All Trades - Master of Nuns