[rspec-users] First steps with RSpec on Rails

Tobias Grimm listaccount at e-tobi.net
Thu Jan 11 19:46:15 EST 2007


If anyone is interested, these are my first tiny steps with RSpec on Rails:


The "ctvdrwebadmin" application should become a web administration tool
for a Debian based distribution that is specialized to VDR [1] - the
Linux video disc recoder by Klaus Schmidinger.  It shall provide an
interface for the installation / uninstallation of software packages,
configuration handling and several status information. It doesn't use a
database - instead it reads data from the file system or grabs it from
the OS and other external tools. For now this is still in the "proof of
concept" phase, giving me the opportunity to play around with Rails and

"ctvdrwebadmin" is tightly coupled to Debian and has a German-only UI,
so most of you probably won't be able to run it. But the interesting
part is the source code, especially the specifications - all English of

Any suggestions for improvements are welcome! I still have a problem
with finding the "right" phrases for specifications, so especially on
this topic any feedback is welcome.

The most interesting part of the application in it's current state
probably is the channel editor. One of the use cases of the channel
editor is, that it should be possible to rearrange the order of
channels. With plain old http get/post this quickly becomes a usability
nightmare, so I decided to throw in some Ajax/JavaScript to implement a
nice drag 'n drop UI for rearranging the list of channels. With
sortable_element() and Rails this was much easier than I initially
thought. It just became a little bit more tricky, when I realized, that
with 1000 channels the Javascripts became damn slow. And several hundred
channels (TV and radio) are not unusual when you use DVB-S. So I needed
to paginate the list of channels. This required a little bit more Ajax.
And because I now needed a way to move a channel from the last page to
the first, I decided to introduce a clipboard where the user can
temporarily store channels when switching between pages.

So finally I had this: Two lists where the user can drag 'n drop
channels within and between the lists. The clipboard list is static, the
channel list is paginated. Each time the user moves a channel, an Ajax
request triggers the rearrangement in the underlying controller.

And these are the specifications for this controller:


Some of the things that still puzzle me there:

spec "should result in an empty clipboard when pulling the last channel
to the order list" - when a channel is moved from the clipboard to the
list, two Ajax requests are triggered. One that passes the new list of
items in the clipboard and one with the items in the channel list. For
this specification I'm only interested in the request from the
clipboard. The question is, if I then can skip the request from the
channel list? In a real use of the application both events always occur
together, when dragging between the two lists. Or should I just rename
the specification to  "should result in an empty clipboard when removing
the last channel from it" and skip the request from the channel list?
(But what if I had a bug in the code that handles the requests from the
channel list?)

What about the contexts? Should I split them into more contexts? Or
should I merge some? The first two contexts only have one specification.
They could easily be merged, but the setup of the second context is a
little bit more complex which is not needed to perform the specification
in the first context.

So far I think that doing it the RSpec-way gave me a little bit more
freedom to evolve the implementation and the overall design than doing
it with "plain old" unit tests. But on the other hand I have the
feeling, that the specifications don't test the code as deeply as unit
test would have done. But that's only a vague feeling at the moment.



PS: David - I followed your suggestion and moved the "logged-in"-code to
a set_logged_in method, which I simply put into spec_helper.rb, so I
don't need to explicitly include a helper module. Thanks!

[1]: http://www.cadsoft.de/vdr/

More information about the rspec-users mailing list