Skip to content

Instantly share code, notes, and snippets.

@cored
Created March 5, 2014 13:20
Show Gist options
  • Save cored/ae8e7bd4a4993be6b134 to your computer and use it in GitHub Desktop.
Save cored/ae8e7bd4a4993be6b134 to your computer and use it in GitHub Desktop.
require 'minitest/autorun'
require_relative '../../lib/timeout_increaser'
class FakeImapConnection
attr_accessor :timeout
def initialize
@timeout = 100
end
def reconnect
end
end
module Timeout
class Error < StandardError; end
end
class FakeAttachmentSaver
def retrieve_message_body(tracked_msg, uid)
raise Timeout::Error
end
end
class TimeoutIncreaserTest < MiniTest::Unit::TestCase
def setup
@imap_connection = FakeImapConnection.new
@uid = 'uid'
end
def test_connection_retry
tracked_msg = 'msg'
attacher = MiniTest::Mock.new
attacher.expect :retrieve_message_body, true, [tracked_msg, @uid]
TimeoutIncreaser.increase(attacher,
@imap_connection, tracked_msg, @uid)
attacher.verify
end
def test_process_attachment_if_retry_failed
attacher = FakeAttachmentSaver.new
tracked_msg = MiniTest::Mock.new
tracked_msg.expect :attachments_processed!, true
TimeoutIncreaser.increase(attacher, @imap_connection,
tracked_msg, @uid)
tracked_msg.verify
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment