Class: EmailSpec::Matchers::CcTo

Inherits:
Object
  • Object
show all
Defined in:
lib/email_spec/matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_email_addresses_or_objects_that_respond_to_email) ⇒ CcTo

Returns a new instance of CcTo.



136
137
138
139
140
141
142
# File 'lib/email_spec/matchers.rb', line 136

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|
    email_or_object.kind_of?(String) ? email_or_object : email_or_object.email
  end

  @expected_email_addresses = emails.sort
end

Instance Method Details

#descriptionObject



144
145
146
# File 'lib/email_spec/matchers.rb', line 144

def description
  "be cc'd to #{@expected_email_addresses.inspect}"
end

#failure_messageObject



154
155
156
# File 'lib/email_spec/matchers.rb', line 154

def failure_message
  "expected #{@email.inspect} to cc to #{@expected_email_addresses.inspect}, but it was cc'd to #{@actual_recipients.inspect}"
end

#matches?(email) ⇒ Boolean

Returns:

  • (Boolean)


148
149
150
151
152
# File 'lib/email_spec/matchers.rb', line 148

def matches?(email)
  @email = email
  @actual_recipients = (Array(email.cc) || []).sort
  @actual_recipients == @expected_email_addresses
end

#negative_failure_messageObject



158
159
160
# File 'lib/email_spec/matchers.rb', line 158

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