class Lemon::TestCase::DSL
Public Class Methods
# 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
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
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
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
The class for which this is a DSL
context.
# File lib/lemon/test_case.rb, line 190 def context_class TestCase end
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
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
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