diff --git a/.rubocop.yml b/.rubocop.yml index 06a82fc3..cc37741e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -26,6 +26,8 @@ Metrics/BlockLength: Metrics/ClassLength: Max: 116 + Exclude: + - 'lib/webdrivers/system.rb' Metrics/CyclomaticComplexity: Max: 8 diff --git a/appveyor.yml b/appveyor.yml index ba6b613f..7c2b4424 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,23 +1,41 @@ -build: off -cache: - - vendor/bundle -environment: - matrix: - - RUBY_VERSION: 24 - RAKE_TASK: spec - - RUBY_VERSION: 24 - RAKE_TASK: rubocop - - RUBY_VERSION: 25 - RAKE_TASK: spec - - RUBY_VERSION: 26 - RAKE_TASK: spec -install: - - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH% - - bundle config --local path vendor/bundle - - bundle install -before_test: - - ruby -v - - gem -v - - bundle -v -test_script: - - bundle exec rake %RAKE_TASK% \ No newline at end of file +build: off +cache: + - vendor/bundle +environment: + matrix: + - RUBY_VERSION: Ruby24 + RUBY_BIN: ruby + RAKE_TASK: spec + SCRIPT_CONTEXT: bundle exec + - RUBY_VERSION: Ruby24 + RUBY_BIN: ruby + RAKE_TASK: rubocop + SCRIPT_CONTEXT: bundle exec + - RUBY_VERSION: Ruby25 + RUBY_BIN: ruby + RAKE_TASK: spec + SCRIPT_CONTEXT: bundle exec + - RUBY_VERSION: Ruby26 + RUBY_BIN: ruby + RAKE_TASK: spec + SCRIPT_CONTEXT: bundle exec + - RUBY_VERSION: jruby-9.2.7.0 + RUBY_BIN: jruby + RAKE_TASK: spec + SCRIPT_CONTEXT: jruby -G -S +install: + - ps: | + if ($env:RUBY_BIN -eq 'jruby') + { + support\install_jruby.ps1 + } + - set PATH=C:\%RUBY_VERSION%\bin;%PATH% + - '%RUBY_BIN% -S gem update --system' + - '%RUBY_BIN% -S gem install bundler' + - '%RUBY_BIN% -S bundle install' +before_test: + - '%RUBY_BIN% -v' + - '%RUBY_BIN% -S gem -v' + - '%RUBY_BIN% -S bundle -v' +test_script: + - '%SCRIPT_CONTEXT% rake %RAKE_TASK%' \ No newline at end of file diff --git a/lib/webdrivers/chrome_finder.rb b/lib/webdrivers/chrome_finder.rb index 68710b49..a7f57ba0 100644 --- a/lib/webdrivers/chrome_finder.rb +++ b/lib/webdrivers/chrome_finder.rb @@ -23,7 +23,13 @@ def win_location directories.each do |dir| envs.each do |root| option = "#{ENV[root]}\\#{dir}\\#{file}" - return option if File.exist?(option) + next unless File.exist?(option) + + # Fix for JRuby on Windows - #41 and #130. + # Escape space and parenthesis with backticks. + option = option.gsub(/([\s()])/, '`\1') if RUBY_PLATFORM == 'java' + + return System.escape_path(option) end end end @@ -36,7 +42,7 @@ def mac_location directories.each do |dir| files.each do |file| option = "#{dir}/#{file}" - return option if File.exist?(option) + return System.escape_path(option) if File.exist?(option) end end end @@ -48,7 +54,7 @@ def linux_location directories.each do |dir| files.each do |file| option = "#{dir}/#{file}" - return option if File.exist?(option) + return System.escape_path(option) if File.exist?(option) end end end @@ -58,11 +64,11 @@ def win_version(location) end def linux_version(location) - System.call("#{Shellwords.escape location} --product-version")&.strip + System.call("#{location} --product-version")&.strip end def mac_version(location) - System.call("#{Shellwords.escape location} --version")&.strip + System.call("#{location} --version")&.strip end end end diff --git a/lib/webdrivers/common.rb b/lib/webdrivers/common.rb index 28dd7e12..504f4a99 100644 --- a/lib/webdrivers/common.rb +++ b/lib/webdrivers/common.rb @@ -105,7 +105,7 @@ def remove # # @return [String] def driver_path - File.join System.install_dir, file_name + System.escape_path File.join(System.install_dir, file_name) end private diff --git a/lib/webdrivers/system.rb b/lib/webdrivers/system.rb index 930a6905..13a0a9d6 100644 --- a/lib/webdrivers/system.rb +++ b/lib/webdrivers/system.rb @@ -149,6 +149,12 @@ def call(cmd) Webdrivers.logger.debug "making System call: #{cmd}" `#{cmd}` end + + def escape_path(path) + return path.tr('/', '\\') if platform == 'win' # Windows + + Shellwords.escape(path) # Linux and macOS + end end end end diff --git a/spec/webdrivers/chromedriver_spec.rb b/spec/webdrivers/chromedriver_spec.rb index a4c4a748..39310334 100644 --- a/spec/webdrivers/chromedriver_spec.rb +++ b/spec/webdrivers/chromedriver_spec.rb @@ -252,7 +252,9 @@ describe '#driver_path' do it 'returns full location of binary' do - expect(chromedriver.driver_path).to match("#{File.join(ENV['HOME'])}/.webdrivers/chromedriver") + expected_bin = "chromedriver#{'.exe' if Selenium::WebDriver::Platform.windows?}" + expected_path = Webdrivers::System.escape_path("#{File.join(ENV['HOME'])}/.webdrivers/#{expected_bin}") + expect(chromedriver.driver_path).to eq(expected_path) end end end diff --git a/spec/webdrivers/geckodriver_spec.rb b/spec/webdrivers/geckodriver_spec.rb index d526fd50..a1ebe776 100644 --- a/spec/webdrivers/geckodriver_spec.rb +++ b/spec/webdrivers/geckodriver_spec.rb @@ -204,7 +204,9 @@ describe '#driver_path' do it 'returns full location of binary' do - expect(geckodriver.driver_path).to match("#{File.join(ENV['HOME'])}/.webdrivers/geckodriver") + expected_bin = "geckodriver#{'.exe' if Selenium::WebDriver::Platform.windows?}" + expected_path = Webdrivers::System.escape_path("#{File.join(ENV['HOME'])}/.webdrivers/#{expected_bin}") + expect(geckodriver.driver_path).to eq(expected_path) end end end diff --git a/spec/webdrivers/i_edriver_spec.rb b/spec/webdrivers/i_edriver_spec.rb index 5e396df8..d486d5fc 100644 --- a/spec/webdrivers/i_edriver_spec.rb +++ b/spec/webdrivers/i_edriver_spec.rb @@ -186,7 +186,8 @@ describe '#driver_path' do it 'returns full location of binary' do - expect(iedriver.driver_path).to eq("#{File.join(ENV['HOME'])}/.webdrivers/IEDriverServer.exe") + expected_path = Webdrivers::System.escape_path("#{File.join(ENV['HOME'])}/.webdrivers/IEDriverServer.exe") + expect(iedriver.driver_path).to eq(expected_path) end end end diff --git a/support/install_jruby.ps1 b/support/install_jruby.ps1 new file mode 100644 index 00000000..4413b841 --- /dev/null +++ b/support/install_jruby.ps1 @@ -0,0 +1,7 @@ +$downloadLink = "https://repo1.maven.org/maven2/org/jruby/jruby-dist/9.2.7.0/jruby-dist-9.2.7.0-bin.zip" +$zipPath = "c:\jruby-dist-9.2.7.0-bin.zip" + +Write-Host "Installing $($env:RUBY_VERSION)" -ForegroundColor cyan +appveyor DownloadFile "$($downloadLink)" -FileName "$($zipPath)" +7z x "$($zipPath)" -oc:\ -y # Unzip to c:\ +Write-Host "JRuby installed.`n" -ForegroundColor green