Class: Qunit::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/qunit/runner.rb,
lib/qunit/runner/version.rb

Constant Summary collapse

VERSION =
"0.0.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Runner

Returns a new instance of Runner.



16
17
18
19
20
21
22
23
# File 'lib/qunit/runner.rb', line 16

def initialize(url)
  $stdout.sync = true
  @should_exit = false
  @exit_status = 0
  @test_url = url
  @logger = Qunit::Logger
  @parser = Qunit::Parser.new
end

Instance Attribute Details

#exit_statusObject (readonly)

Returns the value of attribute exit_status.



12
13
14
# File 'lib/qunit/runner.rb', line 12

def exit_status
  @exit_status
end

#loggerObject (readonly)

Returns the value of attribute logger.



14
15
16
# File 'lib/qunit/runner.rb', line 14

def logger
  @logger
end

#should_exitObject (readonly)

Returns the value of attribute should_exit.



11
12
13
# File 'lib/qunit/runner.rb', line 11

def should_exit
  @should_exit
end

#test_urlObject (readonly)

Returns the value of attribute test_url.



13
14
15
# File 'lib/qunit/runner.rb', line 13

def test_url
  @test_url
end

Instance Method Details

#run(load_timeout = 10000) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/qunit/runner.rb', line 25

def run(load_timeout = 10000)
  root = File.dirname(File.dirname(__FILE__))
  qunit_bridge = File.join root, 'vendor', 'js', 'qunit_bridge.js'
  phantom_bridge = File.join root, 'vendor', 'js', 'phantom_bridge.js'
  opts = {
    timeout: load_timeout,
    inject: qunit_bridge
  }
  cmd = Shellwords.join [
    'phantomjs',
    '--load-images=false',
    phantom_bridge,
    '/dev/stdout',
    @test_url,
    opts.to_json
  ]
  print_banner
  Open3.popen3(cmd) do |i, o, e, t|
    i.close
    begin
      while line = o.gets and !@should_exit
        @should_exit, @exit_status = @parser.parse line
      end
      safe_kill t.pid
    rescue Exception
      safe_kill t.pid
      raise
    end
  end
  exit @exit_status || 1
end

#safe_kill(pid) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/qunit/runner.rb', line 57

def safe_kill(pid)
  begin
    Process.kill("KILL", pid)
    true
  rescue
    false
  end
end