[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

How to do TDD in Ruby?

mekondelta

12/27/2006 10:47:00 AM


Hi,

I'm new to Ruby but am fairly experience in using TDD with Java and am
having some problems in converting my knowledge over.

I'm using the Eclipse Ruby plug-in and want so organise my test source and
code source files separately as I do in Java. While I have found some
tutorials on Ruby and they have been helpful, I have found nothing on TDD
with Ruby. Can someone point me to a small-sized ruby project that I could
download and examine which shows how a well-organised Ruby project should
look? The things I am looking for are:-
- Best practice in terms of code style eg variable/class naming etc
- interaction between class files
- tests in separate folders to source
- ant build script?

Ideally a tutorial would be available but I'm sure the above is available
somewhere but I can't find it!

Any help greatly appreciated so that I can learn Ruby the right way from the
start!

Cheers, Chris.
--
View this message in context: http://www.nabble.com/How-to-do-TDD-in-Ruby--tf2885359.htm...
Sent from the ruby-talk mailing list archive at Nabble.com.


16 Answers

Mat Schaffer

12/27/2006 2:33:00 PM

0

On Dec 27, 2006, at 5:46 AM, mekondelta wrote:
> Hi,
>
> I'm new to Ruby but am fairly experience in using TDD with Java and am
> having some problems in converting my knowledge over.
>
> I'm using the Eclipse Ruby plug-in and want so organise my test
> source and
> code source files separately as I do in Java. While I have found some
> tutorials on Ruby and they have been helpful, I have found nothing
> on TDD
> with Ruby. Can someone point me to a small-sized ruby project that
> I could
> download and examine which shows how a well-organised Ruby project
> should
> look? The things I am looking for are:-
> - Best practice in terms of code style eg variable/class naming etc
> - interaction between class files
> - tests in separate folders to source
> - ant build script?
>
> Ideally a tutorial would be available but I'm sure the above is
> available
> somewhere but I can't find it!
>
> Any help greatly appreciated so that I can learn Ruby the right way
> from the
> start!

I seem to remember a project that was working on this. Basically it
would build a nice structure that allowed for TDD pretty simply. But
I can't find it at the moment. Maybe someone on the list remembers.

If you're building libraries the structure for setup.rb is the standard:
http://i.loveruby.net/en/projects/setup/doc/...

Rails is another option you might consider. I've taken to using
Rails for my CLI projects as well because it buys you a full TDD
framework + ORM right out of the gate. You can delete some of the
cruft (app/views, app/controllers, for example) if you don't need it
for your project.

Hope that helps some.
-Mat


Dale Martenson

12/27/2006 3:23:00 PM

0


Mat Schaffer wrote:
> On Dec 27, 2006, at 5:46 AM, mekondelta wrote:
> > Hi,
> >
> > I'm new to Ruby but am fairly experience in using TDD with Java and am
> > having some problems in converting my knowledge over.
> >
> > I'm using the Eclipse Ruby plug-in and want so organise my test
> > source and
> > code source files separately as I do in Java. While I have found some
> > tutorials on Ruby and they have been helpful, I have found nothing
> > on TDD
> > with Ruby. Can someone point me to a small-sized ruby project that
> > I could
> > download and examine which shows how a well-organised Ruby project
> > should
> > look? The things I am looking for are:-
> > - Best practice in terms of code style eg variable/class naming etc
> > - interaction between class files
> > - tests in separate folders to source
> > - ant build script?
> >
> > Ideally a tutorial would be available but I'm sure the above is
> > available
> > somewhere but I can't find it!
> >
> > Any help greatly appreciated so that I can learn Ruby the right way
> > from the
> > start!
>


Test::Unit is the way to go. See ...

http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test...

Wilson Bilkovich

12/27/2006 4:20:00 PM

0

On 12/27/06, mekondelta <Chris.Melikian@uk.fid-intl.com> wrote:
>
> Hi,
>
> I'm new to Ruby but am fairly experience in using TDD with Java and am
> having some problems in converting my knowledge over.
>
> I'm using the Eclipse Ruby plug-in and want so organise my test source and
> code source files separately as I do in Java. While I have found some
> tutorials on Ruby and they have been helpful, I have found nothing on TDD
> with Ruby. Can someone point me to a small-sized ruby project that I could
> download and examine which shows how a well-organised Ruby project should
> look? The things I am looking for are:-
> - Best practice in terms of code style eg variable/class naming etc
> - interaction between class files
> - tests in separate folders to source
> - ant build script?
>
> Ideally a tutorial would be available but I'm sure the above is available
> somewhere but I can't find it!
>
> Any help greatly appreciated so that I can learn Ruby the right way from the
> start!
>

Allow me to suggest: http://rspec.rub...
It doesn't contain any 'complete' apps, but it has some decent Ruby
samples, and a partial Rails app included in the repository.

Eric Hodel

12/27/2006 10:05:00 PM

0

On Dec 27, 2006, at 02:46, mekondelta wrote:
> I'm new to Ruby but am fairly experience in using TDD with Java and am
> having some problems in converting my knowledge over.
>
> I'm using the Eclipse Ruby plug-in and want so organise my test
> source and
> code source files separately as I do in Java. While I have found some
> tutorials on Ruby and they have been helpful, I have found nothing
> on TDD
> with Ruby. Can someone point me to a small-sized ruby project that
> I could
> download and examine which shows how a well-organised Ruby project
> should
> look? The things I am looking for are:-
> - Best practice in terms of code style eg variable/class naming etc
> - interaction between class files

typical style looks something like:

modules and classes are CamelCase

other constants are UPPERCASE_WITH_UNDERSCORES

variables and method names use underscores like_this

indentation is two spaces

for files:

libs go in lib/, tests go in test/, executables go in bin/

lib/blah.rb contains class/module Blah. A :: usually indicates a
file in a new directory, unless the contents of the class are small.
(Test::Unit::TestCase is in test/unit/testcase.rb.)

> - tests in separate folders to source

The Official Test::Unit Way of Naming Test Files and Classes is:

test/test_blah.rb contains "class TestBlah < Test::Unit::TestCase"
and tests class/module Blah in lib/blah.rb. (Usually there isn't a
directory hierarchy under test/, everything is flattened to
underscores.)

Oh, and you want to run autotest which you'll find in the ZenTest
gem. autotest runs tests when you save your files, and figures out
which test to run based on The Official Test::Unit Way of Naming.
Testers find it more addictive than crack.

> - ant build script?

We use rake and Rakefiles in ruby. Occasionally you'll see a Makefile.

> Ideally a tutorial would be available but I'm sure the above is
> available
> somewhere but I can't find it!
>
> Any help greatly appreciated so that I can learn Ruby the right way
> from the
> start!

If you want to create abstract test cases use
"undef_method :default_test" in your abstract test case to prevent it
from complaining about no tests.

--
Eric Hodel - drbrain@segment7.net - http://blog.se...

I LIT YOUR GEM ON FIRE!


mekondelta

12/28/2006 3:36:00 PM

0


Thanks to all who replied, especially for the style conventions!
--
View this message in context: http://www.nabble.com/How-to-do-TDD-in-Ruby--tf2885359.htm...
Sent from the ruby-talk mailing list archive at Nabble.com.


Rob Muhlestein

12/28/2006 7:20:00 PM

0

> I'm new to Ruby but am fairly experience in using TDD with Java and am
> having some problems in converting my knowledge over.

I strongly recommend a look a rspec at http://rspec.rub... which
is a behavior driven development framework (BDD). I learned of it from
Josh's RubyOnRails PodCast, another highly recommended resource.

I can honestly say I actually enjoyed writing a spec and test suite with
it. They have converters that will also take the natural language from it
and generate a 'manager-friendly' document outlining all the
specification, just so cool--especially to those of us pushing Ruby hard
in the enterprise.

> I'm using the Eclipse Ruby plug-in and want so organise my test source and
> code source files separately as I do in Java.

Rspec hasn't made into the RadRails plugin yet, and there has been talk
about it on other threads. From the buzz rspec is generating I would
bet it will become core or stdlib soon.

> Ideally a tutorial would be available but I'm sure the above is available
> somewhere but I can't find it!

They have a tutorial on the rspec site.

Enjoy.

Rob

M. Edward (Ed) Borasky

12/28/2006 7:31:00 PM

0

Rob Muhlestein wrote:
>> I'm new to Ruby but am fairly experience in using TDD with Java and am
>> having some problems in converting my knowledge over.
>>
>
> I strongly recommend a look a rspec at http://rspec.rub... which
> is a behavior driven development framework (BDD). I learned of it from
> Josh's RubyOnRails PodCast, another highly recommended resource.
>
> I can honestly say I actually enjoyed writing a spec and test suite with
> it. They have converters that will also take the natural language from it
> and generate a 'manager-friendly' document outlining all the
> specification, just so cool--especially to those of us pushing Ruby hard
> in the enterprise.
>
Yes ... I'll second or third or whatever the use of Rspec. I'm trying to
figure out how to use it as a framework to do BDD in some other
languages (R at the moment, but perhaps VBA as well).

> Rspec hasn't made into the RadRails plugin yet, and there has been talk
> about it on other threads. From the buzz rspec is generating I would
> bet it will become core or stdlib soon.
>
Yes, if Test::Unit are core, Rspec should be too. But then, so should
everything from the Zen tree. :)

