Skip to content

Commit

Permalink
move inspector options into phantomjs_options
Browse files Browse the repository at this point in the history
  • Loading branch information
jonleighton committed Jul 11, 2012
1 parent ad7e7b9 commit e270c89
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
22 changes: 6 additions & 16 deletions lib/capybara/poltergeist/client.rb
Expand Up @@ -10,14 +10,13 @@ def self.start(*args)
client
end

attr_reader :pid, :port, :path, :inspector, :window_size, :phantomjs_options
attr_reader :pid, :port, :path, :window_size, :phantomjs_options

def initialize(port, inspector = nil, path = nil, window_size = nil, phantomjs_options = nil)
def initialize(port, path = nil, window_size = nil, phantomjs_options = nil)
@port = port
@inspector = inspector
@path = path || PHANTOMJS_NAME
@window_size = window_size || [1024, 768]
@phantomjs_options = phantomjs_options
@path = path || PHANTOMJS_NAME
@window_size = window_size || [1024, 768]
@phantomjs_options = phantomjs_options || []

pid = Process.pid
at_exit { stop if Process.pid == pid }
Expand Down Expand Up @@ -49,16 +48,7 @@ def restart
def command
@command ||= begin
parts = [path]

if phantomjs_options
parts += phantomjs_options
end

if inspector
parts << "--remote-debugger-port=#{inspector.port}"
parts << "--remote-debugger-autorun=yes"
end

parts.concat phantomjs_options
parts << PHANTOMJS_SCRIPT
parts << port
parts.concat window_size
Expand Down
8 changes: 7 additions & 1 deletion lib/capybara/poltergeist/driver.rb
Expand Up @@ -31,7 +31,13 @@ def server
end

def client
@client ||= Client.start(server.port, inspector, options[:phantomjs], options[:window_size], options[:phantomjs_options])
@client ||= Client.start(server.port, options[:phantomjs], options[:window_size], phantomjs_options)
end

def phantomjs_options
list = options[:phantomjs_options] || []
list += ["--remote-debugger-port=#{inspector.port}", "--remote-debugger-autorun=yes"] if inspector
list
end

def client_pid
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/client_spec.rb
Expand Up @@ -21,7 +21,7 @@ module Capybara::Poltergeist
end

it 'raises an error if phantomjs returns a non-zero exit code' do
subject = Client.new(6000, nil, 'exit 42 && ')
subject = Client.new(6000, 'exit 42 && ')
expect { subject.start }.to raise_error(Error)

begin
Expand All @@ -32,7 +32,7 @@ module Capybara::Poltergeist
end

context "with width and height specified" do
subject { Client.new(6000, nil, nil, [800, 600]) }
subject { Client.new(6000, nil, [800, 600]) }

it "starts phantomjs, passing the width and height through" do
Spawn.should_receive(:spawn).with("phantomjs", Client::PHANTOMJS_SCRIPT, 6000, 800, 600)
Expand All @@ -41,7 +41,7 @@ module Capybara::Poltergeist
end

context "with additional command-line options" do
subject { Client.new(6000, nil, nil, nil, %w[--ignore-ssl-error=yes --load-images=no]) }
subject { Client.new(6000, nil, nil, %w[--ignore-ssl-error=yes --load-images=no]) }
it 'passed additional command-line options to phantomjs' do
Spawn.should_receive(:spawn).with("phantomjs", '--ignore-ssl-error=yes', '--load-images=no', Client::PHANTOMJS_SCRIPT, 6000, 1024, 768)
subject.start
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/driver_spec.rb
Expand Up @@ -57,7 +57,7 @@ module Capybara::Poltergeist
server = stub
server.stub(:port).and_return(64297)
Server.should_receive(:new).and_return(server)
Client.should_receive(:start).with(64297, nil, nil, [800, 600], nil)
Client.should_receive(:start).with(64297, nil, [800, 600], [])
subject.client
end
end
Expand Down

0 comments on commit e270c89

Please sign in to comment.