Skip to content
Browse files

uses an observer to detect new emails instead of setting the delivery…

… method

This allows users to have there own delivery_method, e.g. MockSMTP, and
have email_spec work transparently.
  • Loading branch information...
1 parent ecff947 commit eddf9edef6ec23fa2e429a4f21a207c02b7b5c5f @donaldpiret donaldpiret committed with bmabey Jun 16, 2011
Showing with 10 additions and 2 deletions.
  1. +2 −1 lib/email_spec.rb
  2. +1 −1 lib/email_spec/cucumber.rb
  3. +7 −0 lib/email_spec/test_observer.rb
View
3 lib/email_spec.rb
@@ -12,4 +12,5 @@
require 'email_spec/email_viewer'
require 'email_spec/helpers'
require 'email_spec/matchers'
-require 'email_spec/mail_ext'
+require 'email_spec/mail_ext'
+require 'email_spec/test_observer'
View
2 lib/email_spec/cucumber.rb
@@ -3,7 +3,7 @@
# Global Setup
if defined?(ActionMailer)
unless [:test, :activerecord, :cache, :file].include?(ActionMailer::Base.delivery_method)
- ActionMailer::Base.delivery_method = :test
+ ActionMailer::Base.register_observer(EmailSpec::TestObserver)
end
ActionMailer::Base.perform_deliveries = true
View
7 lib/email_spec/test_observer.rb
@@ -0,0 +1,7 @@
+module EmailSpec
+ class TestObserver
+ def self.delivered_email(message)
+ ActionMailer::Base.deliveries << message
+ end
+ end
+end

0 comments on commit eddf9ed

Please sign in to comment.
Something went wrong with that request. Please try again.