Module: FTPMVC::TestHelpers

Defined in:
lib/ftpmvc/test_helpers.rb

Instance Method Summary collapse

Instance Method Details

#get(ftp, path, encoding = nil) ⇒ Object



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

def get(ftp, path, encoding=nil)
  ''.tap do |response|
    ftp.retrbinary("RETR #{path}", 1024) do |block|
      response << block
    end
    response.force_encoding(encoding) unless encoding.nil?
  end
end

#put(ftp, path, content) ⇒ Object



30
31
32
# File 'lib/ftpmvc/test_helpers.rb', line 30

def put(ftp, path, content)
  ftp.storlines("STOR #{path}", StringIO.new(content))
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