From: Francis Hwang Date: 2005-02-17T04:52:41+09:00 Subject: Re: [ANN] FileSystem 0.1.0: Beta for me, Alpha for you On Feb 16, 2005, at 11:25 AM, Alexander Kellett wrote: > does it already, or would it be possible, for this to act as an > overlay file system? > as in, in a test, i can create a number of virtual files, any lookups > on real files > succeed - thusly meaning that e.g loading of new libraries doesn't > screw up ;) - but > any access to the virtual directories / files would return pseudo > objects. > > whats the feasibility of this? it would vastly simplify many testcases > i imagine. Maybe this is what you're talking about: At Rhizome, we send out lots of customized emails, with templates. So maybe you'll have a template file in /var/www/includes/email/welcome.tmpl . But if you want to play around with the codebase on, say, another server, this is annoying, because then you'd have to build up that directory path just to put one file in it. So instead, I save a representative copy of that template somewhere in the test code directory, say test/test_data/email. Then, if we've got an email class that uses that template: class WelcomeEmail < RhizMail::SimpleTemplateMessage def initialize( user ) template = FileSystem.get_file.open( '/var/www/includes/email/welcome.tmpl' ) { |f| f.gets nil } super( template ) end end the setup for the test code might look like this: class TestWelcomeEmail < Test::Unit::TestCase def setup FileSystem.mock = true contents = File.open( 'test/test_data/email/welcome.tmpl' ) { |f| f.gets nil } FileSystem.mock_file_system.fill_path( '/var/www/includes/email' ) FileSystem.get_file.open( '/var/www/includes/email/welcome.tmpl', File::CREAT | File::WRONLY ) { |f| f << contents } end end So that when the WelcomeEmail#initialize reads the contents of /var/www/includes/email/welcome.tmpl, it's actually reading contents from the virtual file system that was set up in your test case. Is that what you had in mind? Francis Hwang http://fhwang.net/