Class: Tork::Engine

Inherits:
Server show all
Defined in:
lib/tork/engine.rb

Instance Method Summary collapse

Methods inherited from Server

address, #quit

Constructor Details

#initializeEngine

Returns a new instance of Engine.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tork/engine.rb', line 9

def initialize
  super
  Tork.config :engine

  @lines_by_file = {}
  @passed_test_files = Set.new
  @failed_test_files = Set.new
  @running_test_files = Set.new
  @recently_passed_test_files = Set.new
  @recently_failed_test_files = Set.new
end

Instance Method Details

#boot!Object



28
29
30
31
32
33
34
35
36
# File 'lib/tork/engine.rb', line 28

def boot!
  @master.reconnect

  # resume running all previously running test files and
  # all previously failed test files in the new master
  resumable = @running_test_files + @failed_test_files
  @running_test_files.clear
  test resumable
end

#fail!Object



87
88
89
90
91
92
93
# File 'lib/tork/engine.rb', line 87

def fail!
  if @failed_test_files.empty?
    tell @client, 'There are no failed test files to re-run.'
  else
    test @failed_test_files
  end
end

#fail?Boolean

Returns:

  • (Boolean)


95
96
97
98
99
100
101
# File 'lib/tork/engine.rb', line 95

def fail?
  if @failed_test_files.empty?
    tell @client, 'There are no failed test files to list.'
  else
    tell @client, @failed_test_files.sort, false
  end
end

#loopObject



21
22
23
24
25
26
# File 'lib/tork/engine.rb', line 21

def loop
  @master = popen('tork-master')
  super
ensure
  pclose @master
end

#pass!Object



71
72
73
74
75
76
77
# File 'lib/tork/engine.rb', line 71

def pass!
  if @passed_test_files.empty?
    tell @client, 'There are no passed test files to re-run.'
  else
    test @passed_test_files
  end
end

#pass?Boolean

Returns:

  • (Boolean)


79
80
81
82
83
84
85
# File 'lib/tork/engine.rb', line 79

def pass?
  if @passed_test_files.empty?
    tell @client, 'There are no passed test files to list.'
  else
    tell @client, @passed_test_files.sort, false
  end
end

#stop(signal = nil) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/tork/engine.rb', line 62

def stop signal=nil
  if @running_test_files.empty?
    tell @client, 'There are no running test files to stop.'
  else
    send @master, [:stop, signal].compact
    @running_test_files.clear
  end
end

#test(test_file, *line_numbers) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/tork/engine.rb', line 38

def test test_file, *line_numbers
  # a list of tests was passed in for the first argument
  if test_file.respond_to? :each and line_numbers.empty?
    test_file.each {|args| test(*args) }

  elsif File.exist? test_file and @running_test_files.add? test_file
    if line_numbers.empty?
      line_numbers = find_changed_line_numbers(test_file)
    else
      line_numbers.map!(&:to_i)
      line_numbers.clear if line_numbers.any?(&:zero?)
    end
    send @master, [:test, test_file, line_numbers]
  end
end

#test?Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
# File 'lib/tork/engine.rb', line 54

def test?
  if @running_test_files.empty?
    tell @client, 'There are no running test files to list.'
  else
    tell @client, @running_test_files.sort, false
  end
end