Skip to content

Commit

Permalink
Adding #mdtm method
Browse files Browse the repository at this point in the history
  • Loading branch information
petebrowne committed Jul 20, 2010
1 parent d8d96d3 commit 4e901e5
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/mock_ftp/net_ftp.rb
Expand Up @@ -45,6 +45,10 @@ def login(username = 'anonymous', passwd = nil, acct = nil)
"230 User #{username} logged in.\n" "230 User #{username} logged in.\n"
end end


def mdtm(path)
mtime(path).strftime('%Y%m%d%H%M%S')
end

def mtime(path, local = false) def mtime(path, local = false)
raise_if_closed raise_if_closed
full_path = follow_path(path) full_path = follow_path(path)
Expand Down
55 changes: 54 additions & 1 deletion spec/mock_ftp_spec.rb
Expand Up @@ -138,9 +138,62 @@
end end
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 describe '#mtime' do
it 'should return the modification time of the file' do it 'should return the modification time of the file' do
Timecop.freeze(Time.now) do Timecop.freeze do
mock_ftp do |f| mock_ftp do |f|
f.file 'file' f.file 'file'


Expand Down

0 comments on commit 4e901e5

Please sign in to comment.