How to do TDD in Ruby?

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.

On Dec 27, 2006, at 5:46 AM, mekondelta wrote:

with Ruby. Can someone point me to a small-sized ruby project that
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/devel.html

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

Mat S. wrote:

on TDD
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/Unit.html

On 12/27/06, mekondelta [email protected] wrote:

download and examine which shows how a well-organised Ruby project should
start!

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

On Dec 27, 2006, at 02:46, mekondelta wrote:

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 H. - [email protected] - http://blog.segment7.net

I LIT YOUR GEM ON FIRE!

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.rubyforge.org 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

Rob M. wrote:

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. :slight_smile:


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

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

On Dec 28, 2006, at 11:30, M. Edward (Ed) Borasky wrote:

Rob M. 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. :slight_smile:

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 H. - [email protected] - http://blog.segment7.net

I LIT YOUR GEM ON FIRE!

Thanks to all who replied, especially for the style conventions!

On Dec 28, 11:36 am, Eric H. [email protected] 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. :slight_smile:

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 W.

On Fri, 29 Dec 2006 04:36:30 +0900, Eric H. wrote:

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.

On Dec 28, 2006, at 12:05, Rob M. wrote:

everything from the Zen tree. :slight_smile:

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.

You need to read more carefully.


Eric H. - [email protected] - http://blog.segment7.net

I LIT YOUR GEM ON FIRE!

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.

I couldn’t agree with this more–especially since our team may be
bundling
and shipping down a stripped down interp to 10k+ managed servers to do
data collection and reporting. [BTW, love to hear any thoughts on
stripping to bare-bones interp with just needed modules/classes for
automated distribution.]

‘stdlib’ was a hasty mistaken word choice. Thanks for the
corrections. Originally, I meant more as in integration into popular
test
and development tools (few of which I actually care to use personally,
preferring vim + macros + screen for remote pair programming in most all
languages we use).

Thanks,

Rob M. 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.rubyforge.org which
is a behavior driven development framework (BDD). I learned of it from
Josh’s RubyOnRails PodCast, another highly recommended resource.

I know Dan (he of BDD) quite well and should have known he’d come up
with
something!

Thanks for that,

Chris.

Rob M. wrote:
Josh’s RubyOnRails PodCast, another highly recommended resource.

By the way, just noticed I flubbed Geoffrey Grosenbach’s name, or
topfunky (as otherwise known and easier to type). I owe him a beverage
of his choosing, to go with some nice crispy bacon, if I ever bump
into him.

Rob M. wrote:

miniruby?

‘stdlib’ was a hasty mistaken word choice. Thanks for the
corrections. Originally, I meant more as in integration into popular test
and development tools (few of which I actually care to use personally,
preferring vim + macros + screen for remote pair programming in most all
languages we use).
My IDE is Linux. :slight_smile:


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

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

I also just found this:-

http://wiki.rubygarden.org/Ruby/page/show/RubyStyleGuide