From 482dfb35e3e4044be1ddd48648195aef89026187 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Fri, 12 Jul 2019 15:40:35 -0700 Subject: [PATCH] Only expand the path if not already absolute --- lib/capybara/selenium/node.rb | 5 ++++- spec/shared_selenium_session.rb | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/capybara/selenium/node.rb b/lib/capybara/selenium/node.rb index 4e39fd8f..b2b40be8 100644 --- a/lib/capybara/selenium/node.rb +++ b/lib/capybara/selenium/node.rb @@ -300,7 +300,10 @@ private def set_file(value) # rubocop:disable Naming/AccessorMethodName path_names = value.to_s.empty? ? [] : value - native.send_keys(Array(path_names).map(&File.method(:expand_path)).join("\n")) + file_names = Array(path_names).map do |pn| + Pathname.new(pn).absolute? ? pn : File.expand_path(pn) + end.join("\n") + native.send_keys(file_names) end def set_content_editable(value) # rubocop:disable Naming/AccessorMethodName diff --git a/spec/shared_selenium_session.rb b/spec/shared_selenium_session.rb index 4937e154..40ed7642 100644 --- a/spec/shared_selenium_session.rb +++ b/spec/shared_selenium_session.rb @@ -323,6 +323,8 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode| end it 'can attach a relative file' do + pending 'Geckdoriver on windows requires alternate file separator which path expansion replaces' if Gem.win_platform? && firefox?(session) + session.visit('/form') session.attach_file('Single Document', 'spec/fixtures/capybara.csv') session.click_button('Upload Single')