Forum: Ruby How to do TDD in Ruby?

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.
C8ca03811369571c95cd89925136015c?d=identicon&s=25 mekondelta (Guest)
on 2006-12-27 11:48
(Received via mailing list)
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.
Fc784eadb3b54531fdc3d2053db6f83f?d=identicon&s=25 Mat Schaffer (Guest)
on 2006-12-27 15:34
(Received via mailing list)
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
A083f2c63fc0be7f8f19006c9dbdff86?d=identicon&s=25 Dale Martenson (dale)
on 2006-12-27 16:26
(Received via mailing list)
Mat Schaffer 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/rd...
25e11a00a89683f7e01e425a1a6e305c?d=identicon&s=25 Wilson Bilkovich (Guest)
on 2006-12-27 17:20
(Received via mailing list)
On 12/27/06, mekondelta <Chris.Melikian@uk.fid-intl.com> 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.
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2006-12-27 23:05
(Received via mailing list)
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 Hodel - drbrain@segment7.net - http://blog.segment7.net

I LIT YOUR GEM ON FIRE!
C8ca03811369571c95cd89925136015c?d=identicon&s=25 mekondelta (Guest)
on 2006-12-28 16:36
(Received via mailing list)
Thanks to all who replied, especially for the style conventions!
53372374d12edca5a0cb1b028ec32690?d=identicon&s=25 Rob Muhlestein (Guest)
on 2006-12-28 20:21
(Received via mailing list)
> 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
3bb23e7770680ea44a2d79e6d10daaed?d=identicon&s=25 M. Edward (Ed) Borasky (Guest)
on 2006-12-28 20:31
(Received via mailing list)
Rob Muhlestein 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. :)

--
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.
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2006-12-28 20:37
(Received via mailing list)
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.segment7.net

I LIT YOUR GEM ON FIRE!
10d9ed7ab11115b081bb36f56a7a13bc?d=identicon&s=25 John Wilger (jwilger)
on 2006-12-28 21:01
(Received via mailing list)
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://johnwilger.com
53372374d12edca5a0cb1b028ec32690?d=identicon&s=25 Rob Muhlestein (Guest)
on 2006-12-28 21:05
(Received via mailing list)
On Fri, 29 Dec 2006 04:36:30 +0900, Eric Hodel 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.
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2006-12-28 21:13
(Received via mailing list)
On Dec 28, 2006, at 12:05, Rob Muhlestein wrote:
>>> 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.

You need to read more carefully.

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

I LIT YOUR GEM ON FIRE!
53372374d12edca5a0cb1b028ec32690?d=identicon&s=25 Rob Muhlestein (Guest)
on 2006-12-28 21:25
(Received via mailing list)
> 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,
3bb23e7770680ea44a2d79e6d10daaed?d=identicon&s=25 M. Edward (Ed) Borasky (Guest)
on 2006-12-28 21:39
(Received via mailing list)
Rob Muhlestein 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. :)

--
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.
C8ca03811369571c95cd89925136015c?d=identicon&s=25 mekondelta (Guest)
on 2006-12-29 10:13
(Received via mailing list)
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.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.
53372374d12edca5a0cb1b028ec32690?d=identicon&s=25 Rob Muhlestein (Guest)
on 2006-12-29 16:06
(Received via mailing list)
> 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.
C8ca03811369571c95cd89925136015c?d=identicon&s=25 mekondelta (Guest)
on 2006-12-29 16:48
(Received via mailing list)
This topic is locked and can not be replied to.