I’d like to write some Cucumber features for a command-line app I’m
on (specifically, http://github.com/jcoglan/claw). The app runs a
loop taking user input, and uses this input to search for and open files
running shell commands (grep, gedit, firefox etc.). Right now it’s using
#puts and the backtick (`) method for output and shell commands, and I’m
sure how to go about testing the app’s output. Do I mock Kernel#puts,
I give the app an IO object to write output to so I can collect it, or
soemthing else entirely?
If anyone has advice about how to structure this I’d be most grateful.
I’d like to write some Cucumber features
for a command-line app I’m working on [â€¦]
Do I mock Kernel#puts, should I give the app an IO object to
write output to so I can collect it, or soemthing else entirely?
When I was faced with the same problem (albeit with RSpec rather than
Cucumber, but I doubt it matters here) I ended up with a very thin
wrapper (which I donâ€™t test) that simply calls Executable.new.run and
then test the Executable with hand-crafted params and StringIOs:
As you can see, Executable#initializeâ€™s param defaults to ARGV and
the spec redirects $stderr to a StringIO object to inspect it for the
The same with my other command line
app, this time with input and output:
Executable#runâ€™s params default to $stdout and $stdin, but the spec uses
StringIOs in their place to be able to â€˜read fromâ€™ and â€˜write toâ€™ the