From: Randy Coulman Date: 2012-02-23T00:54:41+09:00 Subject: How would you test these? --001636c92c1c93f8a904b98f8b37 Content-Type: text/plain; charset=ISO-8859-1 I'm relatively new to Ruby, but learning fast. As an exercise, I'm porting a family of untested bash scripts to Ruby, and I'm running into some things that I'm not sure how best to test. I know how to write the code, but I want to be able to write it test-first, and I'm not sure of the best way to test it. I'm using minitest, if that makes a difference. 1. Compute the total size of a directory and its contents (bash script uses "du" for this) 2. Make a clean copy of a directory and its contents, removing any version control directories (.svn, .git) 3. Shell out to run a few commands using fakeroot. Bonus points if there's a way to test that the commands have the desired effects. 4. Get a list of files matching a given pattern on a remote server (using ssh). 5. Copy a file up to a remote server (using scp). 6. Run a script on a remote server (again, ssh). I know I could write some mock-heavy tests here to make sure my program is running the right shell commands and such, but that doesn't seem to fully test that the program does what I want. How would you approach writing tests for scenarios like these? Thanks, Randy -- Randy Coulman rcoulman@gmail.com Twitter: @randycoulman --001636c92c1c93f8a904b98f8b37 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I'm relatively new to Ruby, but learning fast. =A0As an exercise, I'= ;m porting a family of untested bash scripts to Ruby, and I'm running i= nto some things that I'm not sure how best to test.

I know how to write the code, but I want to be able to write it test-first,= and I'm not sure of the best way to test it.

I'= m using minitest, if that makes a difference.

1. Compute the total size of a directory and its contents (bash script uses= "du" for this)

2. Make a clean copy of = a directory and its contents, removing any version control directories (.sv= n, .git)

3. Shell out to run a few commands using fakeroot. =A0B= onus points if there's a way to test that the commands have the desired= effects.

4. Get a list of files matching a given = pattern on a remote server (using ssh).

5. Copy a file up to a remote server (using scp).
=

6. Run a script on a remote server (again, ssh).

I know I could write some mock-heavy tests h= ere to make sure my program is running the right shell commands and such, b= ut that doesn't seem to fully test that the program does what I want.

How would you approach writing tests for scenarios like= these?

Thanks,
Randy=A0=A0
--
= Randy Coulman
rc= oulman@gmail.com
Twitter: @randycoulman

--001636c92c1c93f8a904b98f8b37--