BTW, the tmpfs method has the added advantage of failing if you have any
file handles still open at the end of your test (as umount will fail).
Conversely, one test in which umount fails will probably cause all the
subsequent tests to fail.
···
-----Original Message-----
From: Daniel Sheppard
Sent: Tuesday, 20 September 2005 4:34 PM
To: ruby-talk ML
Subject: Re: MockFS 0.1.2
Except for the fact that you can pretend you're talking to the entirety
of the filesystem from the root directory, is there much use for this
that wouldn't be met by running:
mount -t tmpfs tmpfs /somewhere
ie. your unit test would be something like:
require 'test/unit'
def move_log
File.rename('/somewhere/var/log/httpd/access_log','/somewhere/home/franc
is/logs/access_log')
end
class TestMoveLog < Test::Unit::TestCase
def test_move_log
assert(system("mount -t tmpfs tmpfs /somewhere"))
begin
require 'pathname'
Pathname.new('/somewhere/var/log/httpd/').mkpath
Pathname.new( '/somewhere/home/francis/logs/').mkpath
File.open('/somewhere/var/log/httpd/access_log', "a") do |f|
f.puts "line 1 of the access log"
end
move_log
assert( File.exist?( '/somewhere/home/francis/logs/access_log' )
)
assert( !File.exist?( '/somewhere/var/log/httpd/access_log' ) )
contents = File.open( '/somewhere/home/francis/logs/access_log'
) do |f|
f.gets( nil )
end
assert_equal( "line 1 of the access log\n", contents )
ensure
assert(system("umount /somewhere"))
end
end
end
Or am I not understanding the project properly?
-----Original Message-----
From: Francis Hwang [mailto:sera@fhwang.net]
Sent: Tuesday, 20 September 2005 12:27 PM
To: ruby-talk ML
Subject: ANN: MockFS 0.1.2
Hi everyone,
MockFS lumbers forward with its newest release, 0.1.2. Besides a liberal
heaping of bugfixes, this version adds override.rb, which does some
convenient but possibly dangerous redefining of global constants and
methods. Ooh, danger!
http://rubyforge.org/projects/mockfs/
== What's MockFS?
MockFS is nothing less than an attempt to simulate a file system in
memory for the purposes of testing. I wrote it for my own use, because I
write lots of tests and sometimes I get sick of cleaning up test files.
It's a lot simpler to just simulate the disk in memory and drop the
whole thing when you're done with your test.
It's not complete by a longshot, but it's complete enough that I'm able
to use it to help me write tests for production code--most notably, for
Rhizome.org, a community website that gets more than a million pageviews
a month.
== What's new in 0.1.2?
* First, a lot of little things have been fixed. MockFS now has a better
understanding of file permissions, of paths, and the multiple ways that
File, FileUtils, and Dir allow the same method to be called through
class or instance methods.
* I've also added override.rb, which redefines File, FileUtils, and Dir.
This is so your code doesn't have to reference MockFS directly; the test
cases can include override.rb and reference the mock file system that
way.
override.rb also includes a redefinition of Kernel.require, so that if a
file doesn't exist in the real file system, Kernel.require will look for
it in the mock file system. This might be useful in cases where you have
configuration files written in Ruby, and would like to swap them out
during testing.
Pretty much everything in override.rb is experimental, so I'd urge
caution in including the file.
== Help me make this useful for you
I'm putting this out in the hopes that it will be useful right now to
others, but also as a way of soliciting specific bug reports. I don't
expect to fill in the entire necessary functionality overnight, but if
people submit targeted bug reports about specific cases and methods, I
can fill those in first.
Thanks,
Francis
########################################################################
#############
This email has been scanned by MailMarshal, an email content filter.
########################################################################
#############
#####################################################################################
This email has been scanned by MailMarshal, an email content filter.
#####################################################################################