How to do TDD in Ruby?

M

mekondelta

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

Mat Schaffer

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

Wilson Bilkovich

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

Eric Hodel

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

Rob Muhlestein

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
 
M

M. Edward (Ed) Borasky

Rob said:
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.
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. :)
 
E

Eric Hodel

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

John Wilger

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

Rob Muhlestein

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

Eric Hodel

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

Rob Muhlestein

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,
 
M

M. Edward (Ed) Borasky

Rob said:
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.]
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. :)
 
M

mekondelta

Rob said:
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.
 
R

Rob Muhlestein

Rob Muhlestein 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top