Skip to content

Instantly share code, notes, and snippets.

@avit
Created February 24, 2012 20:18
Show Gist options
  • Save avit/1903475 to your computer and use it in GitHub Desktop.
Save avit/1903475 to your computer and use it in GitHub Desktop.
def fetch_data
Net::FTP.open(host, username, password) do |ftp|
begin
ftp.binary = binary
if file_name.is_a?(Regexp)
files = ftp.nlst.select { |i| i =~ file_name }
matching_file = files.pop
end
if file_newer && (@data_time = ftp.mtime(matching_file)) > file_newer
@data = ftp.get(matching_file)
end
rescue Net::FTPError
@error = ftp.last_response
end
end
end
it "connects given a hostname" do
ftp = mock('ftp').as_null_object
# ftp.should_receive(:login).with('uuu', 'ppp')
# ftp.should_receive(:close).and_return nil
Net::FTP.should_receive(:new).and_return(ftp)
subject.get
end
it "connects given a hostname" do
ftp = mock('ftp')
# ftp.should_receive(:login).with('uuu', 'ppp')
# ftp.should_receive(:close).and_return nil
Net::FTP.should_receive(:open).and_yield(ftp)
subject.get
end
1) Importer::Providers::FTP#get connects given a hostname
Failure/Error: Net::FTP.should_receive(:new).and_return(ftp)
(<Net::FTP (class)>).new(any args)
expected: 1 time
received: 0 times
# ./spec/lib/importer/providers/ftp_spec.rb:46:in `block (3 levels) in <top (required)>'
1) Importer::Providers::FTP#get connects given a hostname
Failure/Error: Net::FTP.should_receive(:open).and_yield(ftp)
(<Net::FTP (class)>).open(any args)
expected: 1 time
received: 0 times
# ./spec/lib/importer/providers/ftp_spec.rb:46:in `block (3 levels) in <top (required)>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment