lib/java_autotest/autotest.rb in java-autotest-0.0.1 vs lib/java_autotest/autotest.rb in java-autotest-0.0.2
- old
+ new
@@ -1,35 +1,37 @@
class AutoTest
- attr_accessor :run_at, :files
+ attr_accessor :run_at, :files, :test_runner
- def initialize
- @run_at = Time.new
- @files = File.find_java_files
- end
-
- def listen
- @files.each do |file|
- if (File.atime(file).to_i > @run_at.to_i)
- run(file)
- break
- end
- end
- true
- end
-
- def run(file)
- test_class = find_test_class file
- puts "Running test to #{test_class}."
- green = TestRunner.run_test(test_class)
- TestRunner.run_all_tests if green
- reset
- end
-
- def find_test_class(file)
- return file.split("/").last.split(".java").last.concat("Test.java") unless file.include? "Test.java"
- return file.split("/").last if file.include? "Test.java"
- end
-
- def reset
- @run_at = Time.new
- end
+ def initialize
+ @files = File.find_java_files
+ @test_runner = TestRunner.new
+ @test_runner.run_all_tests
+ @run_at = Time.new
+ end
+
+ def listen
+ @files.each do |file|
+ if (File.atime(file).to_i > @run_at.to_i)
+ run(file)
+ break
+ end
+ end
+ true
+ end
+
+ def run(file)
+ test_class = find_test_class file
+ puts "Running test to #{test_class}."
+ green = @test_runner.run_test(test_class)
+ @test_runner.run_all_tests if green
+ reset
+ end
+
+ def find_test_class(file)
+ return file.split("/").last.split(".java").last.concat("Test") unless file.include? "Test.java"
+ file.split("/").last.split(".").first
+ end
+
+ def reset
+ @run_at = Time.new
+ end
end