Skip to main content

RSpec and BDD - something crucial missing?

RSpec Site: "RSpec provides a framework for writing what we call executable specifications of program behaviour. Since that’s rather wordy, we usually just call them specs. Some other people call these things examples."

If I take a look at the examples on the RSpec site, I cannot help but wonder if just doing this (which they term "behaviour-driven development"), misses out on an important aspect of API documentation and the thought processes that should go into an API design. The missing element is explanation. In my experience, unless I force myself to explain my decisions to an audience (even a hypothetical one), I come up with too complex designs, inconsistent naming, and just generally too much hassle for the users of the API. Sometimes, complexity is warranted. But then, I believe it is important to justify it to your users. Show them why it's there.

The RSpec approach is, as I see it, simply a very concise way to write your tests twice: once in natural language, then in code. In the docs, they presumably cite the natural language version. Which is not checked at all. So I still much prefer the approach I took with JCite. Although I must say I like improved readability of RSpec's condition checking method names.

Comments

Anonymous said…
I agree with your philosophy and it is the ideal scenario.
At the same time nothing prevents you from creating a "true" unit test with RSpec though.

I have been in software devt for many years now and I see that even after all the diktats and goading programmers cut corners on writing tests. It's like encouraging teenagers to embrace chastity: you just don't get high compliance and it is very hard to enforce it. The "pushback" always is that there are too many tests to write. Which is true; you really need to write much more test code than production code if you want to cover all the permutations of possible failure; many experts say 2:1 ratio is more like it. All the additional Test writing has a dollar cost associated with it and it is not lost on the money-watchers.

So it comes down to this - if you have to deal with the realistic scenario where fewer that ideal tests are written, which ones are the most crucial (the 'must not miss' variety)? The answer is the ones that ensure meeting the customer's request most directly. So there BDD is a great help.

And like I said, you can still use an RSpec like tool to go the extra distance to explain your logic to the user if you wish.

Popular posts from this blog

Threaded chat article and demo

While nothing major, managing threaded conversations in chat has bothered me for quite a while. Yesterday I had an idea on how to improve matters: Works using existing chat infrastructure. Needs only augmented clients. Plays well even if other party uses a non-thread aware chat tool. Separates threads automatically based on interaction patterns. I've written an article and have created an online demo about it. Discussion welcome.

Access 2003 and the DCOM Server Process Launcher

Here's a hint: Don't disable the "DCOM Server Process Launcher" service on XP SP2. It may look like one heck of a vulnerability when you really don't use DCOM at all, but, unfortunately, Microsoft Access 2003 does. It will simply open an instant message box stating "A problem occurred while Microsoft Access was communicating with the OLE server or ActiveX Control." if the service is not running.

Google trumps Flock (well, at least for me)!

As I posted earlier, I had this idea about bookmarks that are searchable using Google . Well, they've implemented it if you have personalised search enabled. There is a new link at the bottom to a bookmarklet for easily adding a bookmark within your Google account. Like del.icio.us, but searchable with Google. Cool! (I did, by the way, tell Google about this idea. I'd love to know if that had an influence...) What's not so cool is that they still want me to enter some information (labels etc.) when adding a bookmark. That really sucks. I don't want to categorize. That's the whole point when I am able to search through my bookmarks' contents. Maybe I'll manage to create a bookmarklet that adds a bookmark straight away.