Permalink
Browse files

Test that the email is actually sent on the interweb

  • Loading branch information...
1 parent 0c7d30f commit 653c2561e7fca7cb1466c29b049d42b6d380b509 @sr sr committed Mar 1, 2009
Showing with 39 additions and 6 deletions.
  1. +39 −6 test/mail_test.rb
View
45 test/mail_test.rb
@@ -1,16 +1,38 @@
require "test/unit"
-require "redgreen"
+require "rumbster"
+require "message_observers"
require "integrity/notifier/test_helper"
+begin
+ require "redgreen"
+rescue LoadError
+end
+
require File.dirname(__FILE__) + "/../lib/notifier/email"
class MailTest < Test::Unit::TestCase
include NotifierHelpers
+ MAIL_SERVER_PORT = 10_000
+
def notifier
"Email"
end
+ def setup
+ Net::SMTP.disable_tls
+
+ @server = Rumbster.new(MAIL_SERVER_PORT)
+ @mail_observer = MailMessageObserver.new
+ @server.add_observer(@mail_observer)
+
+ @server.start
+ end
+
+ def teardown
+ @server.stop
+ end
+
def test_configuration_form
assert_form_have_tag "h3", :content => "SMTP Server Configuration"
@@ -24,10 +46,21 @@ def test_configuration_form
assert_form_have_option "domain","localhost"
end
- def test_notification_content
- assert notification.include?("Build")
- assert notification.include?("Build #{commit.identifier} was successful")
- assert notification.include?(commit.author.name)
- assert notification.include?(commit.output)
+ def test_it_sends_email_notification
+ config = { "host" => "127.0.0.1",
+ "port" => MAIL_SERVER_PORT,
+ "to" => "you@example.org",
+ "from" => "me@example.org" }
+
+ Integrity::Notifier::Email.new(commit, config).deliver!
+
+ mail = @mail_observer.messages.first
+
+ assert_equal ["you@example.org"], mail.destinations
+ assert_equal ["me@example.org"], mail.from
+ assert mail.subject.include?("successful")
+ assert mail.body.include?(commit.committed_at.to_s)
+ assert mail.body.include?(commit.author.name)
+ assert mail.body.include?(commit.output)
end
end

0 comments on commit 653c256

Please sign in to comment.