On Wed, Jun 4, 2008 at 12:58 AM, Luke Kanies <[EMAIL PROTECTED]> wrote: > It's really tough to test the executables as they're written, because > there's a lot of code in a file that's supposed to be exec'ed, rather > than loaded like a library. > > If you look in master, you'll see that I've started to pull a lot more > code out of the executables (e.g., look at puppetca), but I haven't > done all of them. > > In general, I'd say that you should refactor what you can, test > whatever else you can that's left, and then, um, do your best to make > sure it works.
I agree 100% with Luke on this. I've been spec'ing executables recently in other areas, and the basic strategy comes down to "get almost everything out of the executable, then spec what's left". It's much easier to do it spec-first, of course, but if the code's already there, it's still possible. I've got at least one example publicly visible that might be helpful for you. I've written partial specs for the 'flog' binary in Ryan Davis' flog project (because I need it plus functionality it doesn't have, and it was written with no tests(!)), and that code is on github. You can find the current executable here: http://github.com/flogic/flame/tree/master/bin/flog and you can find its current specs here: http://github.com/flogic/flame/tree/master/spec/flog_command_spec.rb The key bit is the helper method run_command() which looks like: def run_command eval File.read(File.join(File.dirname(__FILE__), *%w[.. bin flog])) end This works for simple commands, but, as Luke indicated, the puppet executables might not be simple enough to be tested that way. If so, the application of tests should start to apply pressure to the executables, forcing the tough bits down into other classes and making the executables simpler wrappers (really just interfaces to the pure-Ruby class world of puppet and the non-Ruby world of Unix executable scripts). Best, Rick --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en -~----------~----~----~----~------~----~------~--~---
