On Wed, 14 Jan 2004 13:04:24 +0900, Mike Williams wrote:
[snip] 
>     class Link 
>         def initialize(url, content)
>             @url = url
>             @content = content
>         end
>         attr_accessor :url, :content, :link, :target
>     end
> 
>     link = Link.new(url, "here")
>     link.title = "the whole story"
 

I usually wrap my class hierarchy inside a module.
And make another module through which I can build instances, so
that its easy to up a testcase with an expected structure.

For instance the builder code looks like this:

module AbstractSyntaxFactory  
	def mk_file(name)
		AbstractSyntax::File.new(name)
	end
	def mk_directory(name, *files)
		AbstractSyntax::Directory.new(name, files)
	end
	def mk_link(name, *long_names)
		AbstractSyntax::Link.new(name, long_names)
	end
	def mk_hierarchy(root_dir, *shortcuts)
		AbstractSyntax::Hierarchy.new(root_dir, shortcuts)
	end
end 



Then in the testclass I can include AbstractSyntaxFactory
and easily invoke the 'mk_<type>' methods.

Like this:

class TestLookup < Test::Unit::TestCase
	include AbstractSyntaxFactory
	def build_hierarchy
		@image_dir0 = mk_directory("images_anno_2000", 
			@img00 = mk_file("ruby-logo.svg"),
			@img01 = mk_file("rite-logo.png"),
			@img02 = mk_file("ros presentation.avi")
		)
		@image_dir1 = mk_directory("images_anno_2001", 
			@img10 = mk_file("baker.dia"),
			@img11 = mk_file("pickaxe.thumbnail.gif")
		)
	...


Its rarely that I invoke Class.new directly.
Is this what you are seeking?

--
Simon Strandgaard