--
M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)
http://borasky-research.blo...

If God had meant for carrots to be eaten cooked, He would have given rabbits fire.


Eric Hodel

12/28/2006 7:37:00 PM

0

On Dec 28, 2006, at 11:30, M. Edward (Ed) Borasky wrote:
> Rob Muhlestein wrote:
>> Rspec hasn't made into the RadRails plugin yet, and there has been
>> talk
>> about it on other threads. From the buzz rspec is generating I would
>> bet it will become core or stdlib soon.
>>
> Yes, if Test::Unit are core, Rspec should be too. But then, so
> should everything from the Zen tree. :)

No and no. Ruby releases as infrequently as once a year. ZenTest
can be released as often as I feel like it. Including it in ruby
would kill any potential for growth.

--
Eric Hodel - drbrain@segment7.net - http://blog.se...

I LIT YOUR GEM ON FIRE!


John Wilger

12/28/2006 7:55:00 PM

0

On Dec 28, 11:36 am, Eric Hodel <drbr...@segment7.net> wrote:
> On Dec 28, 2006, at 11:30, M. Edward (Ed) Borasky wrote:
> > Yes, if Test::Unit are core, Rspec should be too. But then, so
> > should everything from the Zen tree. :)
>
> No and no. Ruby releases as infrequently as once a year. ZenTest
> can be released as often as I feel like it. Including it in ruby
> would kill any potential for growth.

