Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape paths correctly + Run specs against JRuby on Appveyor. #131

Merged
merged 3 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Metrics/BlockLength:

Metrics/ClassLength:
Max: 116
Exclude:
- 'lib/webdrivers/system.rb'

Metrics/CyclomaticComplexity:
Max: 8
Expand Down
64 changes: 41 additions & 23 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -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%
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%'
16 changes: 11 additions & 5 deletions lib/webdrivers/chrome_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/webdrivers/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/webdrivers/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion spec/webdrivers/chromedriver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion spec/webdrivers/geckodriver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion spec/webdrivers/i_edriver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions support/install_jruby.ps1
Original file line number Diff line number Diff line change
@@ -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