Sha256: d1b6040ab1523003dde75451e15981b9b7992c070421692568ac7dad0d262a87

Contents?: true

Size: 1.52 KB

Versions: 145

Compression:

Stored size: 1.52 KB

Contents

require "common"

class FileFactoryTest < Net::SFTP::TestCase
  def setup
    @sftp = stub(:sftp)
    @factory = Net::SFTP::Operations::FileFactory.new(@sftp)
  end

  def test_open_with_block_should_yield_and_close_handle
    @sftp.expects(:open!).with("/path/to/remote", "r", :permissions => nil).returns("handle")
    @sftp.expects(:close!).with("handle")

    called = false
    @factory.open("/path/to/remote") do |f|
      called = true
      assert_instance_of Net::SFTP::Operations::File, f
    end

    assert called
  end

  def test_open_with_block_should_close_file_even_if_exception_is_raised
    @sftp.expects(:open!).with("/path/to/remote", "r", :permissions => nil).returns("handle")
    @sftp.expects(:close!).with("handle")

    assert_raises(RuntimeError) do
      @factory.open("/path/to/remote") { |f| raise RuntimeError, "b00m" }
    end
  end

  def test_open_without_block_should_return_new_file
    @sftp.expects(:open!).with("/path/to/remote", "r", :permissions => nil).returns("handle")
    @sftp.expects(:close!).never

    f = @factory.open("/path/to/remote")
    assert_instance_of Net::SFTP::Operations::File, f
  end

  def test_directory_should_be_true_for_directory
    @sftp.expects(:lstat!).with("/path/to/dir").returns(mock('attrs', :directory? => true))
    assert @factory.directory?("/path/to/dir")
  end

  def test_directory_should_be_false_for_non_directory
    @sftp.expects(:lstat!).with("/path/to/file").returns(mock('attrs', :directory? => false))
    assert !@factory.directory?("/path/to/file")
  end
end

Version data entries

145 entries across 108 versions & 9 rubygems

Version Path
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-unbundled-2.2.0.0 vendor/bundle/ruby/2.5.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-unbundled-2.1.4.0 vendor/bundle/ruby/2.5.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-unbundled-2.1.2.0 vendor/bundle/ruby/2.3.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/net-sftp-2.1.2/test/test_file_factory.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/net-sftp-2.1.2/test/test_file_factory.rb