one more thing

| | Comments (4)

While I'm on the topic...

assert_nothing_raised and assert_nothing_thrown are the two most useless assertions on the planet. If they have spec equivalents, add those to the list as well.

I had a student litter those everywhere and I told him not to use it. He said he was just trying to be "explicit". You're writing a test already, you're already being explicit. By virtue of running code in the first place you're asserting that it doesn't throw anything unexpected.

Why does anyone use it? Is it just to up the assertion count?

I think I'm going to deprecate them from the assertion library unless someone can show me a compelling reason not to.

4 Comments

Isn't thrown in Ruby like goto and completely useless and confusing? I never understood it.

Assuming when something is raised, it's equally easy to track down with or without assertnothingraised statements, I don't see the need. Maybe it's just to add "balance" to much more useful assert_raised?

Wouldn't it be appropriate to use one of these if you had code that had to catch any exception raised by something it ran or called? Say, for instance, you are writing a new test framework, and want to make sure that errors thrown by test methods don't crash the framework. Then, you explicitly would want your code to call a block or method or whatever that did horrendous unspeakable things, and still assert nothing_raised....

nathan,

yes, throw/catch is very similar to goto, but it isn't completely useless. It has its uses.

luskwater,

short answer: no.

longer answer:

def test_blah
  @obj.something_that_raises
end

outputs a completely intelligible error message.

Leave a comment

About this Entry

This page contains a single entry by zenspider published on April 28, 2008 11:01 AM.

must vs will was the previous entry in this blog.

https/ssl warning cleanup is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Pages

Powered by Movable Type 4.32-en