Ben Giddings
2/16/2005 3:08:00 PM
On Feb 16, 2005, at 09:39, Francis Hwang wrote:
> To use it in live code, you call get methods on the FileSystem module:
>
> FileSystem.get_dir => Dir
> FileSystem.get_file => File
> FileSystem.get_file_utils => FileUtils
> FileSystem.get_dir.entries( '.' ) => [ '.', '..', 'file1', ... ]
>
> (I'm thinking about adding a voodoo.rb file that actually re-assigns
> the constants Dir, File, and FileUtils, though I suspect this will not
> be that usable in many cases.)
>
> Then, to mock out that activity for a test code, simply call
> FileSystem.mock= :
>
> FileSystem.mock = true
> FileSystem.get_dir => FileSystem::DirAdapter
> FileSystem.get_file => FileSystem::FileAdapter
> FileSystem.get_file_utils => FileSystem::FileUtilsAdapter
> FileSystem.get_dir.entries( '.' ) => [ '.', '..', ... ]
Hi Francis,
I like the idea, and the idea of mocking out things like filesystems is
very important. Just a few comments on the naming of things:
If the class is mainly just a test construct and/or a proxy for actual
Filesystem calls, maybe "Test" or "Proxy" should be part of the class
name. Secondly, method names that start with "get_" seem pretty
un-rubyish. They feel more like Java getFoo() and setFoo() type
functions. Maybe it would make sense to rename them just dir, file,
file_utils and dir_entries?
Ben
P.S. If you ever decide to mock out a human being, let me know. This
morning in the shower I was wondering how I can mock out the person who
has to push a button on an embedded device I'm working on. Sure, I can
easily mock out the register that pushing the button supposedly
changes, but that kinda defeats the purpose of the test.