From e270c89d1de28240f997b815707d7024b72c8412 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Wed, 11 Jul 2012 20:14:17 +0100 Subject: [PATCH] move inspector options into phantomjs_options --- lib/capybara/poltergeist/client.rb | 22 ++++++---------------- lib/capybara/poltergeist/driver.rb | 8 +++++++- spec/unit/client_spec.rb | 6 +++--- spec/unit/driver_spec.rb | 2 +- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/lib/capybara/poltergeist/client.rb b/lib/capybara/poltergeist/client.rb index e74b9eb6..6e3bb125 100644 --- a/lib/capybara/poltergeist/client.rb +++ b/lib/capybara/poltergeist/client.rb @@ -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 } @@ -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 diff --git a/lib/capybara/poltergeist/driver.rb b/lib/capybara/poltergeist/driver.rb index b4d8c5a9..6e63629b 100644 --- a/lib/capybara/poltergeist/driver.rb +++ b/lib/capybara/poltergeist/driver.rb @@ -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 diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index e1b1a4f8..1dae30e9 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -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 @@ -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) @@ -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 diff --git a/spec/unit/driver_spec.rb b/spec/unit/driver_spec.rb index b6d3695d..8d92d9ff 100644 --- a/spec/unit/driver_spec.rb +++ b/spec/unit/driver_spec.rb @@ -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