Permalink
Browse files

fix action mailer test method

  • Loading branch information...
1 parent 6989256 commit 832f46b9fc71c28a14548ebeac92f41766f3f70a Chad Pytel committed Jun 11, 2010
@@ -32,13 +32,15 @@ def to(recipient)
end
def matches?(subject)
- @mail = subject
- @subject_failed = !regexp_or_string_match(@mail.subject, @email_subject) if @email_subject
- @body_failed = !regexp_or_string_match(@mail.body, @body) if @body
- @sender_failed = !regexp_or_string_match_in_array(@mail.from, @sender) if @sender
- @recipient_failed = !regexp_or_string_match_in_array(@mail.to, @recipient) if @recipient
+ ::ActionMailer::Base.deliveries.each do |mail|
+ @subject_failed = !regexp_or_string_match(mail.subject, @email_subject) if @email_subject
+ @body_failed = !regexp_or_string_match(mail.body, @body) if @body
+ @sender_failed = !regexp_or_string_match_in_array(mail.from, @sender) if @sender
+ @recipient_failed = !regexp_or_string_match_in_array(mail.to, @recipient) if @recipient
+ return true unless anything_failed?
+ end
- !anything_failed?
+ false
end
def failure_message
@@ -19,35 +19,35 @@ def the_email
end
end
if defined?(AbstractController::Rendering)
- @mail = Mailer.the_email
+ ::ActionMailer::Base.deliveries << Mailer.the_email
else
- @mail = Mailer.create_the_email
+ ::ActionMailer::Base.deliveries << Mailer.create_the_email
end
end
should "accept based on the subject" do
- assert_accepts have_sent_email.with_subject(/is spam$/), @mail
- assert_rejects have_sent_email.with_subject(/totally safe/), @mail
+ assert_accepts have_sent_email.with_subject(/is spam$/), nil
+ assert_rejects have_sent_email.with_subject(/totally safe/), nil
end
should "accept based on the sender" do
- assert_accepts have_sent_email.from('do-not-reply@example.com'), @mail
- assert_rejects have_sent_email.from('you@example.com'), @mail
+ assert_accepts have_sent_email.from('do-not-reply@example.com'), nil
+ assert_rejects have_sent_email.from('you@example.com'), nil
end
should "accept based on the body" do
- assert_accepts have_sent_email.with_body(/is spam\./), @mail
- assert_rejects have_sent_email.with_body(/totally safe/), @mail
+ assert_accepts have_sent_email.with_body(/is spam\./), nil
+ assert_rejects have_sent_email.with_body(/totally safe/), nil
end
should "accept baed on the recipienct" do
- assert_accepts have_sent_email.to('myself@me.com'), @mail
- assert_rejects have_sent_email.to('you@example.com'), @mail
+ assert_accepts have_sent_email.to('myself@me.com'), nil
+ assert_rejects have_sent_email.to('you@example.com'), nil
end
should "chain" do
- assert_accepts have_sent_email.with_subject(/spam/).from('do-not-reply@example.com').with_body(/spam/).to('myself@me.com'), @mail
- assert_rejects have_sent_email.with_subject(/ham/).from('you@example.com').with_body(/ham/).to('them@example.com'), @mail
+ assert_accepts have_sent_email.with_subject(/spam/).from('do-not-reply@example.com').with_body(/spam/).to('myself@me.com'), nil
+ assert_rejects have_sent_email.with_subject(/ham/).from('you@example.com').with_body(/ham/).to('them@example.com'), nil
end
end
end

0 comments on commit 832f46b

Please sign in to comment.