summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Campbell <hikeit@gmail.com>2013-02-18 12:18:50 -0500
committerJesse Campbell <hikeit@gmail.com>2013-02-18 12:18:50 -0500
commitd731a62c7680a4f7d81ca2862e3c2f1ee3701e44 (patch)
tree26c18b4d6a0c3c26c43aa8606a468757381fe1f6
parentf372f8ca80444a038b7dfaf1a1f035de7e1a90ca (diff)
downloadchef-d731a62c7680a4f7d81ca2862e3c2f1ee3701e44.tar.gz
some cleanup utilizing the refactored RemoteFile::FTP
-rw-r--r--lib/chef/provider/remote_file/ftp.rb32
-rw-r--r--spec/unit/provider/remote_file/ftp_spec.rb8
2 files changed, 21 insertions, 19 deletions
diff --git a/lib/chef/provider/remote_file/ftp.rb b/lib/chef/provider/remote_file/ftp.rb
index 0d841408c7..3c5d3e0a91 100644
--- a/lib/chef/provider/remote_file/ftp.rb
+++ b/lib/chef/provider/remote_file/ftp.rb
@@ -51,21 +51,6 @@ class Chef
end
end
- def parse_path(path)
- path = path.sub(%r{\A/}, '%2F') # re-encode the beginning slash because uri library decodes it.
- directories = path.split(%r{/}, -1)
- directories.each {|d|
- d.gsub!(/%([0-9A-Fa-f][0-9A-Fa-f])/) { [$1].pack("H2") }
- }
- unless filename = directories.pop
- raise ArgumentError, "no filename: #{path.inspect}"
- end
- if filename.length == 0 || filename.end_with?( "/" )
- raise ArgumentError, "no filename: #{path.inspect}"
- end
- return directories, filename
- end
-
# Fetches using Net::FTP, returns a Tempfile with the content
def fetch()
tempfile = Tempfile.new(@filename)
@@ -87,6 +72,23 @@ class Chef
tempfile
end
+ private
+
+ def parse_path(path)
+ path = path.sub(%r{\A/}, '%2F') # re-encode the beginning slash because uri library decodes it.
+ directories = path.split(%r{/}, -1)
+ directories.each {|d|
+ d.gsub!(/%([0-9A-Fa-f][0-9A-Fa-f])/) { [$1].pack("H2") }
+ }
+ unless filename = directories.pop
+ raise ArgumentError, "no filename: #{path.inspect}"
+ end
+ if filename.length == 0 || filename.end_with?( "/" )
+ raise ArgumentError, "no filename: #{path.inspect}"
+ end
+ return directories, filename
+ end
+
end
end
end
diff --git a/spec/unit/provider/remote_file/ftp_spec.rb b/spec/unit/provider/remote_file/ftp_spec.rb
index 368a7346c4..03ef9424dd 100644
--- a/spec/unit/provider/remote_file/ftp_spec.rb
+++ b/spec/unit/provider/remote_file/ftp_spec.rb
@@ -36,22 +36,22 @@ describe Chef::Provider::RemoteFile::FTP, "fetch" do
describe "when parsing the uri" do
it "throws an argument exception when no path is given" do
@uri.path = ""
- lambda { Chef::Provider::RemoteFile::FTP.fetch(@uri, false).close! }.should raise_error(ArgumentError)
+ lambda { Chef::Provider::RemoteFile::FTP.new(@uri, false) }.should raise_error(ArgumentError)
end
it "throws an argument exception when only a / is given" do
@uri.path = "/"
- lambda { Chef::Provider::RemoteFile::FTP.fetch(@uri, false).close! }.should raise_error(ArgumentError)
+ lambda { Chef::Provider::RemoteFile::FTP.new(@uri, false) }.should raise_error(ArgumentError)
end
it "throws an argument exception when no filename is given" do
@uri.path = "/the/whole/path/"
- lambda { Chef::Provider::RemoteFile::FTP.fetch(@uri, false).close! }.should raise_error(ArgumentError)
+ lambda { Chef::Provider::RemoteFile::FTP.new(@uri, false) }.should raise_error(ArgumentError)
end
it "throws an argument exception when the typecode is invalid" do
@uri.typecode = "d"
- lambda { Chef::Provider::RemoteFile::FTP.fetch(@uri, false).close! }.should raise_error(ArgumentError)
+ lambda { Chef::Provider::RemoteFile::FTP.new(@uri, false) }.should raise_error(ArgumentError)
end
end