Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Simple nested contexts for your tests
Ruby
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
.gitignore
LICENSE
README.rdoc

README.rdoc

Love Nest

Nested contexts for your Test::Unit test cases.

Example, please

require "test/unit"
require "love_nest"

class MyTestCase < Test::Unit::TestCase
  include LoveNest::TestCase

  context "A foo" do
    setup do
      super
      @foo = Foo.new
    end

    test "is fooey" do
      assert @foo.fooey?
    end
  end

  context "A bar" do
    ...
  end
end

Philosophy

LoveNest wants you to be as explicit as possible when declaring your tests. In order for it to work, you must include it explicitly into a class. You can do the following if you want the methods available on all test cases:

class Test::Unit::TestCase
  include LoveNest::TestCase
end

Also, when you declare setup/teardown blocks, you should call super in order to call other setup/teardown blocks.

class MyTestCase < Test::Unit::TestCase
  setup do
    super # call setup blocks on the parent class
    @foo = Foo.new
  end

  context "Some nesting, please" do
    setup do
      super # first call the setup block on MyTestCase (and ancestors)
      @bar = Bar.new
    end

    test "foobar!" do
      ...
    end
  end
end

Why? Well, in 3 months someone else will read this test case and wonder why a test fails, and then figure out it's because a setup block, defined on a globally required test helper, was doing something bad. With an explicit call to super you get reminded that there are (or at least might be) other blocks of code running, which might introduce side effects to your test case.

Credits

LoveNest was heavily influenced by Contest.

Author

Nicolás Sanguinetti (aka foca)

License

Code released under an MIT license. See LICENSE for details.

Something went wrong with that request. Please try again.