[rspec-users] RSpecing a ‘binary’

1 view
Skip to first unread message

Shot (Piotr Szotkowski)

unread,
Oct 25, 2008, 3:08:12 AM10/25/08
to rspec-users
Hello, good folk of rspec-users.

I’m writing my first Ruby ‘binary’ (i.e., a script meant to be used
as a standalone system command) and I’m wondering how to RSpec it.

(Caveat: With all of my other code I almost alwyas do BDD, but as this
was my first ‘binary’ and these were my first Trollop steps, I ended up
writing the code first.)

‘From inside’? This means turning most of the script into one (or few)
callable method(s) and then testing them; the idea of accomodating the
code to be easier to test seems to miss the point, though.

‘From outside’ (i.e., run it with Kernel#` and observe output and
side-effects)? This feels more like behaviour testing, and I’m leaning
towards it, but I have a gut feeling there might be another choice that
I’m missing…

-- Shot
--
Exchange actually reports two different INTERNALDATEs for the exact
same message when queried at different points in time. [...] Of course
no OTHER imap server I've encountered returns DIFFERENT values for
the SAME message. But it's Microsoft; what do you expect? If their
programmers were any good they'd be working at Google. -- sup/imap.rb

Ashley Moran

unread,
Oct 25, 2008, 7:28:11 AM10/25/08
to rspec-users

On Oct 25, 2008, at 8:08 am, Shot (Piotr Szotkowski) wrote:

> ‘From outside’ (i.e., run it with Kernel#` and observe output and
> side-effects)? This feels more like behaviour testing, and I’m leaning
> towards it, but I have a gut feeling there might be another choice
> that
> I’m missing…


Hi Shot

When I've written command-line tools, I've done exactly this. Use
Dir.tmpdir to give you a working space to hold any input/output files,
and call it with Kernel#` to capture its STDOUT.

Doing it this way proves your binary command works, because RSpec (or
Cucumber, which may be more appropriate here) is doing nothing you
can't do in a shell yourself.

Ashley

--
http://www.patchspace.co.uk/
http://aviewfromafar.net/

_______________________________________________
rspec-users mailing list
rspec...@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Shot (Piotr Szotkowski)

unread,
Nov 1, 2008, 5:49:18 PM11/1/08
to rspec-users
Ashley Moran:

> When I've written command-line tools, I've done exactly this. Use
> Dir.tmpdir to give you a working space to hold any input/output files,
> and call it with Kernel#` to capture its STDOUT.

Thanks a lot, Ashley! This is what I’m going to do, then. :)

I’ve just finished watching Rick Bradley’s ‘flog << Test.new’
presentation¹ from Ruby Hoedown 2008, and the first part (past
the introduction) is about how he RSpeced the flog binary – also
most informative!

¹ http://rubyhoedown2008.confreaks.com/11-rick-bradley-flog-test-new.html

-- Shot
--
I've been almost exclusively hand-coding my JavaScript these
past 4 or 5 months, and I've come to the conclusion that this
experience has permanently altered my neurochemistry in some
strange, pseudo-Stockholm Syndrome kind of way. -- Amy Hoy

Reply all
Reply to author
Forward
0 new messages