Class: Capybara::Poltergeist::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/poltergeist/client.rb

Constant Summary collapse

PHANTOM_SCRIPT =
File.expand_path('../client/compiled/main.js', __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port, path = nil) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
# File 'lib/capybara/poltergeist/client.rb', line 9

def initialize(port, path = nil)
  @port = port
  @path = path || 'phantomjs'

  start
  at_exit { stop }
end

Instance Attribute Details

#errObject (readonly)

Returns the value of attribute err.



7
8
9
# File 'lib/capybara/poltergeist/client.rb', line 7

def err
  @err
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/capybara/poltergeist/client.rb', line 7

def path
  @path
end

#pidObject (readonly)

Returns the value of attribute pid.



7
8
9
# File 'lib/capybara/poltergeist/client.rb', line 7

def pid
  @pid
end

#portObject (readonly)

Returns the value of attribute port.



7
8
9
# File 'lib/capybara/poltergeist/client.rb', line 7

def port
  @port
end

#threadObject (readonly)

Returns the value of attribute thread.



7
8
9
# File 'lib/capybara/poltergeist/client.rb', line 7

def thread
  @thread
end

Instance Method Details

#restartObject



25
26
27
28
# File 'lib/capybara/poltergeist/client.rb', line 25

def restart
  stop
  start
end

#startObject



17
18
19
# File 'lib/capybara/poltergeist/client.rb', line 17

def start
  @pid = Kernel.spawn("#{path} #{PHANTOM_SCRIPT} #{port}")
end

#stopObject



21
22
23
# File 'lib/capybara/poltergeist/client.rb', line 21

def stop
  Process.kill('TERM', pid)
end