On 13 Apr 2011, at 02:48, Nicholas W. wrote:
Hi *, the class I need to test is:
gist:49ef28014bb648ffa63e · GitHub
I know my question is very generic, but I honestly fail to see how to test
something that is so strictly procedural and so dependent to the
platform/libraries.
Should I mock/stub filesystem, services and pretty much everything that is in
there and test how it responds to different inputs, or adopt an “integration
style” ?
How would you proceed in this case ? (you can refer to RSpec book and point to
parts that are relevant).
ngw
It depends on what you’re worried about breaking. It looks to me like
the unpack method is the most likely one to go wrong, and the most
likely one to grow with more cases, so I’d focus my effort on that.
You have about three distinct responsibilities going on in this class -
there’s something which sets up a directory structure, something which
fetches zip files from S3, and something which unpacks a zip file into a
folder structure. If you encapsulated what’s going on in #sandbox into a
Target or Destination or Sandbox class, with methods like
write_stylesheet and and write_image, you could mock out that object
easily. Similarly if you create a wrapper object around the
responsibility of calling S3, you’d be able to test your unpack method
with some fixture zip files from your test suite. The Sandbox and
S3Fetcher classes will be pretty simple and unlikely to break, so you
might not need to test them at all, other than with a quick manual
integration test.
Depending on how mission critical this code is, you might want a simple
integration test to check it all wires up, but that depends on you
appetite for risk, how often this code will change, and where that
change happens. If all you do is add more cases to the unpack method,
you’re going to be safe testing those changes with specs and running a
quick manual test.
http://rubyforge.org/mailman/listinfo/rspec-users
cheers,
Matt
–
Freelance programmer & coach
Founder, http://relishapp.com
+44(0)7974430184 | http://twitter.com/mattwynne