Skip to content

Commit

Permalink
Improve tests for Downloader.destination_for
Browse files Browse the repository at this point in the history
  • Loading branch information
niezbop committed Jan 6, 2018
1 parent 772f9b7 commit 571559f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def with_env_values(hash)
end
end

def warn_if_env(variable)
if ENV[variable] && !ENV[variable].empty?
puts "[WARNING] Environment variable #{variable} should not be assigned during testing. Results may be affected."
end
end

def capture_stds
require "stringio"
orig_stdout = $stdout
Expand Down
57 changes: 54 additions & 3 deletions spec/u3d/downloader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@
end

describe '.destination_for' do
it 'returns the correct destination the Unity installer' do
it 'returns the correct default destination for the specified package' do
warn_if_env('U3D_DOWNLOAD_PATH')
expect(U3d::Utils).to receive(:ensure_dir) {}
allow(U3d::INIparser).to receive(:load_ini) { { 'Unity' => { 'url' => 'http://download.unity3d.com/download_unity/linux/unity-editor-installer-1.2.3f4+20160628.sh' } } }

Expand All @@ -399,6 +400,22 @@
)
).to eql File.join(ENV['HOME'], 'Downloads', 'Unity_Packages', '1.2.3f4', 'unity-editor-installer-1.2.3f4+20160628.sh')
end

it 'returns the custom destination for the specified package when the environment variable is specified' do
with_env_values('U3D_DOWNLOAD_PATH' => '/foo') do
expect(U3d::Utils).to receive(:ensure_dir) {}
allow(U3d::INIparser).to receive(:load_ini) { { 'Unity' => { 'url' => 'http://download.unity3d.com/download_unity/linux/unity-editor-installer-1.2.3f4+20160628.sh' } } }

definition = U3d::UnityVersionDefinition.new('1.2.3f4', :linux, nil)

expect(
@downloader.destination_for(
'Unity',
definition
)
).to eql File.join(File.expand_path('/foo'), '1.2.3f4', 'unity-editor-installer-1.2.3f4+20160628.sh')
end
end
end

describe '.url_for' do
Expand All @@ -422,7 +439,8 @@
end

describe '.destination_for' do
it 'returns the correct destination the specified package' do
it 'returns the correct default destination for the specified package' do
warn_if_env('U3D_DOWNLOAD_PATH')
expect(U3d::Utils).to receive(:ensure_dir) {}
allow(U3d::INIparser).to receive(:load_ini) { { 'package' => { 'url' => 'MacEditorInstaller/Unity.pkg' } } }

Expand All @@ -435,6 +453,22 @@
)
).to eql File.join(ENV['HOME'], 'Downloads', 'Unity_Packages', '1.2.3f4', 'Unity.pkg')
end

it 'returns the custom destination for the specified package when the environment variable is specified' do
with_env_values('U3D_DOWNLOAD_PATH' => '/foo') do
expect(U3d::Utils).to receive(:ensure_dir) {}
allow(U3d::INIparser).to receive(:load_ini) { { 'package' => { 'url' => 'MacEditorInstaller/Unity.pkg' } } }

definition = U3d::UnityVersionDefinition.new('1.2.3f4', :mac, nil)

expect(
@downloader.destination_for(
'package',
definition
)
).to eql File.join(File.expand_path('/foo'), '1.2.3f4', 'Unity.pkg')
end
end
end

describe '.url_for' do
Expand All @@ -458,7 +492,8 @@
end

describe '.destination_for' do
it 'returns the correct destination the specified package' do
it 'returns the correct default destination the specified package' do
warn_if_env('U3D_DOWNLOAD_PATH')
expect(U3d::Utils).to receive(:ensure_dir) {}
allow(U3d::INIparser).to receive(:load_ini) { { 'package' => { 'url' => 'Windows64EditorInstaller/UnitySetup64.exe' } } }

Expand All @@ -471,6 +506,22 @@
)
).to eql File.join(ENV['HOME'], 'Downloads', 'Unity_Packages', '1.2.3f4', 'UnitySetup64.exe')
end

it 'returns the custom destination for the specified package when the environment variable is specified' do
with_env_values('U3D_DOWNLOAD_PATH' => '/foo') do
expect(U3d::Utils).to receive(:ensure_dir) {}
allow(U3d::INIparser).to receive(:load_ini) { { 'package' => { 'url' => 'Windows64EditorInstaller/UnitySetup64.exe' } } }

definition = U3d::UnityVersionDefinition.new('1.2.3f4', :win, nil)

expect(
@downloader.destination_for(
'package',
definition
)
).to eql File.join(File.expand_path('/foo'), '1.2.3f4', 'UnitySetup64.exe')
end
end
end

describe '.url_for' do
Expand Down

0 comments on commit 571559f

Please sign in to comment.