[#35036] Intentional Programming — "John" <nojgoalbyspam@...>

Hi all

17 messages 2002/03/01

[#35112] RDoc question — Michael Davis <mdavis@...>

I have a question about RDoc. I would like to reference an external

17 messages 2002/03/02

[#35162] string to array and back — Ron Jeffries <ronjeffries@...>

I am needing to convert strings to arrays of bytes and back. I see pack and

19 messages 2002/03/03

[#35364] file reading impossibly slow? — Ron Jeffries <ronjeffries@...>

So I'm doing this benchmark to work with my set program. Part of the problem is

18 messages 2002/03/07

[#35429] Interesting link on static/dynamic typing... — Robert Feldt <feldt@...>

...relevant to Ruby compared to other languages discussion:

25 messages 2002/03/08
[#35441] Re: Interesting link on static/dynamic typing... — Paul Brannan <paul@...> 2002/03/08

On Fri, Mar 08, 2002 at 05:34:43PM +0900, Robert Feldt wrote:

[#35460] Spam, ruby-talk, and me — Dave Thomas <Dave@...>

14 messages 2002/03/08

[#35537] Confusion — David Corbin <dcorbin@...>

The following is from my debugging through xmlc.rb

16 messages 2002/03/10

[#35579] RE: WIN32OLE and LDAP — "Morris, Chris" <chris.morris@...>

> The new version 0.4.2 of Win32OLE has WIN32OLE.bind method.

16 messages 2002/03/11

[#35652] Method type 'abstract' — Peter Hickman <peter@...>

The one thing I miss in Ruby is the abstract class method to go along

15 messages 2002/03/12

[#35653] Some potential RCRs — "Bob Alexander" <bobalex@...>

Here are a few thing I am considering submitting as RCRs. I'm looking for comments to help decide whether to make them official, so please let know what you think is good and bad about these...

50 messages 2002/03/12
[#35672] Re: Some potential RCRs — matz@... (Yukihiro Matsumoto) 2002/03/12

Hi,

[#35683] Re: Some potential RCRs — Massimiliano Mirra <list@...> 2002/03/12

On Wed, Mar 13, 2002 at 03:58:01AM +0900, Yukihiro Matsumoto wrote:

[#35697] Re: Some potential RCRs — David Alan Black <dblack@...> 2002/03/13

Hello --

[#35694] rpkg 0.3 — Massimiliano Mirra <list@...>

14 messages 2002/03/13
[#35699] RE: [ANN] rpkg 0.3 — <james@...> 2002/03/13

>

[#35787] testunit - setup -> set_up ? — "Morris, Chris" <chris.morris@...>

I'm just starting to use testunit instead of rubyunit ... I noticed with an

21 messages 2002/03/13
[#35793] RE: testunit - setup -> set_up ? — "Nathaniel Talbott" <nathaniel@...> 2002/03/13

Morris, Chris [mailto:chris.morris@snelling.com] wrote:

[#35796] Re: testunit - setup -> set_up ? — Dave Thomas <Dave@...> 2002/03/13

"Nathaniel Talbott" <nathaniel@talbott.ws> writes:

[#35797] RE: testunit - setup -> set_up ? — "Nathaniel Talbott" <nathaniel@...> 2002/03/13

dave@thomases.com [mailto:dave@thomases.com] wrote:

[#35898] camelCase and underscore_style — "Morris, Chris" <chris.morris@...>

First, a question. If underscore_style is the Ruby norm for methods and the

20 messages 2002/03/15
[#35924] Re: camelCase and underscore_style — "Guy N. Hurst" <gnhurst@...> 2002/03/15

Phil Tomson wrote:

[#35930] RE: camelCase and underscore_style — "Nathaniel Talbott" <nathaniel@...> 2002/03/16

Guy N. Hurst [mailto:gnhurst@hurstlinks.com] wrote:

[#35989] ANN: Locana GUI and GUI Builder version 0.81 — Michael Davis <mdavis@...>

I am pleased to announce release 0.81 of Locana. Locana is a GUI

16 messages 2002/03/16

[#35992] XPath — Michael Schuerig <schuerig@...>

27 messages 2002/03/16

[#36034] Mini Rant: Indenting — Thomas Hurst <tom.hurst@...>

Why is it that I see *so* much code like:

14 messages 2002/03/17

[#36049] web templating for static sites? — Massimiliano Mirra <list@...>

I'm using the Template Toolkit for generating static web sites and I

42 messages 2002/03/17
[#36426] web standars (was: web templating for static sites?) — Tobias Reif <tobiasreif@...> 2002/03/20

Albert Wagner wrote:

[#36052] Xml Serialization for Ruby — "Chris Morris" <chrismo@...>

=Xml Serialization for Ruby

20 messages 2002/03/17
[#36059] Re: [ANN] Xml Serialization for Ruby — Massimiliano Mirra <list@...> 2002/03/17

On Mon, Mar 18, 2002 at 05:20:56AM +0900, Chris Morris wrote:

[#36067] eval/Module question — David Corbin <dcorbin@...>

If I have a String src that is similar to the following:

13 messages 2002/03/18

[#36157] Development of Windows version of Ruby — ptkwt@...1.aracnet.com (Phil Tomson)

Now that we've dumped the cygwin requirement for the Windows version of

63 messages 2002/03/18
[#36330] Re: Development of Windows version of Ruby — Ron Jeffries <ronjeffries@...> 2002/03/19

On Tue, 19 Mar 2002 14:05:27 GMT, "Albert L. Wagner" <alwagner@uark.edu> wrote:

[#36431] Re: Development of Windows version of Ruby — Dennis Newbold <dennisn@...> 2002/03/20

[#36458] Windows version of Ruby (proposals) — ptkwt@... (Phil Tomson) 2002/03/21

Dennis Newbold <dennisn@pe.net> wrote in message news:<Pine.GSO.3.96.1020320113603.22242B-100000@shell2>...

[#36482] RE: Windows version of Ruby (proposals) — "Christian Boos" <cboos@...> 2002/03/21

Some thoughts on the 2 first Windows issues, plus a 4th one...

[#36496] Re: Windows version of Ruby (proposals) — Dave Thomas <Dave@...> 2002/03/21

"Christian Boos" <cboos@bct-technology.com> writes:

[#36510] Re: Windows version of Ruby (proposals) — nobu.nokada@... 2002/03/21

Hi,

[#36514] Re: Windows version of Ruby (proposals) — Dave Thomas <Dave@...> 2002/03/21

nobu.nokada@softhome.net writes:

[#36518] Re: Windows version of Ruby (proposals) — nobu.nokada@... 2002/03/21

Hi,

[#36211] dots in Dir.entries — matz@... (Yukihiro Matsumoto)

Hi,

22 messages 2002/03/19

[#36231] style choice — Ron Jeffries <ronjeffries@...>

A style question for the community ... which of the following do you prefer, and

18 messages 2002/03/19

[#36345] ANN: REXML 2.0 — Sean Russell <ser@...>

I have a feeling there will only be three major revisions of REXML. Version

19 messages 2002/03/20

[#36610] Re: Windows version of Ruby (proposals) — Ron Jeffries <ronjeffries@...>

On Thu, 21 Mar 2002 14:11:55 GMT, Dave Thomas <Dave@PragmaticProgrammer.com> wrote:

16 messages 2002/03/22

[#36645] Ruby for Mac OS 10.1 — Jim Freeze <jim@...>

Hi:

28 messages 2002/03/23

[#36768] Re: Difference between 'do' and 'begin' — Clemens Hintze <c.hintze@...>

In <slrna9ulvi.f2h.mwg@fluffy.isd.dp.ua> Wladimir Mutel <mwg@fluffy.isd.dp.ua> writes:

23 messages 2002/03/26
[#36783] RE: Difference between 'do' and 'begin' — <james@...> 2002/03/26

[#36792] Re: Difference between 'do' and 'begin' — Kent Dahl <kentda@...> 2002/03/26

james@rubyxml.com wrote:

[#36808] Error calling Tk in a loop — <james@...>

I'm trying to write some code that pops up a Tk window when for certain

15 messages 2002/03/26

[#36841] RE: Windows version of Ruby (proposals) — "Andres Hidalgo" <sol123@...>

I believe that Ruby has a place in windows (Office), I happened to have

14 messages 2002/03/27

[#36863] Hash.new(Hash.new) doesn't use Hash.new as default value — "Jonas Delfs" <jonas@...>

Hi -

18 messages 2002/03/27

[#37080] Why isn't Math object-oriented? — Bil Kleb <W.L.Kleb@...>

So I'm reading along in the Pixaxe book (yet again), and I am told

15 messages 2002/03/30

[#37121] String#begins?(s) — timsuth@... (Tim Sutherland)

class String

24 messages 2002/03/31

RE: Test::Unit [long]

From: "Nathaniel Talbott" <nathaniel@...>
Date: 2002-03-15 01:29:45 UTC
List: ruby-talk #35861
Steve Merrick [mailto:Steve.Merrick@Marconi.com] wrote:

> Can someone explain to me the *details* of how to use
> Test::Unit, preferably an example showing the source code to 
> be tested, the test code, and any other glue or details 
> necessary to make it all work? I've never done this before, 
> and it isn't clear to me how you arrange your code and 
> test-code so that your tests can be run automatically, 
> quickly and often. Test harnesses I've used in the past 
> require considerable effort to get started, and to use. TIA.

Hmmm... big question. Let me see if I can give you a little piece of the
answer to start chewing on, and then you can figure out what pieces are
still missing.

First of all, I don't usually start with the code. Usually, I start with
the test. What do we want to do? How about a simple little class that
will wrap a string at some column width? The test seems simple enough:

<file name="tc_string_wrapper.rb">
require 'test/unit'

class TC_StringWrapper < Test::Unit::TestCase
	def test_wrap
		wrapper = StringWrapper.new
		assert_equal("This is a\nwrapped\nline.",
wrapper.wrap("This is a wrapped line.", 9), "The line should have been
wrapped to 9 columns")
	end
end
</file>

Things to note: first of all, you need to require 'test/unit'. Not only
does this get you the whole framework, it will also magically run your
tests for you when you give the file to the interpreter. Secondly, you
need a subclass of Test::Unit::TestCase to inherit all the framework
goodness. Third, you need an instance method within your TestCase that
starts with "test". Every such method will be run as an individual test
when the file is invoked. Finally, the real power is in the various
"assert" methods, such as the #assert_equal used here. To test
something, we assert that some statement is correct. If it isn't, we get
a big fat failure. If it is, then we know we're done.

OK, so now we have a test. Let's run it:

<run>
C:\projects-ruby\Sandbox>ruby tc_string_wrapper.rb
Loaded suite tc_string_wrapper
Started...
..
Error occurred in test_wrap(TC_StringWrapper): NameError: uninitialized
constant StringWrapper at TC
_StringWrapper
        tc_string_wrapper.rb:5:in `test_wrap'
        tc_string_wrapper.rb:4

Finished in 0.0 seconds.
1 runs, 0 assertions, 0 failures, 1 errors
</run>

Well, waddaya know, I didn't create StringWrapper yet. Notice that that
the framework caught the exception for me and gave me some nice
information about it. It's handy to not have an unexpected exception (is
that redundant?) bomb the interpreter and skip all the other tests.

This of course poses no real problem; here's something that will
eliminate the error (actually two of them; normally I'd probably slay
them one at a time, but I don't want this to drag on for too long):

<file name="string_wrapper.rb">
class StringWrapper
	def wrap(string, columns)
	end
end
</file>

Let me add the require to the test and see if I can get a real failure
now:

<file name="tc_string_wrapper.rb">
require 'test/unit'
require 'string_wrapper'

class TC_StringWrapper < Test::Unit::TestCase
	def test_wrap
		wrapper = StringWrapper.new
		assert_equal("This is a\nwrapped\nline.",
wrapper.wrap("This is a wrapped line.", 9), "The line should have been
wrapped to 9 columns")
	end
end
</file>

<run>
C:\projects-ruby\Sandbox>ruby tc_string_wrapper.rb
Loaded suite tc_string_wrapper
Started...
..
Failure occurred in test_wrap(TC_StringWrapper)
[tc_string_wrapper.rb:7]: The line should have been
wrapped to 9 columns. Expected <This is a
wrapped
line.> but was <nil>

Finished in 0.0 seconds.
1 runs, 1 assertions, 1 failures, 0 errors
</run>

Notice the helpful failure message. The string is not what was
expected... as a matter of fact, it's not even a string. This is a
possibility to make it pass:

<file name="string_wrapper.rb">
class StringWrapper
	def wrap(string, columns)
		string.scan(/(.{1,9}) /).join("\n")
	end
end
</file>

I have no earthly idea if that will work (really!), but the tests are
waiting to tell me:

<run>
C:\projects-ruby\Sandbox>ruby tc_string_wrapper.rb
Loaded suite tc_string_wrapper
Started...
..
Failure occurred in test_wrap(TC_StringWrapper)
[tc_string_wrapper.rb:7]: The line should have been
wrapped to 9 columns. Expected <This is a
wrapped
line.> but was <This is a
wrapped>

Finished in 0.0 seconds.
1 runs, 1 assertions, 1 failures, 0 errors
</run>

Oh, sorrow, oh tragedy, oh failure! I'm getting closer, but no
enchilada. No surprise either... I write my tests before I write my code
precisely because I'm not usually smart enough to get this stuff right
the first time. Maybe the second?:

<file name="string_wrapper.rb">
class StringWrapper
	def wrap(string, columns)
		string.scan(/(.{1,9})(?: |$)/).join("\n")
	end
end
</file>

<run>
C:\projects-ruby\Sandbox>ruby tc_string_wrapper.rb
Loaded suite tc_string_wrapper
Started...
..
Finished in 0.01 seconds.
1 runs, 1 assertions, 0 failures, 0 errors
</run>

Yippee! In testing nomenclature (although it doesn't quite map to the
console), I've got a green bar! All my tests pass. Of course, at this
point, they're trivial and have lots of holes, but that just means I
need more of them. If I were to continue, I'd keep adding things I
thought might fail, fixing them, and passing my tests. I'd repeat this
cycle until I was confident the method would stand up to my expectations
of it.

This is really a simple process... copying the information in to the
email took longer than writing and running both tests and code.

There's a lot more sugar in the framework (which you can read about at
http://testunit.talbott.ws/doc/), but I've shared the basics of what I
personally do with it. I could ramble on and on about testing (actually,
I already have: http://www.rubyconf.com/2001/talks/testinginreverse/),
but I don't want to overrun you with details. Let me know what questions
you still have, or if I've totally misinterpreted your original
question, and we'll go from there.

Others should feel free to correct me, chime in and/or make sense...


Nathaniel

<:((><
+ - -
| RoleModel Software, Inc.
| EQUIP VI

In This Thread