Class: Shoulda::ActionMailer::Matchers::HaveSentEmailMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/action_mailer/matchers/have_sent_email.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeHaveSentEmailMatcher

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

#descriptionObject



64
65
66
# File 'lib/shoulda/action_mailer/matchers/have_sent_email.rb', line 64

def description
  "send an email"
end

#failure_messageObject



56
57
58
# File 'lib/shoulda/action_mailer/matchers/have_sent_email.rb', line 56

def failure_message
  "Expected #{expectation}"
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

Returns:

  • (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_messageObject



60
61
62
# File 'lib/shoulda/action_mailer/matchers/have_sent_email.rb', line 60

def negative_failure_message
  "Did not expect #{expectation}"
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