Showing posts from November, 2007

Mocking Backticks and Other Kernel Methods

There's a bunch of places in our build where we need to execute a system command (such as running sqlplus) but often times we've found that the command fails and our build happily churns away. It's pretty easy to check the result of system command with $?.success? but we have to remember to do that everywhere... So that means it's time to extract a method. Here's what Kurtis and I came up with:

module DatabaseHelper
def self.command_runner(command)
output = `#{command}`
puts output
fail unless $?.success?
fail if output.include? "ERROR"

So you pass in a command as a string and the command runner:
runs the commandprints out the outputfails if the return code is badfails if the output includes "ERROR" (useful when running database imports with sqlplus)and returns the output just to be a good citizen
So that's cool but when I started to write the module I thought "Hey, I can test this." Which is a cool side eff…