Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
49 lines (35 sloc) 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
Jump to Line
Something went wrong with that request. Please try again.