Module: IdleMailer::Testing::Helpers
- Included in:
- IdleMailer::Testing
- Defined in:
- lib/idlemailer/testing.rb
Overview
Helpers for your tests
Instance Method Summary collapse
-
#clear_mail! ⇒ Object
Clears sent mail.
-
#mail_from(addr) ⇒ Object
Returns all mail sent from the given email address.
-
#mail_to(addr, subject = nil, body = nil) ⇒ Object
Returns all mail sent to the given email address.
-
#mail_with_body(pattern) ⇒ Object
Returns all mail sent matching the given body (Regexp).
-
#mail_with_subject(pattern) ⇒ Object
Returns all mail sent matching the given subject (String or Regexp).
-
#sent_mail ⇒ Object
Returns all sent mail.
-
#sent_mail_from?(addr) ⇒ Boolean
Returns true if any mail was sent from the given email address.
-
#sent_mail_to?(addr, subject = nil, body = nil) ⇒ Boolean
Returns true if any mail was sent to the given email address.
-
#sent_mail_with_body?(pattern) ⇒ Boolean
Returns true if any mail was sent matching the given body (Regexp).
-
#sent_mail_with_subject?(pattern) ⇒ Boolean
Returns true if any mail was sent matching the given subject (String or Regexp).
Instance Method Details
#clear_mail! ⇒ Object
Clears sent mail.
54 55 56 |
# File 'lib/idlemailer/testing.rb', line 54 def clear_mail! Mail::TestMailer.deliveries.clear end |
#mail_from(addr) ⇒ Object
Returns all mail sent from the given email address.
27 28 29 |
# File 'lib/idlemailer/testing.rb', line 27 def mail_from(addr) sent_mail.select { |m| m.from.include? addr } end |
#mail_to(addr, subject = nil, body = nil) ⇒ Object
Returns all mail sent to the given email address. You may pass subject and body patterns to get more specific (String or Regexp).
32 33 34 35 36 |
# File 'lib/idlemailer/testing.rb', line 32 def mail_to(addr, subject = nil, body = nil) sent_mail.select { |m| m.to.include?(addr) && (subject.nil? || subject === m.subject) && (body.nil? || body === m.to_s) } end |
#mail_with_body(pattern) ⇒ Object
Returns all mail sent matching the given body (Regexp).
44 45 46 |
# File 'lib/idlemailer/testing.rb', line 44 def mail_with_body(pattern) sent_mail.select { |m| pattern === m.to_s } end |
#mail_with_subject(pattern) ⇒ Object
Returns all mail sent matching the given subject (String or Regexp).
39 40 41 |
# File 'lib/idlemailer/testing.rb', line 39 def mail_with_subject(pattern) sent_mail.select { |m| pattern === m.subject } end |
#sent_mail ⇒ Object
Returns all sent mail.
49 50 51 |
# File 'lib/idlemailer/testing.rb', line 49 def sent_mail Mail::TestMailer.deliveries end |
#sent_mail_from?(addr) ⇒ Boolean
Returns true if any mail was sent from the given email address.
7 8 9 |
# File 'lib/idlemailer/testing.rb', line 7 def sent_mail_from?(addr) mail_from(addr).any? end |
#sent_mail_to?(addr, subject = nil, body = nil) ⇒ Boolean
Returns true if any mail was sent to the given email address. You may pass subject and body patterns to get more specific (String or Regexp).
12 13 14 |
# File 'lib/idlemailer/testing.rb', line 12 def sent_mail_to?(addr, subject = nil, body = nil) mail_to(addr, subject, body).any? end |
#sent_mail_with_body?(pattern) ⇒ Boolean
Returns true if any mail was sent matching the given body (Regexp).
22 23 24 |
# File 'lib/idlemailer/testing.rb', line 22 def sent_mail_with_body?(pattern) mail_with_body(pattern).any? end |
#sent_mail_with_subject?(pattern) ⇒ Boolean
Returns true if any mail was sent matching the given subject (String or Regexp).
17 18 19 |
# File 'lib/idlemailer/testing.rb', line 17 def sent_mail_with_subject?(pattern) mail_with_subject(pattern).any? end |