class Lemon::TestCase
Test Case serves as the base class for Lemon's specialized test case classes.
Attributes
Advice are labeled procedures, such as before and after advice.
The parent context in which this case resides.
Brief description of the test case.
The setup and teardown advice.
Skip execution of test case?
Target component.
List of tests and sub-contexts.
Public Class Methods
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
# File lib/lemon/test_case.rb, line 84 def domain @domain end
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
Iterate over each test and subcase.
# File lib/lemon/test_case.rb, line 98 def each(&block) tests.each(&block) end
# File lib/lemon/test_case.rb, line 91 def evaluate(&block) @domain.module_eval(&block) end
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
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
Number of tests and subcases.
# File lib/lemon/test_case.rb, line 105 def size tests.size end
# File lib/lemon/test_case.rb, line 134 def skip!(reason=true) @skip = reason end
# File lib/lemon/test_case.rb, line 127 def skip? @skip end
# File lib/lemon/test_case.rb, line 120 def to_s @label.to_s end
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
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