Class: Capybara::Apparition::Inspector
- Inherits:
-
Object
- Object
- Capybara::Apparition::Inspector
- Defined in:
- lib/capybara/apparition/inspector.rb
Constant Summary collapse
- BROWSERS =
TODO: IS this necessary anymore?
%w[chromium chromium-browser google-chrome open].freeze
- 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(scheme) ⇒ Object
- #url(scheme) ⇒ Object
Constructor Details
#initialize(browser = nil, port = DEFAULT_PORT) ⇒ Inspector
Returns a new instance of Inspector.
15 16 17 18 |
# File 'lib/capybara/apparition/inspector.rb', line 15 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.
13 14 15 |
# File 'lib/capybara/apparition/inspector.rb', line 13 def port @port end |
Class Method Details
.browser_binary_exists?(browser) ⇒ Boolean
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/capybara/apparition/inspector.rb', line 38 def self.browser_binary_exists?(browser) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = "#{path}#{File::SEPARATOR}#{browser}#{ext}" return exe if File.executable? exe end end nil end |
.detect_browser ⇒ Object
9 10 11 |
# File 'lib/capybara/apparition/inspector.rb', line 9 def self.detect_browser @browser ||= BROWSERS.find { |name| browser_binary_exists?(name) } # rubocop:disable Naming/MemoizedInstanceVariableName end |
Instance Method Details
#browser ⇒ Object
20 21 22 |
# File 'lib/capybara/apparition/inspector.rb', line 20 def browser @browser ||= self.class.detect_browser end |
#open(scheme) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/capybara/apparition/inspector.rb', line 28 def open(scheme) if browser Process.spawn(browser, url(scheme)) else raise Error, "Could not find a browser executable to open #{url(scheme)}. " \ "You can specify one manually using e.g. `:inspector => 'chromium'` " \ 'as a configuration option for Apparition.' end end |
#url(scheme) ⇒ Object
24 25 26 |
# File 'lib/capybara/apparition/inspector.rb', line 24 def url(scheme) "#{scheme}://localhost:#{port}/" end |