Comments on: ruby unit test frameworks /2009/08/ruby-unit-test-frameworks/ Sarah Allen's reflections on internet software and other topics Sat, 23 Jul 2011 15:03:34 +0000 hourly 1 https://wordpress.org/?v=5.7.1 By: Taryn East /2009/08/ruby-unit-test-frameworks/#comment-612 Sat, 23 Jul 2011 15:03:34 +0000 /?p=1997#comment-612 YMMV, of course, but I use test::Unit over rspec because altering the output messaging is actually far easier.

Sure, for very simple tests like your examples – that use the default messaging, the output seems better. But if you want to pass custom failure messages, rspec requires you to declare a brand new class every time… whereas Test::Unit you can just pass it as a param.

This becomes more important in actual, complex tests. I have a lot of asserts that are sanity checks… and I like to make sure my code outputs *what* failed and what it should have been.. with a comment eg as a toy example:

should “approve a new widget” do
w = MyWidget.new(:name => “my widget”, :approved => false)
assert !w.approved?, “sanity check: test data should not have started out approved”
assert w.approve!, “approval process should have worked”
assert w.approved? # note – no need to comment this one as it’s the *actual* test
end

The last line is the actual thing you’re testing – but sanity checking the data and the intermediate steps is useful to make sure you are *actually testing what you think you’re testing* – something that you often only find out later when it breaks…
and having better output on the lines makes Test::unit far easier to get proper messages passed around as to what should be happening and why.

]]>
By: on choosing RSpec as a test framework | the evolving ultrasaurus /2009/08/ruby-unit-test-frameworks/#comment-610 Fri, 01 Apr 2011 14:42:24 +0000 /?p=1997#comment-610 […] I most value RSpec is in its clarity of output for a test failure, which I covered in detail in my earlier comparison. When I’m working on production code and a test fails, that is when I want to be most […]

]]>
By: Sarah /2009/08/ruby-unit-test-frameworks/#comment-609 Thu, 31 Mar 2011 22:48:33 +0000 /?p=1997#comment-609 I think we should teach using what is best for the student. As teachers, we need to use our best judgement in picking what collection of tools to introduce students to. This is not just a chocolate or strawberry kind of choice. I tried to explain in my post why I chose RSpec for teaching. As I mentioned, I actually started the experiment with a bias toward Test::Unit.

Right now minitest comes with Ruby and Test::Unit comes with Rails. Those projects pick their test frameworks for a lot of reasons — my guess is that being able to create very clear failing tests was not a high priority. In the case of Rails, RSpec didn’t exists when they chose Test::Unit and they are working on improving the readability of output (https://github.com/TwP/turn) but I still think it doesn’t approach the clarity of RSpec.

]]>
By: Paris Sinclair /2009/08/ruby-unit-test-frameworks/#comment-608 Thu, 31 Mar 2011 18:47:14 +0000 /?p=1997#comment-608 If it’s a matter a taste, and one of the options comes with Ruby, then that’s the obvious choice. Especially when teaching!

Since when is the canon just legacy?

If people want to switch to some other flavor they like, great! But they should be doing that based on real reasons they understand. It’s a major disservice to send them off with some Fav Flav. Even if it’s your fav flav.

]]>
By: Sam Livingston-Gray /2009/08/ruby-unit-test-frameworks/#comment-607 Thu, 31 Mar 2011 17:14:58 +0000 /?p=1997#comment-607 I’ve been using Shoulda in Rails for a couple of years, and I don’t really use its Rails-specific test methods (e.g., #should_belong_to). They’ve always seemed just a little too tautological for my taste — in that they don’t describe actual value. If there aren’t other tests that fail without a given association being declared, You’re Doing It Wrong ™.

That being said, I do like Shoulda’s nested contexts, if for no other reason than that they let me fold up large sections of tests that I don’t currently care about.

]]>
By: Scott Bronson /2009/08/ruby-unit-test-frameworks/#comment-606 Wed, 27 Jan 2010 09:01:28 +0000 /?p=1997#comment-606 Peter, I’m doing this in my current app to compare many deep structures: http://gist.github.com/287675

Not elegant but it works.

]]>
By: Peter Fitzgibbons /2009/08/ruby-unit-test-frameworks/#comment-605 Tue, 01 Sep 2009 21:32:58 +0000 /?p=1997#comment-605 You’ll find the same Rspec look/feel of code and output from within Rails.
There is one spot i notice that still falls apart, no matter the test framework : diffs of failing array/hash comparison. Anyone have a Rpec ‘plugin’ for this?

]]>
By: Jeremy D. Frens /2009/08/ruby-unit-test-frameworks/#comment-604 Tue, 01 Sep 2009 13:08:14 +0000 /?p=1997#comment-604 You can actually use Test::Unit in RSpec (http://blog.davidchelimsky.net/2009/2/2/rspec-works-with-test-unit/) and Shoulda has some special RSpec hooks as well. I’ve found this useful when incrementally transforming Test::Unit tests into RSpec examples.

]]>
By: Sarah /2009/08/ruby-unit-test-frameworks/#comment-603 Tue, 01 Sep 2009 03:55:03 +0000 /?p=1997#comment-603 If anyone wants to experiment with the files at home, I posted them on github: http://github.com/ultrasaurus/test-framework-comparison/tree/master

]]>
By: Sarah /2009/08/ruby-unit-test-frameworks/#comment-602 Tue, 01 Sep 2009 03:48:45 +0000 /?p=1997#comment-602 Wow. That’s a different dialect than I learned. Wikipedia notes that there are different consonants used in different dialects:

“In words that begin with vowel sounds or silent consonants, the syllable “ay” is added to the end of the word. In some dialects, to aid in pronunciation, an extra consonant is added to the beginning of the suffix; for instance, eagle could yield eagle’yay, eagle’way, or eagle’hay.”

http://en.wikipedia.org/wiki/Pig_Latin#Rules_and_variations

]]>