|
|
|
|
|
by danso
4843 days ago
|
|
I was a little disappointed in this article. What I've always wanted to know is: Why do Rails developers use Rspec when they can use MiniTest::Spec? I was hoping the OP would address that, since MiniTest is the default Ruby testing suite he refers to. Do Rails devs continue to use Rspec because it's what they're used to? Or is Rspec a dependency for other testing tools and libraries? I don't agree at all with this premise by the OP: > Just from skimming over the tests, it’s obvious that Rspec is more readable. The Rspec DSL was designed for us humans to be able to understand what is happening at a glance. This is where Rspec gets my vote. Unfortunately, we aren’t talking about reading or sharing tests. We are talking about writing tests, and this is where Rspec has a heafty learning curve. I think the MiniTest::Spec API is both easy to read and write...(I'm assuming the OP is criticizing both Rspec and MiniTest::Spec here). I'm just saying this from personal experience, as I learned both the Spec and standard testing syntax at the same time. |
|
At a high level, I would say that Rspec is just much more thought out. The other libraries all seem to be written by someone who looked at Rspec and though "Ugh, this is too much. I just need X."
But I find, if I'm doing serious TDD, I'm gonna need pretty all of Rspec. And what happens is that the other libs just don't integrate that well.
For example, you may be using one test runner (minitest) with a mock from some other library (mocha) and assertions from a third (test::unit). The question is: are those things all meant to work well together? Are your mocks scoped correctly within your test runner? Is your database cleaner working properly with your before and after hooks?
The answer is sometimes "no". But with Rspec, everything works well together. It just fits. Generally I'm a big fan of focused libraries, loosely coupled. But the state of things with testing is that I don't think we've yet found that good loose coupling.
The second issue is that Rspec just seems to have much richer assertions. I can do things like:
Or: And mocking is also underdeveloped in other libs. Mocha, for example, can't stub constants. In Rspec I can do: Or And it works great. I find I can easily stub out parts of ActiveRecord and write good targetted unit tests. With Mocha I find myself using any_instance all the time because I can't target things on the structure I really want to target them to.Some of these are available in other expectation libraries, but I've found Rspec to have a really nice, comprehensive set of them.
All in all, I just feel like David Chelimsky and the Rspec folks have really thought about testing in a way the other libs' authors haven't. I keep learning things about TDD and finding out that Rspec has already considered them. With other libs the opposite often seems true.