Class: AutoTest

Inherits:
Object
  • Object
show all
Defined in:
lib/java_autotest/autotest.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAutoTest

Returns a new instance of AutoTest.



4
5
6
7
8
9
# File 'lib/java_autotest/autotest.rb', line 4

def initialize
  @files = File.find_java_files
  @test_runner = TestRunner.new
  @test_runner.run_all_tests
  @run_at = Time.new
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



2
3
4
# File 'lib/java_autotest/autotest.rb', line 2

def files
  @files
end

#run_atObject

Returns the value of attribute run_at.



2
3
4
# File 'lib/java_autotest/autotest.rb', line 2

def run_at
  @run_at
end

#test_runnerObject

Returns the value of attribute test_runner.



2
3
4
# File 'lib/java_autotest/autotest.rb', line 2

def test_runner
  @test_runner
end

Instance Method Details

#find_test_class(file) ⇒ Object



29
30
31
32
# File 'lib/java_autotest/autotest.rb', line 29

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

#listenObject



11
12
13
14
15
16
17
18
19
# File 'lib/java_autotest/autotest.rb', line 11

def listen
  @files.each do |file|
    if (File.atime(file).to_i > @run_at.to_i)
      run(file) 
      break
    end
  end
  true
end

#resetObject



34
35
36
# File 'lib/java_autotest/autotest.rb', line 34

def reset
  @run_at = Time.new
end

#run(file) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/java_autotest/autotest.rb', line 21

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