From: Gavin Sinclair Date: 2004-05-18T08:06:29+09:00 Subject: Re: How to duck type? - the psychology of static typing in Ruby On Monday, May 17, 2004, 11:52:22 PM, Tim wrote: > Now if you'd been writing and collecting unit tests as you went along, > instead of > NoMethodError: undefined method `year' for "notadate":String > you would be seeing > 1) Failure: > test_stuff(MyClassTest) [./test/myclasstest.rb:13]: > is not true. > which makes the error even easier to find: you go to test/myclasstest.rb > and see something like: > 10: def test_date > 11: @obj = Foo.new > 12: @obj.date = MyClass.new.notadate > 13: assert(@obj.date.respond_to?(:year)) > 14: end Now I'm no unit testing guru (I try...) but that test to me seems so trivial as to be pointless. Since the code it's testing does absolutely nothing other than assignment, you're not testing the *code*, you're testing one possible input value. I think it would be more convincing to talk about unit tests covering the correct overall operation of the class under scrutiny, rather than examining some lowly accessor. # But your psychological needs could differ from mine :) The rest of the article's good, though. Cheers, Gavin