Class: TestUnitChaser
Constant Summary collapse
- @@test_pattern =
'test/test_*.rb'- @@tests_loaded =
false
Constants inherited from Chaser
Chaser::NULL_PATH, Chaser::VERSION, Chaser::WINDOZE
Instance Attribute Summary
Attributes inherited from Chaser
#klass, #klass_name, #method, #method_name, #old_method
Class Method Summary collapse
- .load_test_files ⇒ Object
- .test_pattern=(value) ⇒ Object
- .validate(klass_name, method_name = nil, force = false) ⇒ Object
Instance Method Summary collapse
-
#initialize(klass_name = nil, method_name = nil) ⇒ TestUnitChaser
constructor
A new instance of TestUnitChaser.
- #tests_pass? ⇒ Boolean
Methods inherited from Chaser
#aliasing_class, #clean_method_name, debug, debug=, guess_timeout?, #modify_class_method, #modify_instance_method, #modify_method, #mutate_value, #rand_number, #rand_range, #rand_string, #rand_symbol, #record_passing_mutation, #run_tests, #silence_stream, timeout=, #unmodify_class_method, #unmodify_instance_method, #unmodify_method, #validate
Constructor Details
#initialize(klass_name = nil, method_name = nil) ⇒ TestUnitChaser
Returns a new instance of TestUnitChaser.
94 95 96 97 |
# File 'lib/test_unit_chaser.rb', line 94 def initialize(klass_name=nil, method_name=nil) super self.class.load_test_files unless @@tests_loaded end |
Class Method Details
.load_test_files ⇒ Object
25 26 27 28 29 |
# File 'lib/test_unit_chaser.rb', line 25 def self.load_test_files @@tests_loaded = true raise "Can't detect any files in test pattern \"#{@@test_pattern}\"#{WINDOZE ? " Are you remembering to use forward slashes?" : ""}" if Dir.glob(@@test_pattern).empty? Dir.glob(@@test_pattern).each {|test| require test} end |
.test_pattern=(value) ⇒ Object
21 22 23 |
# File 'lib/test_unit_chaser.rb', line 21 def self.test_pattern=(value) @@test_pattern = value end |
.validate(klass_name, method_name = nil, force = false) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 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 |
# File 'lib/test_unit_chaser.rb', line 31 def self.validate(klass_name, method_name = nil, force = false) load_test_files klass = klass_name.to_class # Does the method exist? klass_methods = klass.singleton_methods(false).collect {|meth| "self.#{meth}"} if method_name if method_name =~ /self\./ abort "Unknown method: #{klass_name}.#{method_name.gsub('self.', '')}" unless klass_methods.include? method_name else abort "Unknown method: #{klass_name}##{method_name}" unless klass.instance_methods(false).map{|sym| sym.to_s}.include? method_name end end initial_time = Time.now chaser = self.new(klass_name) passed = chaser.tests_pass? unless force or passed then abort "Initial run of tests failed... fix and run chaser again" end if self.guess_timeout? then running_time = Time.now - initial_time adjusted_timeout = (running_time * 2 < 5) ? 5 : (running_time * 2).ceil self.timeout = adjusted_timeout end puts "Timeout set to #{adjusted_timeout} seconds." if passed then puts "Initial tests pass. Let's rumble." else puts "Initial tests failed but you forced things. Let's rumble." end puts methods = method_name ? Array(method_name) : klass.instance_methods(false) + klass_methods counts = Hash.new(0) methods.sort.each do |method_name| result = self.new(klass_name, method_name).validate counts[result] += 1 end all_good = counts[false] == 0 puts "Chaser Results:" puts puts "Passed : %3d" % counts[true] puts "Failed : %3d" % counts[false] puts if all_good then puts "All chasing was thwarted! YAY!!!" else puts "Improve the tests and try again." end all_good end |
Instance Method Details
#tests_pass? ⇒ Boolean
99 100 101 102 103 104 105 |
# File 'lib/test_unit_chaser.rb', line 99 def tests_pass? silence_stream do result = Test::Unit::AutoRunner.run ARGV.clear result end end |