Giter Club home page Giter Club logo

ftpmock's Introduction

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.

ftpmock's People

Contributors

th1agoalmeida avatar

Stargazers

Dmitry Efimov avatar Ruben Arakelyan avatar Tomasz Mazur avatar Enrique Esquinas avatar m.b. avatar Miguel Parramón Teixidó avatar KAWAHARA Keisuke avatar  avatar Marco Castro avatar Gabriel Mazetto avatar Gabriel González Mañaná avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.