module TestBelt
Constants
- LIB_DIR
- TEST_DIR
assume the test dir path is ./test and the lib dir path ./test/../lib
- TEST_HELPER_FILE
- TEST_REGEX
- VERSION
Public Class Methods
included(receiving_test_class)
click to toggle source
# File lib/test_belt/setup.rb, line 17 def self.included(receiving_test_class) if receiving_test_class.ancestors.include?(::Test::Unit::TestCase) receiving_test_class.send(:include, DefaultTest) receiving_test_class.send(:include, TestCase) receiving_test_class.send(:extend, Should) receiving_test_class.send(:include, Context) receiving_test_class.send(:include, Subject) receiving_test_class.send(:include, Skip) receiving_test_class.send(:include, Callbacks) receiving_test_class.send(:include, Matchers) end end
setup(caller_info)
click to toggle source
run some setup stuff based on the caller's info
# File lib/test_belt/setup.rb, line 39 def setup(caller_info) if (crp = caller_root_path(caller_info)) add_caller_paths_to_load_path(crp) require_caller_test_helper(crp) end end
Private Class Methods
add_caller_paths_to_load_path(root_path)
click to toggle source
add the caller's lib/test dirs to the load path
# File lib/test_belt/setup.rb, line 49 def add_caller_paths_to_load_path(root_path) add_to_load_path(File.join(root_path, LIB_DIR)) add_to_load_path(File.join(root_path, TEST_DIR)) end
add_to_load_path(dir)
click to toggle source
# File lib/test_belt/setup.rb, line 54 def add_to_load_path(dir) $LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir) end
caller_root_path(caller_info)
click to toggle source
this method inspects the caller info and finds the caller's root path this expects the caller's root path to be the parent dir of the first parent dir of caller named TEST_DIR
# File lib/test_belt/setup.rb, line 69 def caller_root_path(caller_info) caller_dirname = File.expand_path(File.dirname(caller_info[0])) if (test_dir_pos = caller_dirname.index(TEST_REGEX)) > 0 root_dir = caller_dirname[0..(test_dir_pos-1)] end end
require_caller_test_helper(root_path)
click to toggle source
require the caller's test/helper file if exists
# File lib/test_belt/setup.rb, line 59 def require_caller_test_helper(root_path) if File.exists?(File.join(root_path, TEST_DIR, TEST_HELPER_FILE+'.rb')) && $LOAD_PATH.include?(File.join(root_path, TEST_DIR)) require TEST_HELPER_FILE end end