Class: JsTestDriverServer

Inherits:
Object
  • Object
show all
Defined in:
lib/tasks/js_test_driver/js_test_driver_server.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, pinger, process, jar, browser, sleep_time) ⇒ JsTestDriverServer

Returns a new instance of JsTestDriverServer.



3
4
5
6
7
8
9
10
# File 'lib/tasks/js_test_driver/js_test_driver_server.rb', line 3

def initialize(config, pinger, process, jar, browser, sleep_time)
  @config = config
  @pinger = pinger
  @process = process
  @jar = jar
  @browser = browser
  @sleep_time = sleep_time
end

Instance Method Details

#server_not_runningObject



21
22
23
# File 'lib/tasks/js_test_driver/js_test_driver_server.rb', line 21

def server_not_running
  return !@pinger.is_port_open?('127.0.0.1', @config.port)
end

#start_and_capture_browser(port) ⇒ Object



31
32
33
34
35
36
# File 'lib/tasks/js_test_driver/js_test_driver_server.rb', line 31

def start_and_capture_browser(port)
  capture_url = "http://localhost:#{port}/capture"
  command = @browser.gsub('%1', capture_url)
  @process.create(command)
  sleep @sleep_time
end

#start_if_requiredObject



12
13
14
15
16
17
18
19
# File 'lib/tasks/js_test_driver/js_test_driver_server.rb', line 12

def start_if_required
  @config.reload
  
  if @config.host == 'localhost' && server_not_running
    start_server(@config.port)
    start_and_capture_browser(@config.port)
  end
end

#start_server(port) ⇒ Object



25
26
27
28
29
# File 'lib/tasks/js_test_driver/js_test_driver_server.rb', line 25

def start_server(port)
  command = "java -jar \"#{@jar}\" --port #{port}" #" --browser \"#{@browser}\" "
  @process.create(command)
  sleep @sleep_time
end