ZenTestMapping - mapping method names from impl to test.
Method names are mapped bidirectionally in the following way:
method test_method method? test_method_eh (too much exposure to Canadians :) method! test_method_bang method= test_method_equals [] test_index * test_times == test_equals2 === test_equals3
Further, any of the test methods should be able to have arbitrary extensions put on the name to distinguish edge cases:
method test_method method test_method_simple method test_method_no_network
To allow for unmapped test methods (ie, non-unit tests), name them:
test_integration_.*
# File lib/zentest_mapping.rb, line 62 62: def munge name 63: name = name.to_s.dup 64: 65: is_cls_method = name.sub!(/^self\./, '') 66: 67: name = @@method_map[name] if @@method_map.has_key? name 68: name = name.sub(/=$/, '_equals') 69: name = name.sub(/\?$/, '_eh') 70: name = name.sub(/\!$/, '_bang') 71: 72: name = yield name if block_given? 73: 74: name = "class_" + name if is_cls_method 75: 76: name 77: end
Generates a test method name from a normal method, taking into account names composed of metacharacters (used for arithmetic, etc
# File lib/zentest_mapping.rb, line 82 82: def normal_to_test name 83: "test_#{munge name}" 84: end
Converts a method name beginning with test to its corresponding normal method name, taking into account symbolic names which may have been anglicised by #.
# File lib/zentest_mapping.rb, line 106 106: def test_to_normal(name, klassname=nil) 107: unmunge(name.to_s.sub(/^test_/, '')) do |n| 108: if defined? @inherited_methods then 109: known_methods = (@inherited_methods[klassname] || {}).keys.sort.reverse 110: known_methods_re = known_methods.map {|s| Regexp.escape(s) }.join("|") 111: n = n.sub(/^(#{known_methods_re})(_.*)?$/) { $1 } unless 112: known_methods_re.empty? 113: n 114: end 115: end 116: end
# File lib/zentest_mapping.rb, line 86 86: def unmunge name 87: name = name.to_s.dup 88: 89: is_cls_method = name.sub!(/^class_/, '') 90: 91: name = name.sub(/_equals(_.*)?$/, '=') unless name =~ /index/ 92: name = name.sub(/_bang(_.*)?$/, '!') 93: name = name.sub(/_eh(_.*)?$/, '?') 94: name = name.sub(/^(#{@@mapped_re})(_.*)?$/) {$1} 95: name = yield name if block_given? 96: name = @@method_map[name] if @@method_map.has_key? name 97: name = 'self.' + name if is_cls_method 98: 99: name 100: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.