Class: Mail::Matchers::HasSentEmailMatcher

### Home Classes Methods

### In Files

- lib/mail/matchers/has_sent_mail.rb

### Parent

Object

### Methods

- ::new
- #bcc
- #cc
- #description
- #dump_deliveries
- #explain_expectations
- #failure_message
- #failure_message_when_negated
- #filter_matched_deliveries
- #from
- #matches?
- #matches_on_blind_copy_recipients?
- #matches_on_body?
- #matches_on_body_matcher?
- #matches_on_copy_recipients?
- #matches_on_recipients?
- #matches_on_sender?
- #matches_on_subject?
- #matches_on_subject_matcher?
- #matching_body
- #matching_subject
- #to
- #with_body
- #with_subject

### Files

- TODO.rdoc

### Class/Module Index

Quicksearch

- Mail
- Mail::Address
- Mail::AddressContainer
- Mail::AttachmentsList
- Mail::BccField
- Mail::Body
- Mail::CcField
- Mail::CheckDeliveryParams
- Mail::CommentsField
- Mail::Constants
- Mail::ContentDescriptionField
- Mail::ContentDispositionField
- Mail::ContentIdField
- Mail::ContentLocationField
- Mail::ContentTransferEncodingElement
- Mail::ContentTransferEncodingField
- Mail::ContentTypeField
- Mail::DateField
- Mail::Encodings
- Mail::Encodings::Base64
- Mail::Encodings::Binary
- Mail::Encodings::EightBit
- Mail::Encodings::QuotedPrintable
- Mail::Encodings::SevenBit
- Mail::Encodings::TransferEncoding
- Mail::Encodings::UnixToUnix
- Mail::Envelope
- Mail::EnvelopeFromElement
- Mail::Exim
- Mail::Field
- Mail::Field::FieldError
- Mail::FieldList
- Mail::FileDelivery
- Mail::FromField
- Mail::Header
- Mail::IMAP
- Mail::InReplyToField
- Mail::IndifferentHash
- Mail::KeywordsField
- Mail::Matchers
- Mail::Matchers::HasSentEmailMatcher
- Mail::MessageIdField
- Mail::MessageIdsElement
- Mail::MimeVersionElement
- Mail::MimeVersionField
- Mail::Multibyte
- Mail::Multibyte::EncodingError
- Mail::OptionalField
- Mail::POP3
- Mail::ParameterHash
- Mail::Parsers
- Mail::Parsers::AddressListsParser
- Mail::Parsers::ContentDispositionParser
- Mail::Parsers::ContentLocationParser
- Mail::Parsers::ContentTransferEncodingParser
- Mail::Parsers::ContentTypeParser
- Mail::Parsers::DateTimeParser
- Mail::Parsers::EnvelopeFromParser
- Mail::Parsers::MessageIdsParser
- Mail::Parsers::MimeVersionParser
- Mail::Parsers::PhraseListsParser
- Mail::Parsers::Ragel
- Mail::Parsers::Ragel::AddressListsMachine
- Mail::Parsers::Ragel::ContentDispositionMachine
- Mail::Parsers::Ragel::ContentLocationMachine
- Mail::Parsers::Ragel::ContentTransferEncodingMachine
- Mail::Parsers::Ragel::ContentTypeMachine
- Mail::Parsers::Ragel::DateTimeMachine
- Mail::Parsers::Ragel::EnvelopeFromMachine
- Mail::Parsers::Ragel::MessageIdsMachine
- Mail::Parsers::Ragel::MimeVersionMachine
- Mail::Parsers::Ragel::PhraseListsMachine
- Mail::Parsers::Ragel::ReceivedMachine
- Mail::Parsers::Ragel::Ruby
- Mail::Parsers::ReceivedParser
- Mail::Part
- Mail::PartsList
- Mail::PhraseList
- Mail::ReceivedElement
- Mail::ReceivedField
- Mail::ReferencesField
- Mail::ReplyToField
- Mail::ResentBccField
- Mail::ResentCcField
- Mail::ResentDateField
- Mail::ResentFromField
- Mail::ResentMessageIdField
- Mail::ResentSenderField
- Mail::ResentToField
- Mail::Retriever
- Mail::ReturnPathField
- Mail::Ruby18
- Mail::Ruby19
- Mail::Ruby19::BestEffortCharsetEncoder
- Mail::Ruby19::StrictCharsetEncoder
- Mail::SMTP
- Mail::SMTPConnection
- Mail::SenderField
- Mail::Sendmail
- Mail::StructuredField
- Mail::SubjectField
- Mail::TestMailer
- Mail::TestRetriever
- Mail::ToField
- Mail::UnstructuredField
- Mail::Utilities
- Mail::VERSION
- Net
- Net::SMTP
- Object
- String

