[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>&gt; -----Original Message-----</FONT>
<BR><FONT SIZE=2>&gt; From: Alan Chen [<A \
HREF="mailto:alan@digikata.com">mailto:alan@digikata.com</A>]</FONT> <BR><FONT \
SIZE=2>&gt; Sent: Friday, October 04, 2002 1:36 PM</FONT> <BR><FONT SIZE=2>&gt; To: \
ruby-talk@ruby-lang.org</FONT> <BR><FONT SIZE=2>&gt; Subject: Re: assertions in \
Ruby</FONT> <BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; On Sat, Oct 05, 2002 at 03:07:53AM +0900, Volkmann, Mark \
wrote:</FONT> <BR><FONT SIZE=2>&gt; &gt; </FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; -----Original Message-----</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; From: Alan Chen [<A \
HREF="mailto:alan@digikata.com">mailto:alan@digikata.com</A>]</FONT> <BR><FONT \
SIZE=2>&gt; &gt; &gt; Sent: Friday, October 04, 2002 11:37 AM</FONT> <BR><FONT \
SIZE=2>&gt; &gt; &gt; To: ruby-talk@ruby-lang.org</FONT> <BR><FONT SIZE=2>&gt; &gt; \
&gt; Subject: Re: assertions in Ruby</FONT> <BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; On Fri, Oct 04, 2002 at 10:43:46PM +0900, Volkmann, \
Mark wrote:</FONT> <BR><FONT SIZE=2>&gt; &gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; Is anyone aware of a Ruby module that adds \
support for</FONT> <BR><FONT SIZE=2>&gt; &gt; &gt; assertions such as what</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; is supported in Java 1.4?&nbsp; I wrote such a \
thing yesterday</FONT> <BR><FONT SIZE=2>&gt; &gt; &gt; and am considering</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; releasing it if I'm not duplicating what someone \
else has</FONT> <BR><FONT SIZE=2>&gt; &gt; &gt; already done.</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; &gt; I've included some examples below showing how \
mine is used.</FONT> <BR><FONT SIZE=2>&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=2>&gt; &gt; &gt; I have an unreleased, partailly completed module \
which include the</FONT> <BR><FONT SIZE=2>&gt; &gt; &gt; Test::Unit asserts when \
$DEBUG is set and do nothing otherwise. It</FONT> <BR><FONT SIZE=2>&gt; &gt; &gt; \
looks almost the same as yours.&nbsp; The only suggestion I </FONT> <BR><FONT \
SIZE=2>&gt; have is maybe</FONT> <BR><FONT SIZE=2>&gt; &gt; &gt; working it in with \
the Ruby::Unit or Test::Unit frameworks.</FONT> <BR><FONT SIZE=2>&gt; &gt; I'm not \
quite convinced that assertions should be </FONT> <BR><FONT SIZE=2>&gt; integrated \
with a unit</FONT> <BR><FONT SIZE=2>&gt; &gt; testing framework. They seem \
fundamentally different to me.</FONT> <BR><FONT SIZE=2>&gt; &gt; With assertions \
enabled, an application generally stops as </FONT> <BR><FONT SIZE=2>&gt; soon as one \
fails. </FONT> <BR><FONT SIZE=2>&gt; &gt; Results are not collected into a report \
since only one </FONT> <BR><FONT SIZE=2>&gt; failure is reported. </FONT>
<BR><FONT SIZE=2>&gt; &gt; Assertions go in the code and remain there for </FONT>
<BR><FONT SIZE=2>&gt; documentation purposes.</FONT>
<BR><FONT SIZE=2>&gt; &gt; With unit tests, tests continue even if one fails.&nbsp; \
Results </FONT> <BR><FONT SIZE=2>&gt; are collected into</FONT>
<BR><FONT SIZE=2>&gt; &gt; a report.&nbsp; Unit tests go in a separate class written \
</FONT> <BR><FONT SIZE=2>&gt; exclusively for testing</FONT>
<BR><FONT SIZE=2>&gt; &gt; purposes.</FONT>
<BR><FONT SIZE=2>&gt; &gt; What kinds of things do you envision that an assertion \
</FONT> <BR><FONT SIZE=2>&gt; framework borrow from a</FONT>
<BR><FONT SIZE=2>&gt; &gt; unit testing framework?</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; Sorry, I didn't mean to imply that unit testing and assertions \
should</FONT> <BR><FONT SIZE=2>&gt; be strongly tied together.&nbsp; Test::Unit for \
example provides a wide</FONT> <BR><FONT SIZE=2>&gt; range of asserts already. The \
Test::Unit assert code itself is a</FONT> <BR><FONT SIZE=2>&gt; fairly orthogonal \
module, and, as far as I know, has no other</FONT> <BR><FONT SIZE=2>&gt; dependencies \
on other parts of the unit test framework.&nbsp; So.. I just</FONT> <BR><FONT \
SIZE=2>&gt; did something like the following:</FONT> <BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; if $DEBUG</FONT>
<BR><FONT SIZE=2>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; module Myasserts</FONT>
<BR><FONT SIZE=2>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; require 'test/unit/assertions'</FONT> \
<BR><FONT SIZE=2>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; include Test::Unit::Assertions</FONT> \
<BR><FONT SIZE=2>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end</FONT> <BR><FONT SIZE=2>&gt; \
else</FONT> <BR><FONT SIZE=2>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # all empty assert \
methods</FONT> <BR><FONT SIZE=2>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; module \
Myasserts</FONT> <BR><FONT SIZE=2>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def flunk(msg);end</FONT> <BR><FONT \
SIZE=2>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
def assert(expr,msg);end</FONT> <BR><FONT SIZE=2>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # other assertions \
omitted...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
</FONT> <BR><FONT SIZE=2>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end</FONT>
<BR><FONT SIZE=2>&gt; end</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; Now instead of Myasserts, an integrated module might be \
named</FONT> <BR><FONT SIZE=2>&gt; Test::Assertions.&nbsp; The main reason to \
separate into its own module is</FONT> <BR><FONT SIZE=2>&gt; that you always want the \
asserts to fire in a unit test, but not</FONT> <BR><FONT SIZE=2>&gt; always during an \
application run.&nbsp; I don't really care if its</FONT> <BR><FONT SIZE=2>&gt; $DEBUG \
that controls it or some other flag. $DEBUG was just convenient</FONT> <BR><FONT \
SIZE=2>&gt; in my case.</FONT> </P>

<P><FONT SIZE=2>Ahh ... now I see what you're getting at.&nbsp; I'll see if I can \
rewrite my assertion code to build on top of assert.rb in RUnit.&nbsp; 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