# File lib/mail/matchers/has_sent_mail.rb, line 52 def description result = "send a matching email" result end
# File lib/mail/matchers/has_sent_mail.rb, line 57 def failure_message result = "Expected email to be sent " result += explain_expectations result += dump_deliveries result end
# File lib/mail/matchers/has_sent_mail.rb, line 16 def from(sender) @sender = sender self end
# 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
# File lib/mail/matchers/has_sent_mail.rb, line 47 def matching_body(body_matcher) @body_matcher = body_matcher self end
# File lib/mail/matchers/has_sent_mail.rb, line 37 def matching_subject(subject_matcher) @subject_matcher = subject_matcher self end
# File lib/mail/matchers/has_sent_mail.rb, line 64 def negative_failure_message result = "Expected no email to be sent " result += explain_expectations result += dump_deliveries result end
# 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
# File lib/mail/matchers/has_sent_mail.rb, line 119 def dump_deliveries "(actual deliveries: " + Mail::TestMailer.deliveries.inspect + ")" end
# File lib/mail/matchers/has_sent_mail.rb, line 108 def explain_expectations result = '' result += "from #{@sender} " if instance_variable_defined?('@sender') result += "to #{@recipients.inspect} " if instance_variable_defined?('@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
# File lib/mail/matchers/has_sent_mail.rb, line 73 def filter_matched_deliveries(deliveries) candidate_deliveries = deliveries %(sender 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
# File lib/mail/matchers/has_sent_mail.rb, line 100 def matches_on_body?(delivery) delivery.body == @body end
# File lib/mail/matchers/has_sent_mail.rb, line 104 def matches_on_body_matcher?(delivery) @body_matcher.match delivery.body.raw_source end
# File lib/mail/matchers/has_sent_mail.rb, line 88 def matches_on_recipients?(delivery) @recipients.all? {|recipient| delivery.to.include?(recipient) } end
# File lib/mail/matchers/has_sent_mail.rb, line 84 def matches_on_sender?(delivery) delivery.from.include?(@sender) end
Generated with the Darkfish Rdoc Generator 2.