I'm with Eric here. The standard library should be limited to things
that either a) Ruby would be /almost/ useless without (if it would be
entirely useless, it should be in core) or b) libraries that are so
stable that there is no reason to update them other than to maintain
compatibility with the latest ruby release (and this group should be
limited to things that are "generally useful" as well).

As long as we have an easy to use system for pulling in other external
libraries (Gems seems to be the winner here for Ruby), it's much better
to keep the core and standard library as light as is reasonably
possible.

--
Regards,

John Wilger
http://john...

Rob Muhlestein

12/28/2006 8:04:00 PM

0

On Fri, 29 Dec 2006 04:36:30 +0900, Eric Hodel wrote:
>> Rob Muhlestein wrote:
>>> Rspec hasn't made into the RadRails plugin yet, and there has been talk
>>> about it on other threads. From the buzz rspec is generating I would
>>> bet it will become core or stdlib soon.
>>>
>> Yes, if Test::Unit are core, Rspec should be too. But then, so should
>> everything from the Zen tree. :)
>
> No and no. Ruby releases as infrequently as once a year. ZenTest can be
> released as often as I feel like it. Including it in ruby would kill any
> potential for growth.

So is that a definite no to Rspec support in a future version of ZenTest?
Haven't looked at yet but was considering. Not flaming, just curious.

--
Rob Muhlestein
http://rob.muhl...