On Saturday, June 18, 2011 08:17:19 PM Douglas Seifert wrote:
> Each test method gets a new @life instance because the setup method runs
> before each test.  The theory is each test should run without side affects
> from other tests.  I am no testing expert either, but I would write your
> test in one method.
> 
> def test_vivify_and_murder
>   @life.vivify(2,-1)
>   assert( @life.world[2][-1] )
>   @life.murder(2,-1)
>   assert( !@life.world[2][-1] )
> end
> 
> Again, I'm sure this is considered poor style and not pure TDD/BDD.

You generally want one assertion per test. More doesn't hurt, but you probably 
still want a separate 'test_vivify_vivifies' method.

Also, if you find yourself writing a lot of tests which want a life already 
vivified, you may want to write another test class which does that in its 
setup. I'm not sure of the best way to do that in Test::Unit, though. I think 
I end up doing a lot of things like this in RSpec:

  describe 'A life' do
    before :each do
      @life = Life.new
    end

    it 'should exist' do
      @life.should_not be_nil
    end

    describe 'A vivified life' do
      before :each do
        @life.vivify(2,-1)
      end

      it 'should exist in the world' do
        @life.world[2][-1].should_not be_nil
      end

      it 'should be killed when murdered' do
        @life.murder(2,-1)
        @life.world[2][-1].should be_nil
      end
    end
  end


Be careful with this, though. While DRY (Don't Repeat Yourself) is a good 
principle in developing actual code, it's often better to have explicit 
readability in tests than implicit magic to avoid repeating yourself.