Provides embeddable contexts with setups and teardowns
require 'nanotest' require 'nanotest/contexts' include Nanotest include Nanotest::Contexts context do setup { @foo = 'foo' } teardown { @foo = nil } # test description test do assert { @foo == 'foo' } end context do setup { @bar = 'bar' } test do assert { @foo == 'foo' } assert { @bar == 'bar' } end end end
Contexts provides 4 methods: #context, #setup, #teardown, #test. To use them, you can either mixin the Contexts module as above, or keep them namespaced:
Nanotest::Contexts.context do setup {} # ... end
If you prefer other method names, simply alias them:
module Nanotest::Contexts alias :describe :context alias :before :setup alias :after :teardown end