Skip to content

Commit

Permalink
Update specs related to driver caching.
Browse files Browse the repository at this point in the history
  • Loading branch information
kapoorlakshya committed May 25, 2020
1 parent a50315e commit fcea4dc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
21 changes: 13 additions & 8 deletions spec/webdrivers/chromedriver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,16 @@
end
end

it 'makes a network call if cached driver does not match the browser' do
it 'makes network calls if cached driver does not match the browser' do
Webdrivers::System.cache_version('chromedriver', '71.0.3578.137')
allow(chromedriver).to receive(:current_version).and_return(Gem::Version.new('71.0.3578.137'))
allow(chromedriver).to receive(:browser_version).and_return(Gem::Version.new('73.0.3683.68'))
allow(Webdrivers::Network).to receive(:get).and_return('73.0.3683.68')
allow(Webdrivers::System).to receive(:download)

chromedriver.update

expect(Webdrivers::Network).to have_received(:get).once
expect(Webdrivers::Network).to have_received(:get).twice
end

context 'when required version is 0' do
Expand Down Expand Up @@ -155,19 +156,19 @@

describe '#latest_version' do
it 'returns 2.41 if the browser version is less than 70' do
allow(chromedriver).to receive(:browser_version).and_return('69.0.0')
allow(chromedriver).to receive(:browser_version).and_return Gem::Version.new('69.0.0')

expect(chromedriver.latest_version).to eq(Gem::Version.new('2.41'))
end

it 'returns the correct point release for a production version greater than 70' do
allow(chromedriver).to receive(:browser_version).and_return '71.0.3578.9999'
allow(chromedriver).to receive(:browser_version).and_return Gem::Version.new('71.0.3578.9999')

expect(chromedriver.latest_version).to eq Gem::Version.new('71.0.3578.137')
end

it 'raises VersionError for beta version' do
allow(chromedriver).to receive(:browser_version).and_return('100.0.0')
allow(chromedriver).to receive(:browser_version).and_return Gem::Version.new('100.0.0')
msg = 'Unable to find latest point release version for 100.0.0. '\
'You appear to be using a non-production version of Chrome. '\
'Please set `Webdrivers::Chromedriver.required_version = <desired driver version>` '\
Expand All @@ -177,7 +178,7 @@
end

it 'raises VersionError for unknown version' do
allow(chromedriver).to receive(:browser_version).and_return('72.0.9999.0000')
allow(chromedriver).to receive(:browser_version).and_return Gem::Version.new('72.0.9999.0000')
msg = 'Unable to find latest point release version for 72.0.9999. '\
'Please set `Webdrivers::Chromedriver.required_version = <desired driver version>` '\
'to a known chromedriver version: https://chromedriver.storage.googleapis.com/index.html'
Expand All @@ -199,9 +200,12 @@
expect(File.exist?("#{Webdrivers::System.install_dir}/chromedriver.version")).to eq true
end

it 'does not make network call if cache is valid' do
it 'does not make network call if cache is valid and driver exists' do
allow(Webdrivers).to receive(:cache_time).and_return(3600)
Webdrivers::System.cache_version('chromedriver', '71.0.3578.137')
allow(chromedriver).to receive(:current_version).and_return(Gem::Version.new('71.0.3578.137'))
allow(chromedriver).to receive(:browser_version).and_return(Gem::Version.new('71.0.3578.137'))
allow(Webdrivers::System).to receive(:exists?).and_return(true)
allow(Webdrivers::Network).to receive(:get)

expect(chromedriver.latest_version).to eq Gem::Version.new('71.0.3578.137')
Expand All @@ -211,8 +215,9 @@

it 'makes a network call if cache is expired' do
Webdrivers::System.cache_version('chromedriver', '71.0.3578.137')
allow(chromedriver).to receive(:browser_version).and_return Gem::Version.new('71.0.3578.137')
allow(Webdrivers::Network).to receive(:get).and_return('73.0.3683.68')
allow(Webdrivers::System).to receive(:valid_cache?)
allow(Webdrivers::System).to receive(:valid_cache?).and_return(false)

expect(chromedriver.latest_version).to eq Gem::Version.new('73.0.3683.68')

Expand Down
24 changes: 14 additions & 10 deletions spec/webdrivers/edgedriver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,16 @@
end
end

it 'makes a network call if cached driver does not match the browser' do
it 'makes network calls if cached driver does not match the browser' do
Webdrivers::System.cache_version('msedgedriver', '71.0.3578.137')
allow(edgedriver).to receive(:current_version).and_return(Gem::Version.new('71.0.3578.137'))
allow(edgedriver).to receive(:browser_version).and_return(Gem::Version.new('73.0.3683.68'))
allow(Webdrivers::Network).to receive(:get).and_return('73.0.3683.68'.encode('UTF-16'))
allow(Webdrivers::System).to receive(:download)

edgedriver.update

expect(Webdrivers::Network).to have_received(:get).once
expect(Webdrivers::Network).to have_received(:get).twice
end

context 'when required version is 0' do
Expand Down Expand Up @@ -163,13 +164,13 @@

describe '#latest_version' do
it 'returns the correct point release for a production version' do
allow(edgedriver).to receive(:browser_version).and_return '77.0.207.0'
allow(edgedriver).to receive(:browser_version).and_return Gem::Version.new('77.0.207.0')

expect(edgedriver.latest_version).to be_between(Gem::Version.new('77.0.207.0'), Gem::Version.new('78'))
end

it 'raises VersionError for beta version' do
allow(edgedriver).to receive(:browser_version).and_return('100.0.0')
allow(edgedriver).to receive(:browser_version).and_return Gem::Version.new('100.0.0')
msg = 'Unable to find latest point release version for 100.0.0. '\
'You appear to be using a non-production version of Edge. '\
'Please set `Webdrivers::Edgedriver.required_version = <desired driver version>` '\
Expand All @@ -196,28 +197,31 @@
end

it 'creates cached file' do
allow(edgedriver).to receive(:browser_version).and_return('77.0.207.0')
allow(edgedriver).to receive(:browser_version).and_return Gem::Version.new('77.0.207.0')
allow(Webdrivers::Network).to receive(:get).and_return('77.0.207.0'.encode('UTF-16'))

edgedriver.latest_version
expect(File.exist?("#{Webdrivers::System.install_dir}/msedgedriver.version")).to eq true
end

it 'does not make network call if cache is valid' do
it 'does not make network call if cache is valid and driver exists' do
allow(Webdrivers).to receive(:cache_time).and_return(3600)
Webdrivers::System.cache_version('msedgedriver', '77.0.207.0')
Webdrivers::System.cache_version('msedgedriver', '82.0.445.0')
allow(edgedriver).to receive(:current_version).and_return(Gem::Version.new('82.0.445.0'))
allow(edgedriver).to receive(:browser_version).and_return(Gem::Version.new('82.0.445.0'))
allow(Webdrivers::System).to receive(:exists?).and_return(true)
allow(Webdrivers::Network).to receive(:get)

expect(edgedriver.latest_version).to eq Gem::Version.new('77.0.207.0')
expect(edgedriver.latest_version).to eq Gem::Version.new('82.0.445.0')

expect(Webdrivers::Network).not_to have_received(:get)
end

it 'makes a network call if cache is expired' do
Webdrivers::System.cache_version('msedgedriver', '71.0.3578.137')
allow(Webdrivers::Network).to receive(:get).and_return('77.0.207.0'.encode('UTF-16'))
allow(Webdrivers::System).to receive(:valid_cache?)
allow(edgedriver).to receive(:browser_version).and_return('77.0.207.0')
allow(Webdrivers::System).to receive(:valid_cache?).and_return(false)
allow(edgedriver).to receive(:browser_version).and_return Gem::Version.new('77.0.207.0')

expect(edgedriver.latest_version).to eq Gem::Version.new('77.0.207.0')

Expand Down
3 changes: 2 additions & 1 deletion spec/webdrivers/geckodriver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@
expect(File.exist?("#{Webdrivers::System.install_dir}/geckodriver.version")).to eq true
end

it 'does not make network call if cache is valid' do
it 'does not make network call if cache is valid and driver exists' do
allow(Webdrivers).to receive(:cache_time).and_return(3600)
Webdrivers::System.cache_version('geckodriver', '0.23.0')
allow(Webdrivers::System).to receive(:exists?).and_return(true)
allow(Webdrivers::Network).to receive(:get)

expect(geckodriver.latest_version).to eq Gem::Version.new('0.23.0')
Expand Down
3 changes: 2 additions & 1 deletion spec/webdrivers/i_edriver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@
expect(File.exist?("#{Webdrivers::System.install_dir}/IEDriverServer.version")).to eq true
end

it 'does not make network call if cache is valid' do
it 'does not make network call if cache is valid and driver exists' do
allow(Webdrivers).to receive(:cache_time).and_return(3600)
Webdrivers::System.cache_version('IEDriverServer', '3.4.0')
allow(Webdrivers::System).to receive(:exists?).and_return(true)
allow(Webdrivers::Network).to receive(:get)

expect(iedriver.latest_version).to eq Gem::Version.new('3.4.0')
Expand Down

0 comments on commit fcea4dc

Please sign in to comment.