Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ftpmock

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ftpmock

  • 0.1.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Ftpmock

Test your FTP calls offline.

Status

Is It Working?Is It Tested?Code Quality# of DownloadsGet Involved!
Master Build StatusTest CoverageMaintainabilityDownloadsGitHub 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.

FAQs

Package last updated on 11 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc