Created
February 24, 2012 20:18
-
-
Save avit/1903475 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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