Class: Capybara::Poltergeist::Client

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

Constant Summary collapse

PHANTOMJS_SCRIPT =
File.expand_path('../client/compiled/main.js', __FILE__)
PHANTOMJS_VERSION =
"1.4.1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port, path = nil) ⇒ Client

Returns a new instance of Client.



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

def initialize(port, path = nil)
  @port = port
  @path = path || 'phantomjs'
  at_exit { stop }
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#pidObject (readonly)

Returns the value of attribute pid.



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

def pid
  @pid
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

Class Method Details

.start(*args) ⇒ Object



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

def self.start(*args)
  client = new(*args)
  client.start
  client
end

Instance Method Details

#restartObject



31
32
33
34
# File 'lib/capybara/poltergeist/client.rb', line 31

def restart
  stop
  start
end

#startObject



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

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

#stopObject



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

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