[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: assertions in Ruby
From: "Volkmann, Mark" <Mark.Volkmann () AGEDWARDS ! com>
Date: 2002-10-04 18:52:37
[Download RAW message or body]
> -----Original Message-----
> From: Alan Chen [mailto:alan@digikata.com]
> Sent: Friday, October 04, 2002 1:36 PM
> To: ruby-talk@ruby-lang.org
> Subject: Re: assertions in Ruby
>
>
> On Sat, Oct 05, 2002 at 03:07:53AM +0900, Volkmann, Mark wrote:
> >
> > > -----Original Message-----
> > > From: Alan Chen [mailto:alan@digikata.com]
> > > Sent: Friday, October 04, 2002 11:37 AM
> > > To: ruby-talk@ruby-lang.org
> > > Subject: Re: assertions in Ruby
> > >
> > > On Fri, Oct 04, 2002 at 10:43:46PM +0900, Volkmann, Mark wrote:
> > > >
> > > > Is anyone aware of a Ruby module that adds support for
> > > assertions such as what
> > > > is supported in Java 1.4? I wrote such a thing yesterday
> > > and am considering
> > > > releasing it if I'm not duplicating what someone else has
> > > already done.
> > > > I've included some examples below showing how mine is used.
> > >
> > > I have an unreleased, partailly completed module which include the
> > > Test::Unit asserts when $DEBUG is set and do nothing otherwise. It
> > > looks almost the same as yours. The only suggestion I
> have is maybe
> > > working it in with the Ruby::Unit or Test::Unit frameworks.
> > I'm not quite convinced that assertions should be
> integrated with a unit
> > testing framework. They seem fundamentally different to me.
> > With assertions enabled, an application generally stops as
> soon as one fails.
> > Results are not collected into a report since only one
> failure is reported.
> > Assertions go in the code and remain there for
> documentation purposes.
> > With unit tests, tests continue even if one fails. Results
> are collected into
> > a report. Unit tests go in a separate class written
> exclusively for testing
> > purposes.
> > What kinds of things do you envision that an assertion
> framework borrow from a
> > unit testing framework?
>
> Sorry, I didn't mean to imply that unit testing and assertions should
> be strongly tied together. Test::Unit for example provides a wide
> range of asserts already. The Test::Unit assert code itself is a
> fairly orthogonal module, and, as far as I know, has no other
> dependencies on other parts of the unit test framework. So.. I just
> did something like the following:
>
> if $DEBUG
> module Myasserts
> require 'test/unit/assertions'
> include Test::Unit::Assertions
> end
> else
> # all empty assert methods
> module Myasserts
> def flunk(msg);end
> def assert(expr,msg);end
> # other assertions omitted...
> end
> end
>
> Now instead of Myasserts, an integrated module might be named
> Test::Assertions. The main reason to separate into its own module is
> that you always want the asserts to fire in a unit test, but not
> always during an application run. I don't really care if its
> $DEBUG that controls it or some other flag. $DEBUG was just convenient
> in my case.
Ahh ... now I see what you're getting at. I'll see if I can rewrite my
assertion code to build on top of assert.rb in RUnit. Thanks for the tip!
***********************************************************************************
WARNING: All e-mail sent to and from this address will be received or
otherwise recorded by the A.G. Edwards corporate e-mail system and is
subject to archival, monitoring or review by, and/or disclosure to,
someone other than the recipient.
************************************************************************************
[Attachment #3 (text/html)]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>RE: assertions in Ruby</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>> -----Original Message-----</FONT>
<BR><FONT SIZE=2>> From: Alan Chen [<A \
HREF="mailto:alan@digikata.com">mailto:alan@digikata.com</A>]</FONT> <BR><FONT \
SIZE=2>> Sent: Friday, October 04, 2002 1:36 PM</FONT> <BR><FONT SIZE=2>> To: \
ruby-talk@ruby-lang.org</FONT> <BR><FONT SIZE=2>> Subject: Re: assertions in \
Ruby</FONT> <BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> On Sat, Oct 05, 2002 at 03:07:53AM +0900, Volkmann, Mark \
wrote:</FONT> <BR><FONT SIZE=2>> > </FONT>
<BR><FONT SIZE=2>> > > -----Original Message-----</FONT>
<BR><FONT SIZE=2>> > > From: Alan Chen [<A \
HREF="mailto:alan@digikata.com">mailto:alan@digikata.com</A>]</FONT> <BR><FONT \
SIZE=2>> > > Sent: Friday, October 04, 2002 11:37 AM</FONT> <BR><FONT \
SIZE=2>> > > To: ruby-talk@ruby-lang.org</FONT> <BR><FONT SIZE=2>> > \
> Subject: Re: assertions in Ruby</FONT> <BR><FONT SIZE=2>> > ></FONT>
<BR><FONT SIZE=2>> > > On Fri, Oct 04, 2002 at 10:43:46PM +0900, Volkmann, \
Mark wrote:</FONT> <BR><FONT SIZE=2>> > > ></FONT>
<BR><FONT SIZE=2>> > > > Is anyone aware of a Ruby module that adds \
support for</FONT> <BR><FONT SIZE=2>> > > assertions such as what</FONT>
<BR><FONT SIZE=2>> > > > is supported in Java 1.4? I wrote such a \
thing yesterday</FONT> <BR><FONT SIZE=2>> > > and am considering</FONT>
<BR><FONT SIZE=2>> > > > releasing it if I'm not duplicating what someone \
else has</FONT> <BR><FONT SIZE=2>> > > already done.</FONT>
<BR><FONT SIZE=2>> > > > I've included some examples below showing how \
mine is used.</FONT> <BR><FONT SIZE=2>> > ></FONT>
<BR><FONT SIZE=2>> > > I have an unreleased, partailly completed module \
which include the</FONT> <BR><FONT SIZE=2>> > > Test::Unit asserts when \
$DEBUG is set and do nothing otherwise. It</FONT> <BR><FONT SIZE=2>> > > \
looks almost the same as yours. The only suggestion I </FONT> <BR><FONT \
SIZE=2>> have is maybe</FONT> <BR><FONT SIZE=2>> > > working it in with \
the Ruby::Unit or Test::Unit frameworks.</FONT> <BR><FONT SIZE=2>> > I'm not \
quite convinced that assertions should be </FONT> <BR><FONT SIZE=2>> integrated \
with a unit</FONT> <BR><FONT SIZE=2>> > testing framework. They seem \
fundamentally different to me.</FONT> <BR><FONT SIZE=2>> > With assertions \
enabled, an application generally stops as </FONT> <BR><FONT SIZE=2>> soon as one \
fails. </FONT> <BR><FONT SIZE=2>> > Results are not collected into a report \
since only one </FONT> <BR><FONT SIZE=2>> failure is reported. </FONT>
<BR><FONT SIZE=2>> > Assertions go in the code and remain there for </FONT>
<BR><FONT SIZE=2>> documentation purposes.</FONT>
<BR><FONT SIZE=2>> > With unit tests, tests continue even if one fails. \
Results </FONT> <BR><FONT SIZE=2>> are collected into</FONT>
<BR><FONT SIZE=2>> > a report. Unit tests go in a separate class written \
</FONT> <BR><FONT SIZE=2>> exclusively for testing</FONT>
<BR><FONT SIZE=2>> > purposes.</FONT>
<BR><FONT SIZE=2>> > What kinds of things do you envision that an assertion \
</FONT> <BR><FONT SIZE=2>> framework borrow from a</FONT>
<BR><FONT SIZE=2>> > unit testing framework?</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> Sorry, I didn't mean to imply that unit testing and assertions \
should</FONT> <BR><FONT SIZE=2>> be strongly tied together. Test::Unit for \
example provides a wide</FONT> <BR><FONT SIZE=2>> range of asserts already. The \
Test::Unit assert code itself is a</FONT> <BR><FONT SIZE=2>> fairly orthogonal \
module, and, as far as I know, has no other</FONT> <BR><FONT SIZE=2>> dependencies \
on other parts of the unit test framework. So.. I just</FONT> <BR><FONT \
SIZE=2>> did something like the following:</FONT> <BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> if $DEBUG</FONT>
<BR><FONT SIZE=2>> module Myasserts</FONT>
<BR><FONT SIZE=2>> \
require 'test/unit/assertions'</FONT> \
<BR><FONT SIZE=2>> \
include Test::Unit::Assertions</FONT> \
<BR><FONT SIZE=2>> end</FONT> <BR><FONT SIZE=2>> \
else</FONT> <BR><FONT SIZE=2>> # all empty assert \
methods</FONT> <BR><FONT SIZE=2>> module \
Myasserts</FONT> <BR><FONT SIZE=2>> \
def flunk(msg);end</FONT> <BR><FONT \
SIZE=2>> \
def assert(expr,msg);end</FONT> <BR><FONT SIZE=2>> \
# other assertions \
omitted... \
</FONT> <BR><FONT SIZE=2>> end</FONT>
<BR><FONT SIZE=2>> end</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> Now instead of Myasserts, an integrated module might be \
named</FONT> <BR><FONT SIZE=2>> Test::Assertions. The main reason to \
separate into its own module is</FONT> <BR><FONT SIZE=2>> that you always want the \
asserts to fire in a unit test, but not</FONT> <BR><FONT SIZE=2>> always during an \
application run. I don't really care if its</FONT> <BR><FONT SIZE=2>> $DEBUG \
that controls it or some other flag. $DEBUG was just convenient</FONT> <BR><FONT \
SIZE=2>> in my case.</FONT> </P>
<P><FONT SIZE=2>Ahh ... now I see what you're getting at. I'll see if I can \
rewrite my assertion code to build on top of assert.rb in RUnit. Thanks for the \
tip!</FONT></P>
<CODE><FONT SIZE=3><BR>
<BR>
***********************************************************************************<BR>
WARNING: All e-mail sent to and from this address will be received or<BR>
otherwise recorded by the A.G. Edwards corporate e-mail system and is<BR>
subject to archival, monitoring or review by, and/or disclosure to,<BR>
someone other than the recipient.<BR>
************************************************************************************<BR>
</FONT></CODE></BODY>
</HTML>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic