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" output end end So you pass in a command as a string and the command runner: runs the command prints out the output fails if the return code is bad fails 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." Whic