class Lemon::TestCase

Test Case serves as the base class for Lemon's specialized test case classes.

Attributes

advice[R]

Advice are labeled procedures, such as before and after advice.

context[R]

The parent context in which this case resides.

label[R]

Brief description of the test case.

setup[R]

The setup and teardown advice.

skip[R]

Skip execution of test case?

target[R]

Target component.

tests[R]

List of tests and sub-contexts.

Public Class Methods

new(settings={}, &block) click to toggle source

A test case target is a class or module.

@param [Hash] settings

The settings used to define the test case.

@option settings [TestCase] :context

Parent test case.

@option settings [Module,Class,Symbol] :target

The testcase's target.

@option settings [String] :label

Breif description of testcase.
(NOTE: this might not be used)

@option settings [TestSetup] :setup

Test setup.

@option settings [Boolean] :skip

If runner should skip test.
# File lib/lemon/test_case.rb, line 58
def initialize(settings={}, &block)
  @context = settings[:context]
  @target  = settings[:target]
  @label   = settings[:label]
  @setup   = settings[:setup]
  @skip    = settings[:skip]
  @tags    = settings[:tags]

  @advice  = @context ? @context.advice.dup : TestAdvice.new

  @tests   = []
  @domain  = domain_class.new(self)

  validate_settings

  evaluate(&block)
end

Public Instance Methods

domain() click to toggle source
# File lib/lemon/test_case.rb, line 84
def domain
  @domain
end
domain_class() click to toggle source

Get the domain class dynamically so that each subclass of TestCase will retrieve it's own.

# File lib/lemon/test_case.rb, line 180
def domain_class
  self.class.const_get(:DSL)
end
each(&block) click to toggle source

Iterate over each test and subcase.

# File lib/lemon/test_case.rb, line 98
def each(&block)
  tests.each(&block)
end
evaluate(&block) click to toggle source
# File lib/lemon/test_case.rb, line 91
def evaluate(&block)
  @domain.module_eval(&block)
end
run(test, &block) click to toggle source

Run test in the context of this case.

@param [TestProc] test

The test unit to run.
# File lib/lemon/test_case.rb, line 151
def run(test, &block)
  advice[:before].each do |matches, block|
    if matches.all?{ |match| test.match?(match) }
      scope.instance_exec(test, &block) #block.call(unit)
    end
  end

  block.call

  advice[:after].each do |matches, block|
    if matches.all?{ |match| test.match?(match) }
      scope.instance_exec(test, &block) #block.call(unit)
    end
  end
end
scope() click to toggle source

Module for evaluating test case script.

@return [Scope] evaluation scope

# File lib/lemon/test_case.rb, line 172
def scope
  @scope ||= TestScope.new(self)
end
size() click to toggle source

Number of tests and subcases.

# File lib/lemon/test_case.rb, line 105
def size
  tests.size
end
skip!(reason=true) click to toggle source
# File lib/lemon/test_case.rb, line 134
def skip!(reason=true)
  @skip = reason
end
skip?() click to toggle source
# File lib/lemon/test_case.rb, line 127
def skip?
  @skip
end
tags() click to toggle source
# File lib/lemon/test_case.rb, line 141
def tags
  @tags
end
to_s() click to toggle source
# File lib/lemon/test_case.rb, line 120
def to_s
  @label.to_s
end
type() click to toggle source

Subclasses of TestCase can override this to describe the type of test case they define.

# File lib/lemon/test_case.rb, line 113
def type
  'Test Case'
end
validate_settings() click to toggle source

Subclasses can override this methof to validate settings. It is run just before evaluation of scope block.

# File lib/lemon/test_case.rb, line 80
def validate_settings
end