[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Testing file system manipulations

Chris Vincent

1/29/2009 8:38:00 PM

I am currently writing a class which processes a log file, inserts some
data into the database, and then rotates the log file. I am doing
test-driven development and I was curious as to the best practices for
testing classes which manipulate the file system.

Rails tests have a transactional feature for testing database
manipulation such that changes made to the DB are reset after each test.
I was wondering if there was anything like this for the file system. It
would be great if the test could automatically reverse any file system
changes made during a test; I could imagine doing this via proxying
access to the File, FileUtils, and Dir classes. Has anything like this
been done? Or is there a better approach altogether?

For the record, I'm using Shoulda.
--
Posted via http://www.ruby-....

2 Answers

Andrew Timberlake

1/31/2009 1:19:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Thu, Jan 29, 2009 at 10:37 PM, Chris Vincent <c.j.vincent@gmail.com>wrote:

> I am currently writing a class which processes a log file, inserts some
> data into the database, and then rotates the log file. I am doing
> test-driven development and I was curious as to the best practices for
> testing classes which manipulate the file system.
>
> Rails tests have a transactional feature for testing database
> manipulation such that changes made to the DB are reset after each test.
> I was wondering if there was anything like this for the file system. It
> would be great if the test could automatically reverse any file system
> changes made during a test; I could imagine doing this via proxying
> access to the File, FileUtils, and Dir classes. Has anything like this
> been done? Or is there a better approach altogether?
>
> For the record, I'm using Shoulda.
> --
> Posted via http://www.ruby-....
>
>
You should use mock objects in place of file operations.
If you're using mocha, you can do things like

File.expects(:delete).with(file_name)
File.delete(file_name)

--
Andrew Timberlake
http://ramblingso...
http://www.linkedin.com/in/andrew...

"I have never let my schooling interfere with my education" - Mark Twain

James Mead

1/31/2009 1:33:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

You can find Mocha here: http://mocha.ruby...
--
James.
http://blog.floe...