Forum: Ruby using unit test

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
02bd6b98b7c04f9ae5868eda3d01fb73?d=identicon&s=25 rtilley (Guest)
on 2006-03-24 02:23
(Received via mailing list)
What is the most prevalent way of using unit testing in Ruby? Do I
require 'test/unit' and add test methods to production scripts and then
comment the testing portions out when not testing? Or, should I develop
a 'testing' version of the scripts identical to the production versions?

Thanks for any advice. I've got the concept down... just thinking about
implementation and actively using tests.

Brad
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2006-03-24 02:38
(Received via mailing list)
On 3/23/06, rtilley <rtilley@vt.edu> wrote:
> What is the most prevalent way of using unit testing in Ruby? Do I
> require 'test/unit' and add test methods to production scripts and then
> comment the testing portions out when not testing? Or, should I develop
> a 'testing' version of the scripts identical to the production versions?
>
> Thanks for any advice. I've got the concept down... just thinking about
> implementation and actively using tests.

I generally put my tests in a separate tests directory from my code.
Then I have a 'run_tests.rb' file that runs all the tests.  Here's the
entirety of run_tests.rb:

        Dir["tests/*"].each { |f| require f }

Or, you could somehow use Rake to run the tests, like Rails does.

Joe
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2006-03-24 02:49
(Received via mailing list)
On Mar 23, 2006, at 5:38 PM, Joe Van Dyk wrote:

>> about
>> implementation and actively using tests.
>
> I generally put my tests in a separate tests directory from my code.
> Then I have a 'run_tests.rb' file that runs all the tests.  Here's the
> entirety of run_tests.rb:
>
>         Dir["tests/*"].each { |f| require f }
>
> Or, you could somehow use Rake to run the tests, like Rails does.

Even easier:

$ ls
test/
$ ls test
test_something.rb
$ testrb test
Loaded suite test
Started
.
Finished in 0.012917 seconds.

1 tests, 1 assertions, 0 failures, 0 errors

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

http://trackmap.robotcoop.com
37a3c73ffbf864e4b28f7f2384ee12ce?d=identicon&s=25 Timothy Hunter (tim-hunter)
on 2006-03-24 03:04
(Received via mailing list)
rtilley wrote:
> What is the most prevalent way of using unit testing in Ruby? Do I
> require 'test/unit' and add test methods to production scripts and then
> comment the testing portions out when not testing? Or, should I develop
> a 'testing' version of the scripts identical to the production versions?
>
> Thanks for any advice. I've got the concept down... just thinking about
> implementation and actively using tests.
>
> Brad

Put the tests in a separate directory alongside the code. Chapter 12 of
the Pickaxe includes some "best practices" for unit testing Ruby with
Test::Unit.
95ece3bc20c5dc43685302703a1e99bd?d=identicon&s=25 Erik Hollensbe (Guest)
on 2006-03-29 01:29
(Received via mailing list)
On 2006-03-23 17:38:03 -0800, Tim Hunter <cyclists@nc.rr.com> said:

>
> Put the tests in a separate directory alongside the code. Chapter 12 of
> the Pickaxe includes some "best practices" for unit testing Ruby with
> Test::Unit.

I have a patch which fixes the test functionality in Minero Aoki's
setup.rb, which lets you create a test/ directory and run:

ruby setup.rb test

and it will execute all the tests in the test/ directory.

Please email privately if you want the patch (I've already submitted it
and recieved no response).
This topic is locked and can not be replied to.