Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding #mdtm method

  • Loading branch information...
commit 4e901e57f3ddc463aee88c2b1d2402603146d53d 1 parent d8d96d3
@petebrowne authored
Showing with 58 additions and 1 deletion.
  1. +4 −0 lib/mock_ftp/net_ftp.rb
  2. +54 −1 spec/mock_ftp_spec.rb
View
4 lib/mock_ftp/net_ftp.rb
@@ -45,6 +45,10 @@ def login(username = 'anonymous', passwd = nil, acct = nil)
"230 User #{username} logged in.\n"
end
+ def mdtm(path)
+ mtime(path).strftime('%Y%m%d%H%M%S')
+ end
+
def mtime(path, local = false)
raise_if_closed
full_path = follow_path(path)
View
55 spec/mock_ftp_spec.rb
@@ -138,9 +138,62 @@
end
end
+ describe '#mdtm' do
+ it 'should return the modification time of the file' do
+ Timecop.freeze(Time.utc(2010, 7, 20, 15, 30, 30)) do
+ mock_ftp do |f|
+ f.file 'file'
+
+ open_ftp do |ftp|
+ ftp.mdtm('file').should == '20100720153030'
+ end
+ end
+ end
+ end
+
+ context 'on a folder' do
+ it 'should raise an error' do
+ mock_ftp do |f|
+ f.folder 'folder'
+
+ open_ftp do |ftp|
+ expect {
+ ftp.mdtm('folder')
+ }.to raise_error(Net::FTPPermError, '550 folder: not a plain file.')
+ end
+ end
+ end
+ end
+
+ context 'without a file' do
+ it 'should raise an error' do
+ mock_ftp do |f|
+ open_ftp do |ftp|
+ expect {
+ ftp.mdtm('blah')
+ }.to raise_error(Net::FTPPermError, '550 blah: No such file or directory')
+ end
+ end
+ end
+ end
+
+ context 'when the connection is closed' do
+ it 'should raise an IOError' do
+ mock_ftp do |f|
+ open_ftp do |ftp|
+ ftp.close
+ expect {
+ ftp.mdtm('blah')
+ }.to raise_error(IOError, 'closed stream')
+ end
+ end
+ end
+ end
+ end
+
describe '#mtime' do
it 'should return the modification time of the file' do
- Timecop.freeze(Time.now) do
+ Timecop.freeze do
mock_ftp do |f|
f.file 'file'
Please sign in to comment.
Something went wrong with that request. Please try again.