lib/email_spec/matchers.rb in email_spec-0.3.1 vs lib/email_spec/matchers.rb in email_spec-0.3.5
- old
+ new
@@ -21,11 +21,11 @@
@actual_recipients = (email.to || []).sort
@actual_recipients == @expected_email_addresses
end
def failure_message
- "expected #{@email.inspect} to deliver to #{@expected_email_addresses.inspect}, but it delievered to #{@actual_recipients.inspect}"
+ "expected #{@email.inspect} to deliver to #{@expected_email_addresses.inspect}, but it delivered to #{@actual_recipients.inspect}"
end
def negative_failure_message
"expected #{@email.inspect} not to deliver to #{@expected_email_addresses.inspect}, but it did"
end
@@ -34,9 +34,40 @@
def deliver_to(*expected_email_addresses_or_objects_that_respond_to_email)
DeliverTo.new(expected_email_addresses_or_objects_that_respond_to_email.flatten)
end
alias :be_delivered_to :deliver_to
+
+ class DeliverFrom
+
+ def initialize(email)
+ @expected_email_addresses = email
+ end
+
+ def description
+ "be delivered from #{@expected_email_addresses.inspect}"
+ end
+
+ def matches?(email)
+ @email = email
+ @actual_sender = (email.from || []).first
+ @actual_sender.eql? @expected_email_addresses
+ end
+
+ def failure_message
+ "expected #{@email.inspect} to deliver from #{@expected_email_addresses.inspect}, but it delivered from #{@actual_sender.inspect}"
+ end
+
+ def negative_failure_message
+ "expected #{@email.inspect} not to deliver from #{@expected_email_addresses.inspect}, but it did"
+ end
+ end
+
+ def deliver_from(email)
+ DeliverFrom.new(email)
+ end
+
+ alias :be_delivered_from :deliver_from
class BccTo
def initialize(expected_email_addresses_or_objects_that_respond_to_email)
emails = expected_email_addresses_or_objects_that_respond_to_email.map do |email_or_object|