Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Nested contexts for test/unit tests
Ruby
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
README.textile
nest-unit.gemspec

README.textile

nest-unit

Simple nested contexts for Test::Unit.

Usage

require 'test/unit'
require 'nest-unit'

class FooTest < Test::Unit::TestCase

  test "should be true" do
    assert true
  end
  
  context "when there is a thing" do
    before do
      @thing = Object.new
    end
    
    test "bar-ing" do
      assert Foo.bar(@thing)
    end
    
    test "fizz-ing" do
      assert Foo.fizz(@thing)
    end
    
    context "when there are two things" do
      before do
        @another_thing = Object.new
      end
      
      test "bar-ing" do
        assert Foo.bar(@thing, @another_thing)
      end
      
      test "fizz-ing" do
        assert Foo.fizz(@thing, @another_thing)
      end
      
      after do
        Foo.some_more_cleanup!
      end
    end
    
    after do
      Foo.cleanup!
    end
  end
end

Helper Methods

If you need to define helper methods for your tests, use the helper helper:

class FooTest < Test::Unit::TestCase

  helper :double do |x|
    x * 2
  end

  test "should be double" do
    assert_equal 4, double(2)
  end
end

Note

You must use the test helper. Tests defined with the usual
def test_* don’t work yet. I need to hook up some method_added
juice or something.

© Copyright 2008 Pat Nakajima, released under MIT License.

Something went wrong with that request. Please try again.