Project

ftpmock

0.01
No release in over 3 years
Low commit activity in last 3 years
Just like VCR and WebMock, but for FTP.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 13.0
~> 3.0

Runtime

~> 3.0
 Project Readme

Ftpmock

Test your FTP calls offline.

Status

Is It Working? Is It Tested? Code Quality # of Downloads Get Involved!
Master Build Status Test Coverage Maintainability Downloads GitHub Issues

Compatibility

Ruby 2.3 Ruby 2.4 Ruby 2.5 Ruby 2.6 Ruby 2.7

Installation

Add this line to your application's Gemfile:

group :test do
  gem 'ftpmock'
end

Usage

If you know your way around tests

require 'ftpmock'

RSpec.configure do |config|
  config.around(:example) do |example|
    Ftpmock.on! do
      example.run
    end
  end
end

If you need to see a full example

require 'rubygems'
require 'test/unit'
require 'ftpmock'

# Optional (default values)
Ftpmock.configure do |c|
  c.path = 'test/ftp_records'
  c.verbose = true
end

class FtpmockTest < Test::Unit::TestCase
  def test_ubuntu_mirror
    Ftpmock.on! do
      # Ubuntu Download - University of Pittsburgh
      ftp = Net::FTP.new
      assert_equal(Ftpmock::NetFtpProxy, ftp.class)
      assert ftp.connect('mirror.cs.pitt.edu', 21)
      assert ftp.login('', '')

      t = Time.now
      3.times do |i|
        list = ftp.list('/ubuntu/releases')
        assert list.size.positive?

        ftp.get('/ubuntu/releases/robots.txt', 'tmp/ubuntu_robots.txt')
        assert File.exist?('tmp/ubuntu_robots.txt')

        puts "[Take #{i+1}] #{(Time.now-t).round(3)}s"
      end
    end
  end
end

Run this test once, and Ftpmock will record the FTP requests to test/ftp_records/mirror-cs-pitt-edu_21__/

Run it again, and Ftpmock will replay the responses from mirror.cs.pitt.edu when the FTP request is made.

Your tests are now blazing fast because no real FTP requests are made anymore.

The test will continue to pass, even if you are offline, or if the University of Pittsburgh FTP servers are down for maintenance.

The responses will be accurate since they will contain the same list and files you get from a real request.

Unlike VCR, Ftpmock combines your four credentials (address + port + username + password) and caches onto the exact same directory, optimizing for both storage and readability.

Development

After checking out the repo, run bin/setup to install dependencies.

Then, run bundle exec rake spec to run the tests.

You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Documentation

Chart

  • Core
    • Stubber
    • Configuration
    • Cache
    • Helpers
  • Proxies
    • Proxy for Ruby's native Net::FTP library
    • Proxy for Jamis Buck's gem 'net-sftp'

Core instantiable classes & procedural modules

links: lib/ftpmock/core

  • stubber for proxies
  • configuration class
  • cache class
  • cache path helper
  • cache list helper
  • cache get helper
  • cache put helper

Proxy for Ruby's native Net::FTP library (Ftpmock::NetFtpProxy)

links: lib/ftpmock/proxies/net_ftp_proxy.rb , https://apidock.com/ruby/Net/FTP & https://github.com/ruby/ruby/tree/master/lib/net

  • proxy class
  • stubbers
  • address & port forwarding
  • username & password forwarding
  • chdir forwarding
  • pwd
  • list
  • get
  • put
  • ssl support
  • unit tests
  • integration tests

Proxy for Jamis Buck's gem 'net-sftp' (Ftpmock::NetSftpProxy)

links: lib/ftpmock/proxies/net_sftp_proxy.rb , https://rubygems.org/gems/net-sftp & https://github.com/net-ssh/net-sftp

  • proxy class
  • stubbers
  • address & port forwarding
  • username & password forwarding
  • list
  • get
  • put
  • unit tests
  • integration tests

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/thejamespinto/ftpmock.

Changelog can be found at CHANGELOG.md

License

The gem is available as open source under the terms of the MIT License.