From 12e34ec8c3b7af53de5d9dc2cbb4c3ef71e8176c Mon Sep 17 00:00:00 2001 From: Oli Peate Date: Wed, 11 May 2022 09:52:49 +0100 Subject: [PATCH 1/2] Support custom save_path option Allows paths other than Capybara.save_path to be specified --- lib/capybara/cuprite/driver.rb | 3 +-- spec/lib/driver_spec.rb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 spec/lib/driver_spec.rb diff --git a/lib/capybara/cuprite/driver.rb b/lib/capybara/cuprite/driver.rb index cf6c5723..83d90e21 100644 --- a/lib/capybara/cuprite/driver.rb +++ b/lib/capybara/cuprite/driver.rb @@ -32,8 +32,7 @@ def initialize(app, options = {}) @screen_size = @options.delete(:screen_size) @screen_size ||= DEFAULT_MAXIMIZE_SCREEN_SIZE - - @options[:save_path] = File.expand_path(Capybara.save_path) if Capybara.save_path + @options[:save_path] ||= File.expand_path(Capybara.save_path) if Capybara.save_path ENV["FERRUM_DEBUG"] = "true" if ENV["CUPRITE_DEBUG"] diff --git a/spec/lib/driver_spec.rb b/spec/lib/driver_spec.rb new file mode 100644 index 00000000..169be96d --- /dev/null +++ b/spec/lib/driver_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +describe Capybara::Cuprite::Driver do + describe "save_path configuration" do + it "defaults to the Capybara save path" do + driver = with_capybara_save_path("/tmp/capybara-save-path") do + described_class.new(nil) + end + + expect(driver.browser.options).to include(save_path: "/tmp/capybara-save-path") + end + + it "allows a custom path to be specified" do + custom_path = Dir.mktmpdir + + driver = with_capybara_save_path("/tmp/capybara-save-path") do + described_class.new(nil, { save_path: custom_path }) + end + + expect(driver.browser.options).to include(save_path: custom_path) + end + end + + private + + def with_capybara_save_path(path) + original_capybara_save_path = Capybara.save_path + Capybara.save_path = path + yield + ensure + Capybara.save_path = original_capybara_save_path + end +end From 03906eddc4c1059552a74e48af963fea8157b40f Mon Sep 17 00:00:00 2001 From: Peter Singh Date: Wed, 16 Nov 2022 12:13:56 +0000 Subject: [PATCH 2/2] Update tests, cast options to hash for testing --- spec/lib/driver_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/lib/driver_spec.rb b/spec/lib/driver_spec.rb index 169be96d..349d41f9 100644 --- a/spec/lib/driver_spec.rb +++ b/spec/lib/driver_spec.rb @@ -7,7 +7,7 @@ described_class.new(nil) end - expect(driver.browser.options).to include(save_path: "/tmp/capybara-save-path") + expect(driver.browser.options.to_h).to include(save_path: "/tmp/capybara-save-path") end it "allows a custom path to be specified" do @@ -17,7 +17,7 @@ described_class.new(nil, { save_path: custom_path }) end - expect(driver.browser.options).to include(save_path: custom_path) + expect(driver.browser.options.to_h).to include(save_path: custom_path) end end