All Files
(35.97%
covered at
0.35
hits/line)
4 files in total.
303 relevant lines.
109 lines covered and
194 lines missed
-
# frozen_string_literal: true
-
-
1
require '../spec_helper'
-
-
1
describe Webdrivers::ChromeFinder do
-
1
let(:chrome_finder) { described_class }
-
-
1
context 'when the user relies on the gem to figure out the location of Chrome' do
-
1
it 'determines the location correctly based on the current OS' do
-
expect(chrome_finder.send("#{Webdrivers::System.platform}_location")).not_to be_nil
-
end
-
end
-
-
1
context 'when user provides a path to the Chrome binary' do
-
1
it 'uses Selenium::WebDriver::Chrome.path when it is defined' do
-
Selenium::WebDriver::Chrome.path = chrome_finder.send("#{Webdrivers::System.platform}_location")
-
allow(chrome_finder).to receive(:win_location)
-
allow(chrome_finder).to receive(:mac_location)
-
allow(chrome_finder).to receive(:linux_location)
-
chrome_finder.version
-
expect(chrome_finder).not_to have_received(:win_location)
-
expect(chrome_finder).not_to have_received(:mac_location)
-
expect(chrome_finder).not_to have_received(:linux_location)
-
end
-
-
1
it "uses ENV['WD_CHROME_PATH'] when it is defined" do
-
loc_method = "#{Webdrivers::System.platform}_location"
-
allow(ENV).to receive(:[]).with('WD_CHROME_PATH').and_return(chrome_finder.send(loc_method))
-
allow(chrome_finder).to receive(:win_location)
-
allow(chrome_finder).to receive(:mac_location)
-
allow(chrome_finder).to receive(:linux_location)
-
chrome_finder.version
-
expect(chrome_finder).not_to have_received(:win_location)
-
expect(chrome_finder).not_to have_received(:mac_location)
-
expect(chrome_finder).not_to have_received(:linux_location)
-
end
-
-
1
it 'uses Selenium::WebDriver::Chrome.path over WD_CHROME_PATH' do
-
loc = chrome_finder.send("#{Webdrivers::System.platform}_location")
-
allow(ENV).to receive(:[]).with('WD_CHROME_PATH').and_return('my_wd_chrome_path')
-
Selenium::WebDriver::Chrome.path = loc
-
chrome_finder.version
-
expect(ENV).not_to have_received(:[]).with('WD_CHROME_PATH')
-
end
-
-
1
it 'escapes the user given Chrome path' do
-
platform = Webdrivers::System.platform
-
loc = chrome_finder.send("#{platform}_location")
-
loc = loc.gsub(/([\s()])/, '`\1') if using_jruby_on_windows?
-
allow(Webdrivers::System).to receive(:escape_path).with(loc).and_return(Webdrivers::System.escape_path(loc))
-
chrome_finder.send("#{platform}_version", loc)
-
expect(Webdrivers::System).to have_received(:escape_path).with(loc)
-
end
-
-
1
it 'properly escapes the Chrome path when using JRuby on Windows', if: using_jruby_on_windows? do
-
allow(String).to receive(:gsub)
-
platform = Webdrivers::System.platform
-
loc = chrome_finder.send("#{platform}_location")
-
chrome_finder.send("#{platform}_version", loc)
-
expect(String).to have_received(:gsub).with(/([\s()])/, '`\1')
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require '../spec_helper'
-
-
1
describe Webdrivers::IEdriver do
-
1
let(:iedriver) { described_class }
-
-
1
before do
-
iedriver.remove
-
iedriver.required_version = nil
-
end
-
-
1
describe '#update' do
-
1
context 'when evaluating #correct_binary?' do
-
1
it 'does not download when latest version and current version match' do
-
allow(iedriver).to receive(:latest_version).and_return(Gem::Version.new('0.3.0'))
-
allow(iedriver).to receive(:current_version).and_return(Gem::Version.new('0.3.0'))
-
-
iedriver.update
-
-
expect(iedriver.send(:exists?)).to be false
-
end
-
-
1
it 'does not download when offline, but binary exists' do
-
allow(Webdrivers::System).to receive(:call).and_return('something IEDriverServer.exe 3.5.1 something else')
-
allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
-
allow(iedriver).to receive(:exists?).and_return(true)
-
-
iedriver.update
-
-
expect(File.exist?(iedriver.driver_path)).to be false
-
end
-
-
1
it 'raises ConnectionError when offline, and no binary exists' do
-
allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
-
allow(iedriver).to receive(:exists?).and_return(false)
-
-
expect { iedriver.update }.to raise_error(Webdrivers::ConnectionError)
-
end
-
end
-
-
1
context 'when correct binary is found' do
-
1
before { allow(iedriver).to receive(:correct_binary?).and_return(true) }
-
-
1
it 'does not download' do
-
iedriver.update
-
-
expect(iedriver.current_version).to be_nil
-
end
-
-
1
it 'does not raise exception if offline' do
-
allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
-
-
iedriver.update
-
-
expect(iedriver.current_version).to be_nil
-
end
-
end
-
-
1
context 'when correct binary is not found' do
-
1
before { allow(iedriver).to receive(:correct_binary?).and_return(false) }
-
-
1
it 'downloads binary' do
-
iedriver.update
-
-
expect(File.exist?(iedriver.driver_path)).to eq true
-
end
-
-
1
it 'raises ConnectionError if offline' do
-
allow(Net::HTTP).to receive(:get_response).and_raise(SocketError)
-
-
msg = %r{Can not reach https://selenium-release.storage.googleapis.com/}
-
expect { iedriver.update }.to raise_error(Webdrivers::ConnectionError, msg)
-
end
-
end
-
end
-
-
1
describe '#current_version' do
-
1
it 'returns nil if binary does not exist on the system' do
-
allow(iedriver).to receive(:driver_path).and_return('')
-
-
expect(iedriver.current_version).to be_nil
-
end
-
-
1
it 'returns a Gem::Version instance if binary is on the system' do
-
allow(iedriver).to receive(:exists?).and_return(true)
-
-
return_value = 'something IEDriverServer.exe 3.5.1 something else'
-
-
allow(Webdrivers::System).to receive(:call).with("#{iedriver.driver_path} --version").and_return return_value
-
-
expect(iedriver.current_version).to eq Gem::Version.new('3.5.1')
-
end
-
end
-
-
1
describe '#latest_version' do
-
1
it 'finds the latest version from parsed hash' do
-
base = 'https://selenium-release.storage.googleapis.com/'
-
hash = {Gem::Version.new('3.4.0') => "#{base}/3.4/IEDriverServer_Win32_3.4.0.zip",
-
Gem::Version.new('3.5.0') => "#{base}/3.5/IEDriverServer_Win32_3.5.0.zip",
-
Gem::Version.new('3.5.1') => "#{base}/3.5/IEDriverServer_Win32_3.5.1.zip"}
-
allow(iedriver).to receive(:downloads).and_return(hash)
-
-
expect(iedriver.latest_version).to eq Gem::Version.new('3.5.1')
-
end
-
-
1
it 'correctly parses the downloads page' do
-
expect(iedriver.send(:downloads)).not_to be_empty
-
end
-
-
1
it 'creates cached file' do
-
allow(Webdrivers::Network).to receive(:get).and_return('3.4.0')
-
-
iedriver.latest_version
-
expect(File.exist?("#{Webdrivers::System.install_dir}/IEDriverServer.version")).to eq true
-
end
-
-
1
it 'does not make network call if cache is valid' do
-
allow(Webdrivers).to receive(:cache_time).and_return(3600)
-
Webdrivers::System.cache_version('IEDriverServer', '3.4.0')
-
allow(Webdrivers::Network).to receive(:get)
-
-
expect(iedriver.latest_version).to eq Gem::Version.new('3.4.0')
-
-
expect(Webdrivers::Network).not_to have_received(:get)
-
end
-
-
1
it 'makes a network call if cache is expired' do
-
Webdrivers::System.cache_version('IEDriverServer', '3.4.0')
-
base = 'https://selenium-release.storage.googleapis.com/'
-
hash = {Gem::Version.new('3.4.0') => "#{base}/3.4/IEDriverServer_Win32_3.4.0.zip",
-
Gem::Version.new('3.5.0') => "#{base}/3.5/IEDriverServer_Win32_3.5.0.zip",
-
Gem::Version.new('3.5.1') => "#{base}/3.5/IEDriverServer_Win32_3.5.1.zip"}
-
allow(iedriver).to receive(:downloads).and_return(hash)
-
allow(Webdrivers::System).to receive(:valid_cache?)
-
-
expect(iedriver.latest_version).to eq Gem::Version.new('3.5.1')
-
expect(iedriver).to have_received(:downloads)
-
expect(Webdrivers::System).to have_received(:valid_cache?)
-
end
-
end
-
-
1
describe '#required_version=' do
-
1
it 'returns the version specified as a Float' do
-
iedriver.required_version = 0.12
-
-
expect(iedriver.required_version).to eq Gem::Version.new('0.12')
-
end
-
-
1
it 'returns the version specified as a String' do
-
iedriver.required_version = '0.12.1'
-
-
expect(iedriver.required_version).to eq Gem::Version.new('0.12.1')
-
end
-
end
-
-
1
describe '#remove' do
-
1
it 'removes existing iedriver' do
-
iedriver.update
-
-
iedriver.remove
-
expect(iedriver.current_version).to be_nil
-
end
-
-
1
it 'does not raise exception if no iedriver found' do
-
expect { iedriver.remove }.not_to raise_error
-
end
-
end
-
-
1
describe '#install_dir' do
-
1
it 'uses ~/.webdrivers as default value' do
-
expect(Webdrivers::System.install_dir).to include('.webdriver')
-
end
-
-
1
it 'uses provided value' do
-
begin
-
install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
-
Webdrivers.install_dir = install_dir
-
-
expect(Webdrivers::System.install_dir).to eq install_dir
-
ensure
-
Webdrivers.install_dir = nil
-
end
-
end
-
end
-
-
1
describe '#driver_path' do
-
1
it 'returns full location of binary' do
-
expected_path = Webdrivers::System.escape_path("#{File.join(ENV['HOME'])}/.webdrivers/IEDriverServer.exe")
-
expect(iedriver.driver_path).to eq(expected_path)
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require '../spec_helper'
-
-
1
describe Webdrivers do
-
1
describe '#cache_time' do
-
1
before { Webdrivers::Chromedriver.remove }
-
-
1
after { described_class.cache_time = nil }
-
-
1
context 'when cache time is not set' do
-
1
before { described_class.cache_time = nil }
-
-
1
it 'defaults cache time to 86,400 Seconds (24 hours)' do
-
expect(described_class.cache_time).to eq(86_400)
-
end
-
end
-
-
1
context 'when Webdrivers.cache_time is set' do
-
1
before { described_class.cache_time = '999' }
-
-
1
it 'returns user defined cache time' do
-
expect(described_class.cache_time).to eq(999)
-
end
-
-
1
it 'returns cache time as an Integer' do
-
expect(described_class.cache_time).to be_an_instance_of(Integer)
-
end
-
end
-
-
1
context 'when ENV variable WD_CACHE_TIME is set' do
-
1
before { described_class.cache_time = 3600 }
-
-
1
it 'uses cache time value from Webdrivers.cache_time over the ENV variable value' do
-
allow(ENV).to receive(:[]).with('WD_CACHE_TIME').and_return(900)
-
expect(described_class.cache_time).to be(3600)
-
end
-
-
1
it 'returns cache time as an Integer' do
-
allow(ENV).to receive(:fetch).with('WD_CACHE_TIME', 3600).and_return('999')
-
expect(described_class.cache_time).to be_an_instance_of(Integer)
-
end
-
end
-
end
-
-
1
describe '#install_dir' do
-
1
it 'uses ~/.webdrivers as default value' do
-
expect(described_class.install_dir).to include('.webdriver')
-
end
-
-
1
it 'uses provided value' do
-
begin
-
install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
-
described_class.install_dir = install_dir
-
-
expect(described_class.install_dir).to eq install_dir
-
ensure
-
described_class.install_dir = nil
-
end
-
end
-
-
1
context 'when ENV variable WD_INSTALL_DIR is set and Webdrivers.install_dir is not' do
-
1
it 'uses path from the ENV variable' do
-
begin
-
described_class.install_dir = nil
-
allow(ENV).to receive(:[]).with('WD_INSTALL_DIR').and_return('custom_dir')
-
expect(described_class.install_dir).to be('custom_dir')
-
ensure
-
described_class.install_dir = nil
-
end
-
end
-
end
-
-
1
context 'when both ENV variable WD_INSTALL_DIR and Webdrivers.install_dir are set' do
-
1
it 'uses path from Webdrivers.install_dir' do
-
begin
-
described_class.install_dir = 'my_install_dir_path'
-
allow(ENV).to receive(:[]).with('WD_INSTALL_DIR').and_return('my_env_path')
-
expect(described_class.install_dir).to be(described_class.install_dir)
-
ensure
-
described_class.install_dir = nil
-
end
-
end
-
end
-
end
-
end