Class: TTK::Strategies::RUnit
- Includes:
- Concrete
- Defined in:
- lib/ttk/strategies/RUnit.rb
Overview
Description
This strategy is wrapper around a Ruby unit test suite based on the test/unit library. Using RUnit you avoid the Ruby ‘require’ problem and you use all the power of the TTK’s Suite and/or Pool.
How it works ?
RUnit works by invoking Ruby on the specified file and then parsing the output to inject the result in the TTK’s log stream. To do that, you must use a specific TestRunner based on YAML. This TestRunner produces a YAML output readable by a human and the strategy.
Examples
You need to first write your unit test suite using the test/unit package and the YAML TestRunner. Then, you write a few line in the input TTK file to incorporate the unit test in the TTK’s suite.
The unit test suite file: foo_test.rb
require 'test/unit/ui/yaml/testrunner'
require 'foo'
class FooTest < Test::Unit::TestCase
def test_1
assert(true)
end
end
Test::Unit::UI::Yaml::TestRunner.run(FooTest)
The YAML input file for TTK
---
RUnit example test:
strategy: RUnit
unit_file: my_unit_directory/foo_test.rb
One suite for all your unit test suite
If you find cumbersome to write for every unit test file a single RUnit strategy into the YAML input file of TTK, there is another way to do so. Here we go:
---
TTK's unit test suite:
strategy: Glob
glob: '<<pwd>>/../runit/**/*_test.rb'
regexp: !re /(runit/.+_test\.rb)$
test:
'Unit test <<match>>':
strategy: RUnit
unit_file: <<match>>
work_dir: <<pwd>>/..
load_path: ../lib
verbose: true
This file is extracted from the TTK’s minimal test suite (test/ttk-minimal/unit_test.yml). The strategy upon it is based (Glob) looks for every file ending by ‘_test.rb’ in a particular directory relative to the place the TTK YAML input file is located (<<pwd>>). All these files are loaded as RUnit strategy with a verbose mode on, the TTK library loaded in the $LOAD_PATH Ruby variable, and the correct working directory. Thus, every unit test files are embedded in a TTK suite.
Instance Attribute Summary
Attributes inherited from Strategy
Method Summary
Methods inherited from Strategy
#abort, #assign, #clean_instance_variables, #display_unexpected_exc, #display_unexpected_synflow_exc, #fail, #initialize, #initialize_flow_factory, #pass, #raise_error, #reject, #run, #running?, #skip, #skip_if_cached, #strategy, #strategy=, #symbols=, #testify, #timeout=, #to_s, #wclass=
Constructor Details
This class inherits a constructor from TTK::Strategies::Strategy