Class: Lemon::TestCase::DSL
- Defined in:
- lib/lemon/test_case.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#after(*matches, &procedure) ⇒ Object
(also: #After)
Define a complex after procedure.
-
#before(*matches, &procedure) ⇒ Object
(also: #Before)
Define a complex before procedure.
-
#context(label, *tags, &block) ⇒ Object
(also: #Context)
Create a subcase of module testcase.
-
#context_class ⇒ Object
The class for which this is a DSL context.
-
#initialize(testcase) ⇒ DSL
constructor
A new instance of DSL.
-
#omit(reason = true) ⇒ Object
(also: #Omit)
Omitted tests are simply ignored and never instantiated let alone passed on to the test harness.
-
#setup(description = nil, &procedure) ⇒ Object
(also: #Setup, #concern, #Concern)
Setup is used to set things up for each unit test.
-
#skip(reason = true) ⇒ Object
(also: #Skip)
Skip tests.
-
#teardown(&procedure) ⇒ Object
(also: #Teardown)
Teardown procedure is used to clean-up after each unit test.
Methods inherited from Module
Constructor Details
#initialize(testcase) ⇒ DSL
Returns a new instance of DSL.
197 198 199 200 201 202 203 204 205 |
# 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 |
Instance Method Details
#after(*matches, &procedure) ⇒ Object Also known as: After
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.
295 296 297 |
# File 'lib/lemon/test_case.rb', line 295 def after(*matches, &procedure) @_testcase.advice[:after][matches] = procedure end |
#before(*matches, &procedure) ⇒ Object Also known as: Before
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.
264 265 266 |
# File 'lib/lemon/test_case.rb', line 264 def before(*matches, &procedure) @_testcase.advice[:before][matches] = procedure end |
#context(label, *tags, &block) ⇒ Object Also known as: Context
Create a subcase of module testcase.
306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/lemon/test_case.rb', line 306 def context(label, *, &block) return if @_omit @_testcase.tests << context_class.new( :context => @_testcase, :target => @_testcase.target, :setup => @_setup, :skip => @_skip, :label => label, :tags => , &block ) end |
#context_class ⇒ Object
The class for which this is a DSL context.
190 191 192 |
# File 'lib/lemon/test_case.rb', line 190 def context_class TestCase end |
#omit(reason = true) ⇒ Object Also known as: Omit
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.
364 365 366 367 368 369 370 371 372 |
# 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(description = nil, &procedure) ⇒ Object Also known as: Setup, concern, Concern
Setup is used to set things up for each unit test. The setup procedure is run before each unit.
214 215 216 217 218 |
# 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(reason = true) ⇒ Object Also known as: Skip
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.
338 339 340 341 342 343 344 345 346 |
# 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 |
#teardown(&procedure) ⇒ Object Also known as: Teardown
Teardown procedure is used to clean-up after each unit test.
230 231 232 |
# File 'lib/lemon/test_case.rb', line 230 def teardown(&procedure) @_setup.teardown = procedure end |