[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Test::Unit gotcha

Daniel Martin

8/31/2006 11:20:00 PM

Eric Hodel <drbrain@segment7.net> writes:

> On Aug 30, 2006, at 6:16 PM, Morton Goldberg wrote:
>> If I were implementing something like Test::Unit, as an application
>> of principle of least surprise, I would want to ensure Test::Unit
>> preserved the order in which the programmer defined the tests.
>
> An object's methods don't have an order.

Although I agree with the principle that unit tests shouldn't depend
on the order they're executed in (I actually think that Test::Unit
should sort the methods randomly to enforce this), the order that
methods are defined can actually be recorded in Ruby:

irb(main):001:0> class Foo
irb(main):002:1> def Foo.method_added(r); @meth ||= []; @meth << r; end
irb(main):003:1> def Foo.get_meths; @meth; end
irb(main):004:1> end
=> nil
irb(main):005:0>
irb(main):006:0* class FooDescendant < Foo
irb(main):007:1> def h;1;end
irb(main):008:1> def e;1;end
irb(main):009:1> def ll;1;end
irb(main):010:1> def o;1;end
irb(main):011:1> end
=> nil
irb(main):012:0> FooDescendant.get_meths
=> [:h, :e, :ll, :o]

So if the author of Test::Unit wanted to perform tests in the order
that they were defined, it would be perfectly possible without
changing the existing interface. I just don't think it would be a
good idea.

--
s=%q( Daniel Martin -- martin@snowplow.org
puts "s=%q(#{s})",s.map{|i|i}[1] )
puts "s=%q(#{s})",s.map{|i|i}[1]

4 Answers

Eric Hodel

9/1/2006 4:56:00 AM

0

On Aug 31, 2006, at 4:20 PM, Daniel Martin wrote:

> Eric Hodel <drbrain@segment7.net> writes:
>
>> On Aug 30, 2006, at 6:16 PM, Morton Goldberg wrote:
>>> If I were implementing something like Test::Unit, as an application
>>> of principle of least surprise, I would want to ensure Test::Unit
>>> preserved the order in which the programmer defined the tests.
>>
>> An object's methods don't have an order.
>
> Although I agree with the principle that unit tests shouldn't depend
> on the order they're executed in (I actually think that Test::Unit
> should sort the methods randomly to enforce this), the order that
> methods are defined can actually be recorded in Ruby:
>
> irb(main):001:0> class Foo
> irb(main):002:1> def Foo.method_added(r); @meth ||= []; @meth <<
> r; end
> irb(main):003:1> def Foo.get_meths; @meth; end
> irb(main):004:1> end
> => nil
> irb(main):005:0>
> irb(main):006:0* class FooDescendant < Foo
> irb(main):007:1> def h;1;end
> irb(main):008:1> def e;1;end
> irb(main):009:1> def ll;1;end
> irb(main):010:1> def o;1;end
> irb(main):011:1> end
> => nil
> irb(main):012:0> FooDescendant.get_meths
> => [:h, :e, :ll, :o]
>
> So if the author of Test::Unit wanted to perform tests in the order
> that they were defined, it would be perfectly possible without
> changing the existing interface. I just don't think it would be a
> good idea.

Harder than you think:

class AbstractTestCase < Test::Unit::TestCase
def test_one() end
end

class TestClassOne < AbstractTestCase
def test_some_thing() end
end

class TestClassTwo < AbstractTestCase
def test_some_other_thing() end
end

Handling this correctly will take more code than it is worth. Simple
is better.

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...



Tom Gardner

8/21/2012 12:12:00 AM

0

On 8/20/2012 4:51 PM, Kicking Ass and Takin' Names wrote:
> On Mon, 20 Aug 2012 22:21:58 +0200, "Progressive means Parasite"
> <lowlifes@mediamatters.org> wrote:
>
>> You want to vote? Get off welfare and get a job.
>>
>> You want to vote? Unmarried? Go after the 30 babydaddies of
>> your 6 illegitimate brats for support, then we'll talk.
>>
>> You want to vote? Welfare is not a free ride for life just
>> because you are black and playing the race card.
>>
>> You want to vote? Earn the right.
>
>
> If "welfare" prevents people from voting, half the WHITE population of
> TX, LA, AR, MS, AL, GA, WV, and SC will not be able to vote.
>
> Not exactly what you intended.
>
>
>
> *************
>
> "Gun control" means hitting the
> Republikan you're aiming at.
>


Typical violent, racist libtard! ...but I repeat myself.

Too_Many_Tools

8/21/2012 4:55:00 PM

0

On Aug 20, 3:51 pm, Kicking Ass and Takin' Names
<PopUlist...@hotmail.com> wrote:
> On Mon, 20 Aug 2012 22:21:58 +0200, "Progressive means Parasite"
>
> <lowli...@mediamatters.org> wrote:
> >You want to vote?  Get off welfare and get a job.
>
> >You want to vote?  Unmarried? Go after the 30 babydaddies of
> >your 6 illegitimate brats for support, then we'll talk.
>
> >You want to vote?  Welfare is not a free ride for life just
> >because you are black and playing the race card.
>
> >You want to vote?  Earn the right.
>
> If "welfare" prevents people from voting, half the WHITE population of
> TX, LA, AR, MS, AL, GA, WV, and SC will not be able to vote.
>
> Not exactly what you intended.
>
> *************
>
> "Gun control" means hitting the
> Republikan you're aiming at.

Correct..the cream of the crop for the Republican Party.

TMT

JerryD\(upstateNY\)

8/22/2012 5:45:00 AM

0

some lib wrote "Gun control" means
hitting the Republican you're aiming at.<<<

Some liberal weenie wrote the above.
hahahahahaha
Since he is for gun control, I wonder what he is aiming with ?
A fly swatter, maybe ?
hahahahaha
hehehehehe

--
JerryD(upstateNY)