Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/christian-schulze/testftpd
Simple FTP server written in pure Ruby, allowing integration testing of FTP client code without mocks and stubs
https://github.com/christian-schulze/testftpd
Last synced: about 1 month ago
JSON representation
Simple FTP server written in pure Ruby, allowing integration testing of FTP client code without mocks and stubs
- Host: GitHub
- URL: https://github.com/christian-schulze/testftpd
- Owner: christian-schulze
- License: mit
- Created: 2013-03-11T13:21:32.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2023-01-30T13:22:05.000Z (almost 2 years ago)
- Last Synced: 2024-04-25T10:03:17.464Z (8 months ago)
- Language: Ruby
- Size: 284 KB
- Stars: 7
- Watchers: 3
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rspec - testftpd - Simple FTP server written in pure Ruby, allowing integration testing of FTP client code without mocks and stubs. (Mocks)
README
# TestFtpd
[![Gem Version](https://badge.fury.io/rb/testftpd.png)](http://badge.fury.io/rb/testftpd) [![Build Status](https://travis-ci.org/christian-schulze/testftpd.png)](https://travis-ci.org/christian-schulze/testftpd)
Simple FTP server written in pure Ruby.
The primary use case is for integration testing FTP client code in a Rails 3.1 codebase using RSpec 2.
Enough FTP commands are implemented to be useful, including:
portpasvuserpassquitsysttype
listretrstordelesizemdtmrnfr/rnto
pwdcdupcwdmkdrmdnlst
## Usage
Update your Gemfile
```ruby
group :test do
gem 'testftpd', :require => false
end
```Write some specs...
```ruby
require 'spec_helper'
require 'testftpd'describe 'Test all the things!' do
let(:ftp_port) { 21212 }
let(:ftp_root) { Rails.root.to_s }before do
@ftp_server = TestFtpd::Server.new(port: ftp_port, root_dir: ftp_root)
@ftp_server.start
endafter do
@ftp_server.shutdown
endit 'lists remote files' do
ftp = Net::FTP.new
ftp.connect('127.0.0.1', ftp_port)
ftp.login('username', 'password')
ftp.list.any? { |file| file ~= /Gemfile/ }.should be_true
end
end
```You can change the list command format by monkey-patching or stubbing. Heres a stubbing technique I've used:
```ruby
require 'spec_helper'
require 'testftpd'describe 'Test all the things!' do
let(:ftp_port) { 21212 }
let(:ftp_root) { Rails.root.to_s }before do
@ftp_server = TestFtpd::Server.new(port: ftp_port, root_dir: ftp_root)
@ftp_server.start
endafter do
@ftp_server.shutdown
endbefore :each do
TestFtpd::FileSystemProvider.stub(:format_list_entry) do |entry|
raw = entry.ftp_date.strftime('%m-%d-%g %I:%M%p') + ' '
if entry.directory?
raw += ' '
else
raw += entry.ftp_size.to_s.rjust(20, ' ') + ' '
end
raw += entry.ftp_name
raw += "\r\n"
raw
end
endit 'lists remote files' do
ftp = Net::FTP.new
ftp.connect('127.0.0.1', ftp_port)
ftp.login('username', 'password')
ftp.list.any? { |file| file ~= /Gemfile/ }.should be_true
end
```This will most likely make it into the *TestFtpd* code base as a configurable option, stay tuned.
## Todo
* more tests
* add simple authentication provider
* implement more FTP commands## Acknowledgements
This code builds upon Rubtsov Vitaly' excellent project [dyn-ftp-serv](http://rubyforge.org/projects/dyn-ftp-serv/) created in late 2007.
Also [Francis Hwang](https://github.com/fhwang/fake_ftp) who originally adapted *dyn-ftp-serv*, and gave me a head start for this project.
## Contributers
* Christian Schulze
## License
Released under the MIT license. Please see the `LICENSE` file for more information.