Skip to content

Commit

Permalink
Fix bug where values from the ENV vars had precedence over user defin…
Browse files Browse the repository at this point in the history
…ed configs in the project.
  • Loading branch information
kapoorlakshya committed Jun 18, 2019
1 parent 94b760f commit aa4ed8e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/webdrivers/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class NetworkError < StandardError
end

DEFAULT_CACHE_TIME = 86_400 # 24 hours
DEFAULT_INSTALL_DIR = File.expand_path(File.join(ENV['HOME'], '.webdrivers'))

class << self
attr_accessor :proxy_addr, :proxy_port, :proxy_user, :proxy_pass
Expand All @@ -30,15 +31,15 @@ class << self
# are set, it defaults to 86,400 Seconds (24 hours).
#
def cache_time
(ENV['WD_CACHE_TIME'] || @cache_time || DEFAULT_CACHE_TIME).to_i
(@cache_time || ENV['WD_CACHE_TIME'] || DEFAULT_CACHE_TIME).to_i
end

#
# Returns the install (download) directory path for the drivers.
#
# @return [String]
def install_dir
@install_dir || ENV['WD_INSTALL_DIR'] || File.expand_path(File.join(ENV['HOME'], '.webdrivers'))
@install_dir || ENV['WD_INSTALL_DIR'] || DEFAULT_INSTALL_DIR
end

def logger
Expand Down
16 changes: 14 additions & 2 deletions spec/webdrivers/webdrivers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
context 'when ENV variable WD_CACHE_TIME is set' do
before { described_class.cache_time = 86_400 }

it 'uses cache time value from ENV variable over the Webdrivers.cache_time value' do
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(999)
expect(described_class.cache_time).to be(999)
expect(described_class.cache_time).to be(86_400)
end

it 'returns cache time as an Integer' do
Expand Down Expand Up @@ -70,5 +70,17 @@
end
end
end

context 'when both ENV variable WD_INSTALL_DIR and Webdrivers.install_dir are set' do
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

0 comments on commit aa4ed8e

Please sign in to comment.