Class: Shoulda::ActionMailer::Matchers::HaveSentEmailMatcher
- Inherits:
-
Object
- Object
- Shoulda::ActionMailer::Matchers::HaveSentEmailMatcher
- Defined in:
- lib/shoulda/action_mailer/matchers/have_sent_email.rb
Overview
:nodoc:
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #from(sender) ⇒ Object
-
#initialize ⇒ HaveSentEmailMatcher
constructor
A new instance of HaveSentEmailMatcher.
- #matches?(subject) ⇒ Boolean
- #negative_failure_message ⇒ Object
- #to(recipient) ⇒ Object
- #with_body(body) ⇒ Object
- #with_subject(email_subject) ⇒ Object
Constructor Details
#initialize ⇒ HaveSentEmailMatcher
Returns a new instance of HaveSentEmailMatcher.
21 22 |
# File 'lib/shoulda/action_mailer/matchers/have_sent_email.rb', line 21 def initialize end |
Instance Method Details
#description ⇒ Object
88 89 90 |
# File 'lib/shoulda/action_mailer/matchers/have_sent_email.rb', line 88 def description "send an email" end |
#failure_message ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/shoulda/action_mailer/matchers/have_sent_email.rb', line 56 def msg = "expected a sent email" msg += " with subject #{@email_subject.inspect}" if @subject_failed msg += " with body #{@body.inspect}" if @body_failed msg += " from #{@sender.inspect}" if @sender_failed msg += " to #{@recipient.inspect}" if @recipient_failed if anything_failed? msg += " but got" msg += " the subject #{@mail.subject.inspect}" if @subject_failed msg += " the body #{@mail.body.inspect}" if @body_failed msg += " from #{@mail.from.inspect}" if @sender_failed msg += " to #{@mail.to.inspect}" if @recipient_failed end msg end |
#from(sender) ⇒ Object
29 30 31 32 |
# File 'lib/shoulda/action_mailer/matchers/have_sent_email.rb', line 29 def from(sender) @sender = sender self end |
#matches?(subject) ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/shoulda/action_mailer/matchers/have_sent_email.rb', line 44 def matches?(subject) ::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 false end |
#negative_failure_message ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/shoulda/action_mailer/matchers/have_sent_email.rb', line 72 def msg = "expected no sent email" msg += " with subject #{@email_subject.inspect}" if @subject_failed msg += " with body #{@body.inspect}" if @body_failed msg += " from #{@sender.inspect}" if @sender_failed msg += " to #{@recipient.inspect}" if @recipient_failed if anything_failed? msg += " but got" msg += " the subject #{@mail.subject.inspect}" if @subject_failed msg += " the body #{@mail.body.inspect}" if @body_failed msg += " from #{@mail.from.inspect}" if @sender_failed msg += " to #{@mail.to.inspect}" if @recipient_failed end msg end |
#to(recipient) ⇒ Object
39 40 41 42 |
# File 'lib/shoulda/action_mailer/matchers/have_sent_email.rb', line 39 def to(recipient) @recipient = recipient self end |
#with_body(body) ⇒ Object
34 35 36 37 |
# File 'lib/shoulda/action_mailer/matchers/have_sent_email.rb', line 34 def with_body(body) @body = body self end |
#with_subject(email_subject) ⇒ Object
24 25 26 27 |
# File 'lib/shoulda/action_mailer/matchers/have_sent_email.rb', line 24 def with_subject(email_subject) @email_subject = email_subject self end |