Sha256: 09e33da2aee3a7ba4262ee6c95e8785a0b72c1b430c52fc8a78e57aa5a12bf62

Contents?: true

Size: 1.01 KB

Versions: 8

Compression:

Stored size: 1.01 KB

Contents

module EmailSpec

    module Matchers
          
    class DeliverTo

      def initialize(expected_email_addresses)
        @expected_email_addresses = expected_email_addresses.sort
      end

      def matches?(email)
        @email = email
        @actual_recipients = (email.to || []).sort
        @actual_recipients.should == @expected_email_addresses
        true
      end

      def failure_message
        "expected #{@email.inspect} to deliver to #{@expected_email_addresses.inspect}, but it delievered to #{@actual_recipients.inspect}"
      end

      def negative_failure_message
        "expected #{@email.inspect} not to deliver to #{@expected_email_addresses.inspect}, but it did"
      end
    end

    def deliver_to(*expected_email_addresses_or_objects_that_respond_to_email)
      emails = expected_email_addresses_or_objects_that_respond_to_email.map do |email_or_object|
        email_or_object.kind_of?(String) ? email_or_object : email_or_object.email
      end
      DeliverTo.new(emails)
    end
  end
end

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
bmabey-email_spec-0.0.5 lib/email_spec/email_spec_matchers.rb
bmabey-email_spec-0.0.6 lib/email_spec/matchers.rb
mischa-email-spec-0.0.1 lib/email_spec/email_spec_matchers.rb
mischa-email-spec-0.0.2 lib/email_spec/email_spec_matchers.rb
mischa-email_spec-0.0.1 lib/email_spec/email_spec_matchers.rb
mischa-email_spec-0.0.2 lib/email_spec/email_spec_matchers.rb
mischa-email_spec-0.0.3 lib/email_spec/email_spec_matchers.rb
mischa-email_spec-0.0.4 lib/email_spec/email_spec_matchers.rb