I’m trying to spec a ‘binary’, and as previously discussed on this list, I’m trying to do it ‘from outside’ – i.e., by calling it with Kernel#` and observing the (side-)effects.
Unfortunately, this doesn’t really let me spec expectations about its internals. Let’s assume I have a -d flag and I parse it with Trollop to set Conf.debug: opts = Trollop::options do opt :debug, 'Print debug info', :default => false end Conf.debug = opts[:debug] To have a spec that actually expects this, I’d write something like this: it 'should set the debug option properly' do `binary -d` Conf.should_receive(:debug=).with true end This obviously doesn’t work, as the Kernel#` call is executed in a context that is not visible from the current Ruby interpreter. I assume that eval()-ing the binary (much like Rick Bradley does¹ for specing flog) would be the way to go, but then I don’t know how to pass the -d flag to Trollop. ¹ http://rubyhoedown2008.confreaks.com/11-rick-bradley-flog-test-new.html What would be the best practice in this case? Prepare ARGV for Trollop so that it believes we are calling the binary with the -d flag and then eval the binary, or run the binary with Kernel#`, pass it something that should generate debug output and then check whether the output was generated (rather than check whether the binary set Conf.debug)? -- Shot -- I've found that nurturing one's Zen nature is vital to dealing with technology. Violence is pretty damn useful too. -- Lionel Lauer, asr
pgp5iYhMx3BHS.pgp
Description: PGP signature
_______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users