Class: Util::Testing
- Inherits:
-
Object
- Object
- Util::Testing
- Defined in:
- lib/util/test.rb
Overview
Class for some basic unit testing.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(logger = nil) ⇒ Testing
constructor
Create a new testing framework.
-
#register(name, expect = nil, with = '', &block) ⇒ Object
Add a test to the framework.
-
#run ⇒ Object
Run all the tests and express the results on the given logger.
Constructor Details
#initialize(logger = nil) ⇒ Testing
Create a new testing framework.
50 51 52 53 54 55 56 57 |
# File 'lib/util/test.rb', line 50 def initialize logger=nil init_i18n init_logger logger init_tmp_path init_io @tests = [] ObjectSpace.define_finalizer self, self.class.method(:finalize) end |
Class Method Details
.finalize(id) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/util/test.rb', line 37 def self.finalize id obj = ObjectSpace._id2ref id begin File.delete obj.send(:stdout_path) File.delete obj.send(:stderr_path) rescue Exception => e puts e. end end |
Instance Method Details
#register(name, expect = nil, with = '', &block) ⇒ Object
Add a test to the framework. If the test name is empty, the test will be run, but its results will not be displayed. Makes it possible to clean up between tests.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/util/test.rb', line 68 def register name, expect=nil, with='', &block return false unless block.respond_to? :call test = { :proc => block } test[:name] = name.to_s test[:expect] = expect unless expect.nil? test[:with] = with.to_s unless with.nil? @tests << test end |
#run ⇒ Object
Run all the tests and express the results on the given logger.
80 81 82 83 84 85 86 |
# File 'lib/util/test.rb', line 80 def run @tests.each do |t| run_actual_test t run_determine_success t run_express_result t end end |