class RSpec::Rails::Matchers::SendEmail
@see RSpec::Rails::Matchers#send_email
Matcher class for ‘send_email`. Should not be instantiated directly.
@api private
def define_matched_emails(block)
def define_matched_emails(block) before = deliveries.dup block.call after = deliveries @diff = after - before @matched_emails = @diff.select(&method(:matched_email?)) end
def deliveries
def deliveries ActionMailer::Base.deliveries end
def diffable?
def diffable? true end
def failure_message
-
(String)
-
Other tags:
- Api: - private
def failure_message result = if multiple_match? "More than 1 matching emails were sent." else "No matching emails were sent." end "#{result}#{sent_emails_message}" end
def failure_message_when_negated
-
(String)
-
Other tags:
- Api: - private
def failure_message_when_negated "Expected not to send an email but it was sent." end
def initialize(criteria)
def initialize(criteria) @criteria = criteria end
def matched_email?(email)
def matched_email?(email) @criteria.all? do |attr, value| expected = case attr when :to, :from, :cc, :bcc then Array(value) else value end values_match?(expected, email.public_send(attr)) end end
def matches?(block)
def matches?(block) define_matched_emails(block) @matched_emails.one? end
def multiple_match?
def multiple_match? @matched_emails.many? end
def sent_emails_message
def sent_emails_message if @diff.empty? "\n\nThere were no any emails sent inside the expectation block." else sent_emails = @diff.map do |email| inspected = INSPECT_EMAIL_ATTRIBUTES.map { |attr| "#{attr}: #{email.public_send(attr)}" }.join(", ") "- #{inspected}" end.join("\n") "\n\nThe following emails were sent:\n#{sent_emails}" end end
def supports_block_expectations?
- Api: - private
def supports_block_expectations? true end
def supports_value_expectations?
- Api: - private
def supports_value_expectations? false end