class Lemon::TestCase::DSL

Public Class Methods

new(testcase) click to toggle source
# File lib/lemon/test_case.rb, line 197
def initialize(testcase) #, &code)
  @_testcase = testcase
  @_setup    = testcase.setup
  @_skip     = nil

  include testcase.context.domain if testcase.context

  #module_eval(&code)
end

Public Instance Methods

After(*matches, &procedure)
Alias for: after
Before(*matches, &procedure)
Alias for: before
Concern(description=nil, &procedure)
Alias for: setup
Context(label, *tags, &block)
Alias for: context
Omit(reason=true)
Alias for: omit
Setup(description=nil, &procedure)
Alias for: setup
Skip(reason=true)
Alias for: skip
Teardown(&procedure)
Alias for: teardown
after(*matches, &procedure) click to toggle source

Define a complex after procedure. The before method allows before procedures to be defined that are triggered by a match against the unit's target method name or aspect description. This allows groups of tests to be defined that share special teardown code.

@example

Method :puts do
  Test "standard output (@stdout)" do
    puts "Hello"
  end

  Before /@stdout/ do
    $stdout = StringIO.new
  end

  After /@stdout/ do
    $stdout = STDOUT
  end
end

@param [Array<Symbol,Regexp>] matches

List of match critera that must _all_ be matched
to trigger the after procedure.
# File lib/lemon/test_case.rb, line 295
def after(*matches, &procedure)
  @_testcase.advice[:after][matches] = procedure
end
Also aliased as: After
before(*matches, &procedure) click to toggle source

Define a complex before procedure. The before method allows before procedures to be defined that are triggered by a match against the unit's target method name or aspect description. This allows groups of tests to be defined that share special setup code.

@example

Method :puts do
  Test "standard output (@stdout)" do
    puts "Hello"
  end

  Before /@stdout/ do
    $stdout = StringIO.new
  end

  After /@stdout/ do
    $stdout = STDOUT
  end
end

@param [Array<Symbol,Regexp>] matches

List of match critera that must _all_ be matched
to trigger the before procedure.
# File lib/lemon/test_case.rb, line 264
def before(*matches, &procedure)
  @_testcase.advice[:before][matches] = procedure
end
Also aliased as: Before
concern(description=nil, &procedure)

Original Lemon nomenclature for `#setup`.

Alias for: setup
context(label, *tags, &block) click to toggle source

Create a subcase of module testcase.

# File lib/lemon/test_case.rb, line 306
def context(label, *tags, &block)
  return if @_omit

  @_testcase.tests << context_class.new(
    :context => @_testcase,
    :target  => @_testcase.target,
    :setup   => @_setup,
    :skip    => @_skip,
    :label   => label,
    :tags    => tags,
    &block
  )
end
Also aliased as: Context
context_class() click to toggle source

The class for which this is a DSL context.

# File lib/lemon/test_case.rb, line 190
def context_class
  TestCase
end
omit(reason=true) { || ... } click to toggle source

Omitted tests are simply ignored and never instantiated let alone passed on to the test harness.

If a block is given then only tests defined with-in the block are skipped. If no block is given then all subsquent tests in the test case are skipped.

@example

omit do
  test do
    ...
  end
end
# File lib/lemon/test_case.rb, line 364
def omit(reason=true)
  if block_given?
    @_omit = reason
    yield
    @_omit = nil
  else
    @_omit = reason
  end
end
Also aliased as: Omit
setup(description=nil, &procedure) click to toggle source

Setup is used to set things up for each unit test. The setup procedure is run before each unit.

@param [String] description

A brief description of what the setup procedure sets-up.
# File lib/lemon/test_case.rb, line 214
def setup(description=nil, &procedure)
  if procedure
    @_setup = TestSetup.new(@test_case, description, &procedure)
  end
end
Also aliased as: Setup, concern, Concern
skip(reason=true) { || ... } click to toggle source

Skip tests. Unlike omit, skipped tests are passed to the test harness, so they still can be included in reports, though they are not executed.

If a block is given then only tests defined with-in the block are skipped. If no block is given then all subsquent tests in the test case are skipped.

@param [String,Boolean] reason

A description of the reason to skip the test, or simply a boolean value.

@example

skip "reason" do
  test do
    ...
  end
end
# File lib/lemon/test_case.rb, line 338
def skip(reason=true)
  if block_given?
    @_skip = reason
    yield
    @_skip = nil
  else
    @_skip = reason
  end
end
Also aliased as: Skip
teardown(&procedure) click to toggle source

Teardown procedure is used to clean-up after each unit test.

# File lib/lemon/test_case.rb, line 230
def teardown(&procedure)
  @_setup.teardown = procedure
end
Also aliased as: Teardown