Last active
July 1, 2022 21:49
-
-
Save b-nik/35ee176d7116f9610b8f7ad130507e7b to your computer and use it in GitHub Desktop.
Mock Simple FTP
This file contains 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
# add in a before(:all) in your test suite for example | |
ls_command = [ | |
"-rw-r--r-- 1 ftp ftp 671686268 Feb 21 03:14 some_file", | |
"drw-r--r-- 1 ftp ftp 671686268 Feb 21 03:14 directory", | |
# ... | |
] | |
class FakeFtp < OpenStruct | |
# So that for example fake_ftp.chdir("path/to/dir") will be send as fake_ftp.chdir | |
def method_missing(method, *args) | |
self[method] | |
end | |
end | |
@fake_ftp = FakeFtp.new({ | |
pwd: "/some/folder", | |
chdir: true, | |
list: ls_command, | |
getbinaryfile: "binary_file_data", | |
gettextfile: "text_file_data", | |
# add anything here really | |
}) | |
# rspec type mock, make sure Net::Ftp.new will return our fake ftp object | |
allow(Net::FTP).to receive(:new) { @fake_ftp } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment