Class: Mail::Matchers::HasSentEmailMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/mail/matchers/has_sent_mail.rb

Instance Method Summary collapse

Constructor Details

#initialize(_context) ⇒ HasSentEmailMatcher

Returns a new instance of HasSentEmailMatcher.



9
10
# File 'lib/mail/matchers/has_sent_mail.rb', line 9

def initialize(_context)
end

Instance Method Details

#bcc(recipient_or_list) ⇒ Object



44
45
46
47
48
# File 'lib/mail/matchers/has_sent_mail.rb', line 44

def bcc(recipient_or_list)
  @blind_copy_recipients ||= []
  @blind_copy_recipients.concat(Array(recipient_or_list))
  self
end

#cc(recipient_or_list) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/mail/matchers/has_sent_mail.rb', line 33

def cc(recipient_or_list)
  @copy_recipients ||= []

  if recipient_or_list.kind_of?(Array)
    @copy_recipients += recipient_or_list
  else
    @copy_recipients << recipient_or_list
  end
  self
end

#descriptionObject



96
97
98
99
# File 'lib/mail/matchers/has_sent_mail.rb', line 96

def description
  result = "send a matching email"
  result
end

#failure_messageObject



101
102
103
104
105
106
# File 'lib/mail/matchers/has_sent_mail.rb', line 101

def failure_message
  result = "Expected email to be sent "
  result += explain_expectations
  result += dump_deliveries
  result
end

#failure_message_when_negatedObject



108
109
110
111
112
113
# File 'lib/mail/matchers/has_sent_mail.rb', line 108

def failure_message_when_negated
  result = "Expected no email to be sent "
  result += explain_expectations
  result += dump_deliveries
  result
end

#from(sender) ⇒ Object



17
18
19
20
# File 'lib/mail/matchers/has_sent_mail.rb', line 17

def from(sender)
  @sender = sender
  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/mail/matchers/has_sent_mail.rb', line 12

def matches?(subject)
  matching_deliveries = filter_matched_deliveries(Mail::TestMailer.deliveries)
  !(matching_deliveries.empty?)
end

#matching_body(body_matcher) ⇒ Object



81
82
83
84
# File 'lib/mail/matchers/has_sent_mail.rb', line 81

def matching_body(body_matcher)
  @body_matcher = body_matcher
  self
end

#matching_subject(subject_matcher) ⇒ Object



71
72
73
74
# File 'lib/mail/matchers/has_sent_mail.rb', line 71

def matching_subject(subject_matcher)
  @subject_matcher = subject_matcher
  self
end

#to(recipient_or_list) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/mail/matchers/has_sent_mail.rb', line 22

def to(recipient_or_list)
  @recipients ||= []

  if recipient_or_list.kind_of?(Array)
    @recipients += recipient_or_list
  else
    @recipients << recipient_or_list
  end
  self
end

#with_any_attachmentsObject



61
62
63
64
# File 'lib/mail/matchers/has_sent_mail.rb', line 61

def with_any_attachments
  @having_attachments = true
  self
end

#with_attachments(attachments) ⇒ Object



50
51
52
53
54
# File 'lib/mail/matchers/has_sent_mail.rb', line 50

def with_attachments(attachments)
  @attachments ||= []
  @attachments.concat(Array(attachments))
  self
end

#with_body(body) ⇒ Object



76
77
78
79
# File 'lib/mail/matchers/has_sent_mail.rb', line 76

def with_body(body)
  @body = body
  self
end

#with_html(body) ⇒ Object



86
87
88
89
# File 'lib/mail/matchers/has_sent_mail.rb', line 86

def with_html(body)
  @html_part_body = body
  self
end

#with_no_attachmentsObject



56
57
58
59
# File 'lib/mail/matchers/has_sent_mail.rb', line 56

def with_no_attachments
  @having_attachments = false
  self
end

#with_subject(subject) ⇒ Object



66
67
68
69
# File 'lib/mail/matchers/has_sent_mail.rb', line 66

def with_subject(subject)
  @subject = subject
  self
end

#with_text(body) ⇒ Object



91
92
93
94
# File 'lib/mail/matchers/has_sent_mail.rb', line 91

def with_text(body)
  @text_part_body = body
  self
end