28 points · by steveklabnik · 15y ago · 8 comments
I'm not a fan of RSpec; however, I also find Steak just a little too minimalist for me.
Occasionally, I want very badly to be able to render my Scenarios to plain text for communication with customers and other developers. I need the individual steps for that as well.
Where the example here maintains the steps (eg., Given, when, and then) as comments, I prefer them in the code.
So I wrote Coulda (http://coulda.tiggerpalace.com/) a bit over a year ago. Yes, it uses Test::Unit. While I am in the minority, I still prefer Test::Unit. It scales well.
When I say that, I mean in the sense that I can write almost any test using just "assert" and then add an error message for when the assert fails. I don't limit myself to using solely "assert"; however, when I'm not sure how to write an assertion, and neither shoulda nor Test::Unit gives it to me, it's easy to build it using "assert" and then wrapping it in a method (making it a helper).
And I still find Test::Unit code readable enough. Maybe that's just a matter of taste.
Dare I add: RSpec, although cleaner with the release of RSpec 2.0, is still a very complicated swiss army knife. Miniunit, included in Ruby 1.9.1 but also available as a gem for older Ruby installs, is the basis for Test::Unit as Ruby moves forward. That is, Test::Unit inherits from Miniunit in Ruby 1.9.
And Miniunit is far far simpler than RSpec.
Update: I'll consider rolling a screencast of how I TDD w/ Coulda as a basis for comparison.
(I recommend embiggening the video player.)
https://github.com/ludicast/saki
It lets you write your specs with "smart contexts" so you can do stuff like:
with_existing :user do
that_has_an :article do
that_has_a :comment do
or with_existing :user do
on_visiting edit_user_path do
it { should let_me_edit(@user) }
end
end
I'm obviously biased, but I think this sort of testing kicks ass. I initially wrote them as extensions to Steak, but then ripped them out to use with vanilla rspec.This is why I tend to prefer the Given-When-Then style with reusable "macros" (class methods) that provide niceties such as "given_a :user", "when_i_visit root_path", etc.
Assuming that you are writing automated acceptance test, any test of more than trivial length would then be nested several levels deep.
1) I don't like the given/when/then syntax anymore (a personal thing, but I do see the advantages (Uncle Bob has a great article about it))
2) I don't mind the nesting as long as each context is making explicit what it does.
Of course it's a "different strokes" thing. I could see this not fitting in with everybody's style but for me it has DRYed up the parts of a test that should be DRY (imho).
Overall, I feel pretty good about this, but commentary is always welcome. I'm still getting used to the nooks and crannies of MongoMapper, but I felt that leaving some awkward parts in was better than pretending that everything always goes perfectly when you're doing test-first development.