RSpec adding to the confusion?
Posted by James Mead Tue, 02 Jan 2007 17:39:00 GMT
Update:
I’ve just read Aslak’s article again in the cold light of day. I now realise I have put words in his mouth, for which I apologise.
I posted the article late at night after being annoyed by the line on the caboose blog. In hindsight, I should have waited until morning and read it through again (and then not posted it in it’s current form).
Original Article:
In a recent article Aslak Hellesoy seemed to imply one of the differences between RSpec and Test::Unit was that RSpec you could do interaction-based testing using Mock Objects. I don’t think this implication was intentional, but this lack of clarity isn’t helpful to those just getting to grips with automated testing.
As I’m sure Aslak will acknowledge, interaction-based testing has been around a lot longer than RSpec and BDD. Most Ruby mocking frameworks (e.g. FlexMock, Mocha) were originally designed to work with Test::Unit. And as Nat Pryce recently explained ,”Mock Objects is a Technique Not a Technology”.
There is a similarly confusing statement in a recent post from courtenay (of the caboose).
The counter-intuitive thing for you test::unit types is that you set up the expectations before calling the method.
...thus perpetuating the myth that you can’t do interaction-based testing without RSpec.
Today, Martin Fowler published an update to his excellent article “Mocks Aren’t Stubs”. I think he has added clarity by breaking
the old dichotomy of state based testing and interaction based testing into the state/behavior verification dichotomy and the classical/mockist TDD dichotomy.
However, I fear people might incorrectly associate “behavior verification” with BDD.
In a comment on Aslak’s article, David Chelimsky comments that
It helps at the very least by promoting this very conversation. How does it hurt?
I don’t think it hurts to have a debate (about whether BDD is more usefu than TDD), but we should avoid sowing confusion about what makes BDD different from TDD.
Aslak talks about the “BDD buzzword”. Quoting from Wikipedia...
Buzzwords are typically intended to impress one’s audience with the pretense of knowledge. For this reason, they are often universal. They typically make sentences difficult to dispute, on account of their cloudy meaning.
I vote for more clarity and less cloudy meaning.

I’ve used Mocha and it’s a very nice library. One thing that really confuses me is how you appear to be insulted whenever someone posts about RSpec without mentioning Mocha.
I don’t see how Aslak implies that you can’t use mock objects with Test::Unit. In fact, the second part of his article essentially says you can’t do BDD without mock objects. He doesn’t say that RSpec is better than Test::Unit with mock objects.
Like I said, Mocha is very good, but I really don’t think that every single person who writes about RSpec needs to add the disclaimer “btw, you can use Mocha as a mock object framework for Test::Unit”
Test::Unit sucks and you couldn’t possibly use mock objects with it. :)
I vote for more clarity and less cloudy meaning.
I agree. I’m warn out by the BDD debate. Even with Test::Unit I’ve always tested workflows, not API methods (or worse… private methods). Of course every pattern or methodology has exceptions and edge cases.
Pat: I’m glad you like Mocha. I have no problem with people mentioning RSpec and not mentioning Mocha. I’d just prefer it if people didn’t give the impression that you can only do mocking with RSpec.
As a more serious reply.. I think the debate is misguided. As I’ve been seeing over at my blog, nobody’s code is good enough for us to spend time on this discussion. We need to be talking about how to make our code better, not about the subtleties of meaning in a couple of TLAs.
You’re putting words in my mouth. Please help me understand how you have concluded that:
Aslak Hellesoy seemed to imply one of the differences between RSpec and Test::Unit was that RSpec you could do interaction-based testing using Mock Objects.
And what’s with this:
As I’m sure Aslak will acknowledge, interaction-based testing has been around a lot longer than RSpec and BDD.
I never said anything that suggests otherwise. It gets better:
perpetuating the myth that you can’t do interaction-based testing without RSpec.
What myth are you talking about?? You just invented that.
Aslak:
I’ve just read your article again in the cold light of day. I think you’re right – I have put words in your mouth, for which I apologise.
I posted the article late at night after being annoyed by the line on the caboose blog. In hindsight, I should have waited until morning and read it through again (and then not posted it in it’s current form). I’ll post an update to the article to explain.
I do still think there is ambiguity when you describe what techniques are used in BDD – if you are not explicit people are likely to assume they are things that are not used or possible in TDD.
I agree that we need more clarity. Part of the problem here is that RSpec is the first attempt (that I’m aware of) at a BDD tool in ruby, but it really isn’t all that BDD-ish yet. But, since we call it a BDD tool, people seem to think that “I’m using RSpec so I must be doing BDD”. We should definitely work towards clearing the air on that. And we will….
Wilson: I wholeheartedly agree. Thanks for your sensible comment. Suggesting improvements to example code is always better than pontificating about abstract concepts. I’ll try and stick to the former from now on.
David: I agree with you, but I think there is the same problem with people using Test::Unit and thinking they’re doing TDD.