mirror of
https://github.com/teampoltergeist/poltergeist.git
synced 2022-11-09 12:05:00 -05:00

posix-spawn relies on a C extension. This does work under JRuby, but it won't work on Travis CI as they disallow JRuby C extensions, as they are considered to not be a good practice. Instead we are using either Process.spawn on Ruby 1.9, or the childprocess gem on Ruby 1.8. childprocess uses native JVM APIs on JRuby, and fork+exec on others.
35 lines
864 B
Ruby
35 lines
864 B
Ruby
module Capybara::Poltergeist
|
|
class Inspector
|
|
BROWSERS = %w(chromium chromium-browser google-chrome safari)
|
|
|
|
def self.detect_browser
|
|
@browser ||= BROWSERS.find { |name| system("which #{name} &>/dev/null") }
|
|
end
|
|
|
|
def initialize(browser = nil)
|
|
@browser = browser.respond_to?(:to_str) ? browser : nil
|
|
end
|
|
|
|
def browser
|
|
@browser ||= self.class.detect_browser
|
|
end
|
|
|
|
def port
|
|
@port ||= Util.find_available_port
|
|
end
|
|
|
|
def url
|
|
"http://localhost:#{port}/"
|
|
end
|
|
|
|
def open
|
|
if browser
|
|
Spawn.spawn(browser, url)
|
|
else
|
|
raise Error, "Could not find a browser executable to open #{url}. " \
|
|
"You can specify one manually using e.g. `:inspector => 'chromium'` " \
|
|
"as a configuration option for Poltergeist."
|
|
end
|
|
end
|
|
end
|
|
end
|