From ad7e7b9efa6d05506bdea59d9aadd875d0823d7a Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Wed, 11 Jul 2012 20:05:10 +0100 Subject: [PATCH] fix steps and tidy a bit --- lib/capybara/poltergeist/client.rb | 16 +++++++--------- lib/capybara/poltergeist/driver.rb | 5 +---- spec/unit/client_spec.rb | 6 +++--- spec/unit/driver_spec.rb | 2 +- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/lib/capybara/poltergeist/client.rb b/lib/capybara/poltergeist/client.rb index e3b690e..e74b9eb 100644 --- a/lib/capybara/poltergeist/client.rb +++ b/lib/capybara/poltergeist/client.rb @@ -10,14 +10,13 @@ module Capybara::Poltergeist client end - attr_reader :pid, :port, :path, :inspector, :width, :height, :phantomjs_options + attr_reader :pid, :port, :path, :inspector, :window_size, :phantomjs_options - def initialize(port, inspector = nil, path = nil, width = 1024, height = 768, phantomjs_options=nil) - @port = port - @inspector = inspector - @path = path || PHANTOMJS_NAME - @width = width - @height = height + def initialize(port, inspector = nil, 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 pid = Process.pid @@ -62,8 +61,7 @@ module Capybara::Poltergeist parts << PHANTOMJS_SCRIPT parts << port - parts << width - parts << height + parts.concat window_size parts end end diff --git a/lib/capybara/poltergeist/driver.rb b/lib/capybara/poltergeist/driver.rb index 0d9ac70..b4d8c5a 100644 --- a/lib/capybara/poltergeist/driver.rb +++ b/lib/capybara/poltergeist/driver.rb @@ -13,9 +13,6 @@ module Capybara::Poltergeist @server = nil @client = nil @headers = {} - if @options[:window_size] - @width, @height = @options[:window_size] - end @app_server = Capybara::Server.new(app) @app_server.boot if Capybara.run_server @@ -34,7 +31,7 @@ module Capybara::Poltergeist end def client - @client ||= Client.start(server.port, inspector, options[:phantomjs], @width, @height, options[:phantomjs_options]) + @client ||= Client.start(server.port, inspector, options[:phantomjs], options[:window_size], options[:phantomjs_options]) end def client_pid diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index 5866f47..e1b1a4f 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -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, 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,9 +41,9 @@ module Capybara::Poltergeist end context "with additional command-line options" do - subject { Client.new(6000, nil, nil, nil, nil, %w[--ignore-ssl-error=yes --load-images=no]) } + subject { Client.new(6000, nil, 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, nil, nil) + Spawn.should_receive(:spawn).with("phantomjs", '--ignore-ssl-error=yes', '--load-images=no', Client::PHANTOMJS_SCRIPT, 6000, 1024, 768) subject.start end end diff --git a/spec/unit/driver_spec.rb b/spec/unit/driver_spec.rb index baa3d61..b6d3695 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) + Client.should_receive(:start).with(64297, nil, nil, [800, 600], nil) subject.client end end