Re: How do I patch Test::Unit?
Jeff,
I just tested the change to unit.rb that you mentioned, and it had the
expected effect (printing "Hello there"). So I would make sure you're
editing the right file. If you are sure you are editing the right file,
but still cannot get any result, try deleting it -- then you'll know for
sure whether that file is being used.
As for not being able to edit the (open) classes, make sure you are
editing the classes after you require the files, otherwise your changes
will be overwritten. Also be very careful about namespaces / modules and
such. I suggest not using any "include" statements, because they might
introduce ambiguity. The important thing is that when you make a change
to the class in question, you are changing the right class (and not just
making a new one). When I ran "irb -r 'test/unit'", I found that the
module Test::Unit::UI existed, but Test::Unit::UI::Console did not, so
that might be your problem. (I just tested with "puts".)
Finally, for which strategy you should use to extend these tools:
-If your end goal is to make changes that you want distributed with the
ruby standard library, you might as well patch the source directly.
-If you intend to distribute your code as a library or gem, you had
better reopen the class in a different file (not patch unit.rb), because
it would be rude to ask users to make that change for the sake of your
program. After all, it could break other programs.
-If this is purely for personal use, you may do whichever is easier. The
second way leaves you less likely to accidentally cripple your Ruby
distribution.
Hope this s,
Dan
Jeff wrote:
> Perhaps my original post was too long or too obtuse... let me
> rephrase.
>
> What's the best way to extend then test/unit classes?
>
> Thanks
> Jeff
>
> On Sep 14, 6:50 pm, Jeff <cohen.j...@gmail.com> wrote:
>> I've finally found some time to dig into one of my favorite parts of
>> Ruby, the Test::Unit module. I have some ideas for how to enhance it
>> a bit.
>>
>> First I just wanted to do a sanity check that I can make changes and
>> see the effects. For some reason, no matter what I modify in my
>> Test::Unit source code, my changes don't seem to take effect.
>>
>> For example, if I found unit.rb and added a puts statement:
>>
>> at_exit do
>> unless $! || Test::Unit.run?
>> puts "HELLO THERE!"
>> exit Test::Unit::AutoRunner.run
>> end
>> end
>>
>> but when I run my test (a simple ruby file that requires test/unit), I
>> don't see "HELLO THERE!".
>>
>> I also tried just reopening the class right above my test class
>> definition:
>>
>> module Test
>> module Unit
>> module UI
>> module Console
>>
>> # Runs a Test::Unit::TestSuite on the console.
>> class TestRunner
>> def start
>> output "Hello There!"
>> setup_mediator
>> attach_to_mediator
>> return start_mediator
>> end
>> end
>> end
>> end
>> end
>> end
>>
>> and still nothing.
>>
>> What am I doing wrong?
>>
>> Oh, ruby -v reports:
>> ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.9.1]
>>
>> Thanks
>> Jeff
>
>
>
|