Module: FTPMVC::TestHelpers

Defined in:
lib/ftpmvc/test_helpers.rb

Instance Method Summary collapse

Instance Method Details

#get(ftp, path) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/ftpmvc/test_helpers.rb', line 21

def get(ftp, path)
  ''.tap do |response|
    ftp.retrbinary("RETR #{path}", 1024) do |block|
      response << block.force_encoding('UTF-8')
    end
    response
  end
end

#with_application(app) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ftpmvc/test_helpers.rb', line 6

def with_application(app)
  server = FTPMVC::Server.new('127.0.0.1', 0).start_in_new_thread(app)
  begin
    ftp = Net::FTP.new
    begin
      ftp.connect('127.0.0.1', server.port)
      yield ftp
    ensure
      ftp.close rescue nil
    end
  ensure
    server.stop
  end
end