Commit 6e785527 authored by Francis Chong's avatar Francis Chong

refactor: raise a UnsupportedFileTypeError when unexpected file type is given

parent f1072e7e
...@@ -6,6 +6,8 @@ require 'yaml' ...@@ -6,6 +6,8 @@ require 'yaml'
module Pod module Pod
class Downloader class Downloader
class Http < Downloader class Http < Downloader
class UnsupportedFileTypeError < StandardError; end
executable :curl executable :curl
executable :unzip executable :unzip
executable :tar executable :tar
...@@ -49,7 +51,7 @@ module Pod ...@@ -49,7 +51,7 @@ module Pod
when :tar when :tar
"file.tar" "file.tar"
else else
raise "Pod::Downloader::Http Unsupported file type: #{type}" raise UnsupportedFileTypeError.new "Unsupported file type: #{type}"
end end
end end
...@@ -66,7 +68,7 @@ module Pod ...@@ -66,7 +68,7 @@ module Pod
when :tar when :tar
tar "xf '#{full_filename}' -d #{target_path}" tar "xf '#{full_filename}' -d #{target_path}"
else else
raise "Http Downloader: Unsupported file type" raise UnsupportedFileTypeError.new "Unsupported file type: #{type}"
end end
end end
......
...@@ -56,4 +56,20 @@ describe Pod::Downloader::Http do ...@@ -56,4 +56,20 @@ describe Pod::Downloader::Http do
downloader.expects(:extract_with_type).with(anything(), :tgz).at_least_once downloader.expects(:extract_with_type).with(anything(), :tgz).at_least_once
downloader.download downloader.download
end end
it 'should raise error when unsupported filetype is pass' do
downloader = Pod::Downloader.for_pod(stub_pod_with_source(
:http => 'https://testflightapp.com/media/sdk-downloads/TestFlightSDK1.0.rar'
))
downloader.expects(:download).raises(Pod::Downloader::Http::UnsupportedFileTypeError)
downloader.download rescue nil
downloader = Pod::Downloader.for_pod(stub_pod_with_source(
:http => 'https://testflightapp.com/media/sdk-downloads/TestFlightSDK1.0',
:type => :rar
))
downloader.expects(:download).raises(Pod::Downloader::Http::UnsupportedFileTypeError)
downloader.download rescue nil
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment