From: Eric Hodel Date: 2007-01-24T11:22:56+09:00 Subject: Re: I don't get rspec On Jan 23, 2007, at 17:36, Pat Maddox wrote: > On 1/23/07, Eric Hodel wrote: >> On Jan 23, 2007, at 16:26, James Edward Gray II wrote: >> > On Jan 23, 2007, at 6:10 PM, Joe Van Dyk wrote: >> >> What's wrong with zentest, specifically? >> > >> > You will probably understand better by watching the movie, but >> > zentest encourages you to make a test case for each class and a >> > test method for each method. >> >> Which will match up 1:1 if you factor your code well. > > The point is that you shouldn't try to shoehorn your tests into this > 1:1 approach. Shoehorning is design smell, so I refactor. The 1:1 falls out because of good design. Its not something I aim for, its something I refactor to. > You brought up the tutorial as an example of specs that > match up nicely with the code, but even that ends up with a few > contexts. If you just have a StackTest class, you won't get the same > logical separation. How many programmers are going to write an > EmpyStackTest class, a OneItemStackTest class, a FullStackTest class, > etc? BDD and TDD are not 1:1 in this manner, so you've overdesigned your unit tests. Instead, do the simplest thing that works: require 'rubygems' require 'test/unit' require 'test/zentest_assertions' class TestStack < Test::Unit::TestCase def setup @s = Stack.new end def test_empty_eh assert @s.empty? @s.push 1 deny @s.empty? end def test_push @s.push 1 deny @s.empty? assert_equal 1, @s.top end def test_top assert_nil @s.top @s.push 1 assert_equal 1, @s.top end end > As your behavior becomes more complex - by interacting with other > objects - you need to be able to drill a bit deeper with your > specifications. I often have one complete context for an individual > method. Not many programmers will create a new test class just to > spec a method. And that doesn't mean that this method is too tightly > coupled to other objects, it just means that you need more > finely-grained specifications. This is where I create new methods or new classes on the implementation side. As the number of edgecases increase I pull out bits that are resistant to testing by refactoring. Creating multiple test classes to test one implementation class is design smell. -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net I LIT YOUR GEM ON FIRE!