Class: Keeptesting::BrowserConsole

Inherits:
Object
  • Object
show all
Defined in:
lib/keeptesting/browser_console.rb

Constant Summary collapse

RESULT_FILE_PATH =
"/tmp/keeptesting-state.txt"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BrowserConsole

Returns a new instance of BrowserConsole.



11
12
13
14
# File 'lib/keeptesting/browser_console.rb', line 11

def initialize(options={})
  watch_files(options)
  start_console
end

Class Method Details

.retrieve_last_test_summaryObject



35
36
37
38
39
40
41
42
43
# File 'lib/keeptesting/browser_console.rb', line 35

def self.retrieve_last_test_summary
  file = File.open(RESULT_FILE_PATH, "rb")
  contents = file.read

  result = contents.lines.first
  output = contents.lines.to_a[1..-1].join("\n")
  
  return result, output
end

Instance Method Details

#start_consoleObject



69
70
71
72
73
# File 'lib/keeptesting/browser_console.rb', line 69

def start_console      
  webconsole_path = File.dirname(__FILE__) + '/../../webconsole.rb'
  puts "\n\n\nWeb console ready at http://localhost:5000\n\n\n"
  puts `ruby #{webconsole_path} -e development -p 5000`
end

#store_last_test_summary(success, output) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/keeptesting/browser_console.rb', line 24

def store_last_test_summary(success, output)
  File.open RESULT_FILE_PATH, "w" do |filebody|
    if success
      filebody.write("Success\n")
    else
      filebody.write("Failure\n")
    end
    filebody.write(output)
  end
end

#store_running_statusObject



18
19
20
21
22
# File 'lib/keeptesting/browser_console.rb', line 18

def store_running_status
  File.open RESULT_FILE_PATH, "w" do |filebody|
      filebody.write("Running tests...\n")
  end
end

#testrun(options) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/keeptesting/browser_console.rb', line 45

def testrun(options)
  store_running_status
  cmd = options[:test_command]
  test_output = `#{cmd} 2>&1`
  test_succeeded = Keeptesting::Common::test_success?(test_output, options[:failure_regex])
  store_last_test_summary(test_succeeded, test_output)
end

#watch_files(options) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/keeptesting/browser_console.rb', line 53

def watch_files(options)
  Thread.new do
    console = self
    console.testrun(options)
    FSSM.monitor do
      options[:watched_paths].each do |watched_path|
        path watched_path do
          update {|base, relative| console.testrun(options)}
          delete {|base, relative| console.testrun(options)}
          create {|base, relative| console.testrun(options)}
        end
      end
    end
  end
end