Ruby: April 2008 Archives

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.

must vs will

| | Comments (0)

John Barnette made a suggestion I like: will vs wont.

Do you like that better than must vs wont? I think I do, but it might be too visually similar. I'm not sure. Check it:

(6 * 7).must_equal 42
(6 * 9).wont_equal 42

vs.

(6 * 7).will_equal 42
(6 * 9).wont_equal 42

I think it looks OK so far.

Also, I added a simple little mapping system to make morphing the assertions into specifications more readable:

Object.infect(:must, :wont,
              /(throw)s/              => '\1',
              /must_(.*_of|nil|same)/ => 'must_be_\1',
              /must_not_(nil|same)/   => 'must_not_be_\1',
              /wont_(nil|same)/       => 'wont_be_\1',
              /must_in_delta/         => 'must_be_close_to',
              /must_no_match/         => 'must_not_match',
              /must_operator/         => 'must_be',
/^(wont|must(_(block|raises|nothing_(raised|thrown)))?)$/ => :skip)

deny, refute, debunk

| | Comments (3)

I've been working a lot on miniunit (still needs a new name) and have been playing with words lately. should has been replaced with must, and should_not (lame!) has been replaced with wont. Wish I could have an apostrophe in there.

For a while Eric and I have added a method to our assertion suite:

def deny exp
  assert ! exp
end

It is a really handy way to describe things. I dislike the look and sound of assert ! blah so we go with deny... but one thing bugs me:

def test\_something
  assert 42 == 6 * 7
  deny 42 == 6 * 9    # does not line up
end

Yeah yeah... I'm OCD or something. I would much rather read:

def test\_something\_better
  assert 42 == 6 * 7
  refute 42 == 6 * 9
end

I was digging through Apple's wonderful dictionary and thesaurus and came up with another possibility: debunk... how much better or worse is this?

def test\_something\_better
  assert 42 == 6 * 7
  debunk 42 == 6 * 9
end

Hell... let's get rid of assert and go with prove and rebut! I've just saved you all an extra key per test! OH! show! Now that's a lot more assertive (pun intended) than assert is. That means I could come back full circle to deny.

That reminds me... I've LONG wanted a list of same-length opposite verbs and adjectives. Google turns up nothing... I'm wondering if I can't somehow generate it with GED's linguistics library.

miniunit needs a new name

| | Comments (2)

I've restructured and added to miniunit:

lib/mini/test.rb
lib/mini/spec.rb
lib/mini/mock.rb

All this fun in less than a thousand lines, tests included!

So obviously it needs a new name. I was thinking of calling it "Mini de Sade" for fun, but it really doesn't convey what it does (other than hurt other code--tee hee!). I also searched through the dictionary looking for other possibilities:

% egrep -i "m.*(t.*s|s.*t)|t.*(m.*s|s.*m)|s.*(m.*t|t.*m)" /usr/share/dict/words | ruby -e 'p STDIN.read.split(/\n/).sort_by { |s| s.length }.first(11)'
["must", "mist", "mast", "stem", "smit", "stum", "smut", "most", "myst", "stim", "stam"]

And I gotta say, I kinda like MuST. I used that as inspiration already. I've also decided that "should" is too wishy-washy and switched to "must" in mini/spec.rb. (Don't worry, I made it easy to add your shoulds if you so desire).

(ooh. smut == specs, mocks, and unit tests)

Any naming suggestions?

Speaking at GoRuCo

| | Comments (0)

I'll be giving my talk "Hurting Code for Fun and Profit" as well as hosting RejectConf at GoRuCo this weekend. I hope to see you there!

About this Archive

This page is a archive of entries in the Ruby category from April 2008.

Ruby: March 2008 is the previous archive.

Ruby: May 2008 is the next archive.

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

Pages

Powered by Movable Type 4.1