No matching classes.

# Mail::Matchers::HasSentEmailMatcher

### Public Class Methods

new(_context) click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 8
    def initialize(_context)
    end

### Public Instance Methods

bcc(recipient_or_list) click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 43
    def bcc(recipient_or_list)
      @blind_copy_recipients ||= []

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

cc(recipient_or_list) click to toggle source

    # 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

description() click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 75
    def description
      result = "send a matching email"
      result
    end

failure_message() click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 80
    def failure_message
      result = "Expected email to be sent "
      result += explain_expectations
      result += dump_deliveries
      result
    end

failure_message_when_negated() click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 87
    def failure_message_when_negated
      result = "Expected no email to be sent "
      result += explain_expectations
      result += dump_deliveries
      result
    end

from(sender) click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 16
    def from(sender)
      @sender = sender
      self
    end

matches?(subject) click to toggle source

    # 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) click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 70
    def matching_body(body_matcher)
      @body_matcher = body_matcher
      self
    end

matching_subject(subject_matcher) click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 60
    def matching_subject(subject_matcher)
      @subject_matcher = subject_matcher
      self
    end

to(recipient_or_list) click to toggle source

    # 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_body(body) click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 65
    def with_body(body)
      @body = body
      self
    end

with_subject(subject) click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 55
    def with_subject(subject)
      @subject = subject
      self
    end

### Protected Instance Methods

dump_deliveries() click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 152
    def dump_deliveries
      "(actual deliveries: " + Mail::TestMailer.deliveries.inspect + ")"
    end

explain_expectations() click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 139
    def explain_expectations
      result = ''
      result += "from #{@sender} " if instance_variable_defined?('@sender')
      result += "to #{@recipients.inspect} " if instance_variable_defined?('@recipients')
      result += "cc #{@copy_recipients.inspect} " if instance_variable_defined?('@copy_recipients')
      result += "bcc #{@blind_copy_recipients.inspect} " if instance_variable_defined?('@blind_copy_recipients')
      result += "with subject \"#{@subject}\" " if instance_variable_defined?('@subject')
      result += "with subject matching \"#{@subject_matcher}\" " if instance_variable_defined?('@subject_matcher')
      result += "with body \"#{@body}\" " if instance_variable_defined?('@body')
      result += "with body matching \"#{@body_matcher}\" " if instance_variable_defined?('@body_matcher')
      result
    end

filter_matched_deliveries(deliveries) click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 96
    def filter_matched_deliveries(deliveries)
      candidate_deliveries = deliveries

      %(sender recipients copy_recipients blind_copy_recipients subject subject_matcher body body_matcher).each do |modifier_name|
        next unless instance_variable_defined?("@#{modifier_name}")
        candidate_deliveries = candidate_deliveries.select{|matching_delivery| self.send("matches_on_#{modifier_name}?", matching_delivery)}
      end

      candidate_deliveries
    end

matches_on_blind_copy_recipients?(delivery) click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 119
    def matches_on_blind_copy_recipients?(delivery)
      @blind_copy_recipients.all? {|recipient| delivery.bcc.include?(recipient) }
    end

matches_on_body?(delivery) click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 131
    def matches_on_body?(delivery)
      delivery.body == @body
    end

matches_on_body_matcher?(delivery) click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 135
    def matches_on_body_matcher?(delivery)
      @body_matcher.match delivery.body.raw_source
    end

matches_on_copy_recipients?(delivery) click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 115
    def matches_on_copy_recipients?(delivery)
      @copy_recipients.all? {|recipient| delivery.cc.include?(recipient) }
    end

matches_on_recipients?(delivery) click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 111
    def matches_on_recipients?(delivery)
      @recipients.all? {|recipient| delivery.to.include?(recipient) }
    end

matches_on_sender?(delivery) click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 107
    def matches_on_sender?(delivery)
      delivery.from.include?(@sender)
    end

matches_on_subject?(delivery) click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 123
    def matches_on_subject?(delivery)
      delivery.subject == @subject
    end

matches_on_subject_matcher?(delivery) click to toggle source

    # File lib/mail/matchers/has_sent_mail.rb, line 127
    def matches_on_subject_matcher?(delivery)
      @subject_matcher.match delivery.subject
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.