class Tork::Driver

Constants

ALL_TEST_FILE_GLOBS
REABSORB_FILE_GREPS
TEST_FILE_GLOBBERS

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/tork/driver.rb, line 14
def initialize
  super
  Tork.config :driver
end

Public Instance Methods

loop() click to toggle source
Calls superclass method
# File lib/tork/driver.rb, line 19
def loop
  @herald = popen('tork-herald')
  @engine = popen('tork-engine')
  super
ensure
  pclose @herald
  pclose @engine
end
test!() click to toggle source
# File lib/tork/driver.rb, line 28
def test!
  test_files_found = false
  Dir.glob(ALL_TEST_FILE_GLOBS) do |test_file|
    next if overhead_file? test_file
    test test_file
    test_files_found = true
  end
  tell @client, 'There are no test files to run.' unless test_files_found
end

Protected Instance Methods

recv(client, message) click to toggle source
Calls superclass method
# File lib/tork/driver.rb, line 49
def recv client, message
  case client
  when @engine
    send @clients, message # propagate downstream

  when @herald
    message.each do |changed_file|
      # make sure this path works with the GREPS and GLOBBERS below
      # by squashing relative directory traversal and extra slashes
      changed_file = Pathname.new(changed_file).cleanpath.to_s

      # reabsorb text execution overhead if overhead files changed
      if overhead_file? changed_file
        send @clients, [:boot!, changed_file]
        boot!
      else
        run_non_overhead_test_files find_dependent_test_files(changed_file)
      end
    end

  else
    super
  end
end

Private Instance Methods

find_dependent_test_files(source_file, results=Set.new) click to toggle source
# File lib/tork/driver.rb, line 90
def find_dependent_test_files source_file, results=Set.new
  TEST_FILE_GLOBBERS.each do |regexp, globber|
    if regexp =~ source_file and globs = globber.call($~)
      Dir.glob(*globs) do |dependent_file|
        if results.add? dependent_file
          find_dependent_test_files dependent_file, results
        end
      end
    end
  end
  results
end
overhead_file?(file) click to toggle source
# File lib/tork/driver.rb, line 80
def overhead_file? file
  REABSORB_FILE_GREPS.any? do |pattern|
    if pattern.kind_of? Regexp
      pattern =~ file
    else
      pattern == file
    end
  end
end
run_non_overhead_test_files(test_files) click to toggle source
# File lib/tork/driver.rb, line 76
def run_non_overhead_test_files test_files
  test test_files.reject {|f| overhead_file? f }
end