This repository has been archived by the owner on Nov 27, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract inspector code to a separate class. Implement Driver#debug an…
…d Driver#pause methods for using inspector.
- Loading branch information
1 parent
a094273
commit 8d9b224
Showing
6 changed files
with
114 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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 | ||
Kernel.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'spec_helper' | ||
|
||
module Capybara::Poltergeist | ||
describe Inspector do | ||
it 'detects a browser by default' do | ||
Inspector.stub(:detect_browser => 'chromium') | ||
Inspector.new.browser.should == 'chromium' | ||
Inspector.new(true).browser.should == 'chromium' | ||
end | ||
|
||
it 'allows a browser to be specified' do | ||
Inspector.new('foo').browser.should == 'foo' | ||
end | ||
|
||
it 'finds a port to run on' do | ||
subject.port.should_not be_nil | ||
end | ||
|
||
it 'remembers the port' do | ||
subject.port.should == subject.port | ||
end | ||
|
||
it 'has a url' do | ||
subject.stub(:port => 1234) | ||
subject.url.should == "http://localhost:1234/" | ||
end | ||
|
||
it 'can be opened' do | ||
subject.stub(:port => 1234, :browser => 'chromium') | ||
Kernel.should_receive(:spawn).with("chromium http://localhost:1234/") | ||
subject.open | ||
end | ||
|
||
it 'raises an error on open when the browser is unknown' do | ||
subject.stub(:port => 1234, :browser => nil) | ||
expect { subject.open }.to raise_error(Capybara::Poltergeist::Error) | ||
end | ||
end | ||
end |