Class: Capybara::Poltergeist::Inspector
- Inherits:
-
Object
- Object
- Capybara::Poltergeist::Inspector
- Defined in:
- lib/capybara/poltergeist/inspector.rb
Constant Summary collapse
- BROWSERS =
%w(chromium chromium-browser google-chrome open)
- DEFAULT_PORT =
9664
Instance Attribute Summary collapse
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Class Method Summary collapse
Instance Method Summary collapse
- #browser ⇒ Object
-
#initialize(browser = nil, port = DEFAULT_PORT) ⇒ Inspector
constructor
A new instance of Inspector.
- #open ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(browser = nil, port = DEFAULT_PORT) ⇒ Inspector
Returns a new instance of Inspector.
12 13 14 15 |
# File 'lib/capybara/poltergeist/inspector.rb', line 12 def initialize(browser = nil, port = DEFAULT_PORT) @browser = browser.respond_to?(:to_str) ? browser : nil @port = port end |
Instance Attribute Details
#port ⇒ Object (readonly)
Returns the value of attribute port.
10 11 12 |
# File 'lib/capybara/poltergeist/inspector.rb', line 10 def port @port end |
Class Method Details
.browser_binary_exists?(browser) ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/capybara/poltergeist/inspector.rb', line 35 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 |
.detect_browser ⇒ Object
6 7 8 |
# File 'lib/capybara/poltergeist/inspector.rb', line 6 def self.detect_browser @browser ||= BROWSERS.find { |name| browser_binary_exists?(name) } end |
Instance Method Details
#browser ⇒ Object
17 18 19 |
# File 'lib/capybara/poltergeist/inspector.rb', line 17 def browser @browser ||= self.class.detect_browser end |
#open ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/capybara/poltergeist/inspector.rb', line 25 def open if browser Process.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 |
#url ⇒ Object
21 22 23 |
# File 'lib/capybara/poltergeist/inspector.rb', line 21 def url "//localhost:#{port}/" end |