Sha256: 287461bf6254cf279f32ccfc225d0fd4734e933b29e8863227e66a8154b39769

Contents?: true

Size: 1.87 KB

Versions: 1

Compression:

Stored size: 1.87 KB

Contents

$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'test/unit'
require 'rumbster'
require 'net/smtp'
require 'gserver'


class RumbsterTest < Test::Unit::TestCase
  
  def setup
    @observer = RumbsterObserver.new
    @server = Rumbster.new(10025)
    @server.add_observer(@observer)
    
    @server.start
  end
  
  def teardown
    @server.stop
  end
  
  def test_single_receiver_message_sent_by_client_is_received_by_listener
    message = "From: <junk@junkster.com>\r\nTo: junk@junk.com\r\nSubject: hi\r\n\r\nThis is a test\r\n"
    to = 'his_address@example.com'
    send_message to, message 
        
    assert_equal message, @observer.message
  end
  
  def test_multiple_receiver_message_sent_by_client_is_received_by_listener
    message = "From: <junk@junkster.com>\r\nTo: junk@junk.com\r\nSubject: hi\r\n\r\nThis is a test\r\n"
    to = ['his_address@example.com', 'her_address@example.com']
    send_message to, message 
        
    assert_equal message, @observer.message
  end

  def test_multiple_receiver_messages_sent_by_client_are_received_by_listener
    message_1 = "From: <junk_1@junkster.com>\r\nTo: junk_1@junk.com\r\nSubject: hi\r\n\r\nThis is a test_1\r\n"
    to_1 = ['his_address_1@example.com', 'her_address_1@example.com']
    send_message to_1, message_1 

    assert_equal message_1, @observer.message

    message_2 = "From: <junk_2@junkster.com>\r\nTo: junk_2@junk.com\r\nSubject: hi\r\n\r\nThis is a test_2\r\n"
    to_2 = ['his_address_2@example.com', 'her_address_2@example.com']
    send_message to_2, message_2 
        
    assert_equal message_2, @observer.message
  end
  
  private

  def send_message(to, message)
    Net::SMTP.start('localhost', 10025) do |smtp|
      smtp.send_message message, 'your@mail.address', to
    end
  end
  
end

class RumbsterObserver
  attr_accessor :message
  
  def update(message)
    @message = message
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rumbster-1.0.0 test/rumbster_test.rb