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



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

def initialize(_context)
end

Instance Method Details

#bcc(recipient_or_list) ⇒ Object



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

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

#cc(recipient_or_list) ⇒ Object



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

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



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

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

#failure_messageObject



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

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

#failure_message_when_negatedObject



97
98
99
100
101
102
# File 'lib/mail/matchers/has_sent_mail.rb', line 97

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

#from(sender) ⇒ Object



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

def from(sender)
  @sender = sender
  self
end

#matches?(subject) ⇒ Boolean



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

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

#matching_body(body_matcher) ⇒ Object



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

def matching_body(body_matcher)
  @body_matcher = body_matcher
  self
end

#matching_subject(subject_matcher) ⇒ Object



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

def matching_subject(subject_matcher)
  @subject_matcher = subject_matcher
  self
end

#to(recipient_or_list) ⇒ Object



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

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



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

def with_any_attachments
  @having_attachments = true
  self
end

#with_attachments(attachments) ⇒ Object



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

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

#with_body(body) ⇒ Object



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

def with_body(body)
  @body = body
  self
end

#with_no_attachmentsObject



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

def with_no_attachments
  @having_attachments = false
  self
end

#with_subject(subject) ⇒ Object



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

def with_subject(subject)
  @subject = subject
  self
end