summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Campbell <hikeit@gmail.com>2013-02-18 12:18:50 -0500
committerBryan McLellan <btm@opscode.com>2013-02-26 11:11:44 -0800
commit6f6fff817866e1fb5ab3c90862bfaa627b5378fd (patch)
tree582c032fc5452da4f9db933cb15c2fa686e20a48
parent8dcd04c05f57ca3f89893d0460fb867f2073df57 (diff)
downloadchef-6f6fff817866e1fb5ab3c90862bfaa627b5378fd.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