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

detect browser by parsing $PATH env var instead of relying on unreliable which

This commit is contained in:
Niklas Hofer 2012-09-15 18:22:08 +02:00
parent d3a8849c24
commit c7daae9f28

View file

@ -3,7 +3,7 @@ module Capybara::Poltergeist
BROWSERS = %w(chromium chromium-browser google-chrome open)
def self.detect_browser
@browser ||= BROWSERS.find { |name| system("which #{name} &>/dev/null") }
@browser ||= BROWSERS.find { |name| browser_binary_exists?(name) }
end
def initialize(browser = nil)
@ -31,5 +31,16 @@ module Capybara::Poltergeist
"as a configuration option for Poltergeist."
end
end
def self.browser_binary_exists?(browser)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = "#{path}#{File::SEPARATOR}#{browser}#{ext}"
return exe if File.executable? exe
}
end
return nil
end
end
end