Module: Oats::TestData
- Defined in:
- lib/oats/test_data.rb
Overview
Interface module for TestCase or TestList related operations
Constant Summary collapse
- @@pause_after_error =
false
Class Method Summary collapse
-
.current_test ⇒ Object
- Returns last test in the currently executing list index
-
of the test in tests array.
- .error(exception) ⇒ Object
-
.locate(test_file, is_dir = false) ⇒ Object
Returns absolute path after locating file in test directories, or nil If exact match is not found, searches with added .rb extension If dir is false, do not return a directory #.
- .pause_after_error ⇒ Object
- .pause_after_error=(do_pause) ⇒ Object
- .previous_test ⇒ Object
-
.tests ⇒ Object
Returns array of test objects in the currently executing list TestData.tests is the same as as the current_test.
Class Method Details
.current_test ⇒ Object
Returns last test in the currently executing list
- index
-
of the test in tests array. Default is last
26 27 28 |
# File 'lib/oats/test_data.rb', line 26 def TestData.current_test TestData.tests[-1] end |
.error(exception) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/oats/test_data.rb', line 42 def TestData.error(exception) raise exception unless TestData.current_test error = [exception.class.to_s,exception., exception.backtrace] TestData.current_test.errors << error TestData.current_test.status = 1 @@pause_after_error = true end |
.locate(test_file, is_dir = false) ⇒ Object
Returns absolute path after locating file in test directories, or nil If exact match is not found, searches with added .rb extension If dir is false, do not return a directory #
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/oats/test_data.rb', line 53 def TestData.locate(test_file, is_dir = false) option ||= {} # Don't rely on $oats when called from OCC dir_tests = if $oats and $oats['execution'] and $oats['execution']['dir_tests'] $oats['execution']['dir_tests'] else ENV['OATS_TESTS'] end Oats.assert test_file, "Test File must be non-nil" extn = File.extname(test_file) extn = nil if extn == '' found_file = catch :found_file do if RUBY_PLATFORM =~ /(mswin|mingw)/ ? test_file[1] == ?: : test_file[0] == ?/ # absolute path # Try exact match throw(:found_file, test_file) if File.exist?(test_file) and (is_dir or not FileTest.directory?(test_file)) # Try globbing the input name as is found_file = File.exist?(test_file) throw(:found_file, test_file ) if found_file and (is_dir or not FileTest.directory?(test_file)) throw(:found_file, test_file+'.rb') if File.exist?(test_file+'.rb') unless extn end # Relative path dir_tests = "{#{is_dir},#{dir_tests}}" if is_dir.instance_of?(String) and is_dir != dir_tests # 19.2 glob skips over the exact test paths, so try that first file = File.join(dir_tests, test_file) file += '{,.rb}' unless extn found_file = Dir.glob(file).first throw(:found_file, found_file) if found_file and (is_dir or not FileTest.directory?(found_file)) # Try finding it anywhere inside the dir_test tree file = File.join(dir_tests, '**', test_file) file += '{,.rb}' unless extn found_file = Dir.glob(file).first throw(:found_file, found_file) if found_file and (is_dir or not FileTest.directory?(found_file)) return nil end Oats::Util.(found_file) end |
.pause_after_error ⇒ Object
34 35 36 |
# File 'lib/oats/test_data.rb', line 34 def TestData.pause_after_error @@pause_after_error end |
.pause_after_error=(do_pause) ⇒ Object
38 39 40 |
# File 'lib/oats/test_data.rb', line 38 def TestData.pause_after_error=(do_pause) @@pause_after_error = do_pause end |
.previous_test ⇒ Object
30 31 32 |
# File 'lib/oats/test_data.rb', line 30 def TestData.previous_test TestData.tests[-2] end |
.tests ⇒ Object
Returns array of test objects in the currently executing list TestData.tests is the same as as the current_test
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/oats/test_data.rb', line 12 def TestData.tests cur_test_list = TestList.current return nil unless cur_test_list vars = cur_test_list.variations return nil unless vars last_var = vars.last return nil unless last_var tests = last_var.tests return nil unless tests return tests end |