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.
-
Compute the total size of a directory and its contents (bash script
uses
“du” for this) -
Make a clean copy of a directory and its contents, removing any
version
control directories (.svn, .git) -
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. -
Get a list of files matching a given pattern on a remote server
(using
ssh). -
Copy a file up to a remote server (using scp).
-
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