[rspec-users] How to spec a (Trollop-based) binary’s internal state?
Shot (Piotr Szotkowski)
shot at hot.pl
Fri Nov 7 08:05:51 EST 2008
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
opts = Trollop::options do
opt :debug, 'Print debug info', :default => false
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
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.
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)?
I've found that nurturing one's Zen nature is vital to dealing with
technology. Violence is pretty damn useful too. -- Lionel Lauer, asr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 191 bytes
Desc: not available
More information about the rspec-users