Skip to content

Latest commit

 

History

History
48 lines (35 loc) · 876 Bytes

README_CONTEXTS.rdoc

File metadata and controls

48 lines (35 loc) · 876 Bytes

Summary

Provides embeddable contexts with setups and teardowns

Examples

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

API

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