Class: EmailSpec::Matchers::IncludeEmailWithSubject

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

Instance Method Summary collapse

Constructor Details

#initialize(subject) ⇒ IncludeEmailWithSubject

Returns a new instance of IncludeEmailWithSubject.



232
233
234
# File 'lib/email_spec/matchers.rb', line 232

def initialize(subject)
  @expected_subject = subject
end

Instance Method Details

#descriptionObject



236
237
238
239
240
241
242
# File 'lib/email_spec/matchers.rb', line 236

def description
  if @expected_subject.is_a?(String)
    "include email with subject of #{@expected_subject.inspect}"
  else
    "include email with subject matching #{@expected_subject.inspect}"
  end
end

#failure_messageObject



253
254
255
256
257
258
259
# File 'lib/email_spec/matchers.rb', line 253

def failure_message
  if @expected_subject.is_a?(String)
    "expected at least one email to have the subject #{@expected_subject.inspect} but none did. Subjects were #{@given_emails.map(&:subject).inspect}"
  else
    "expected at least one email to have a subject matching #{@expected_subject.inspect}, but none did. Subjects were #{@given_emails.map(&:subject).inspect}"
  end
end

#failure_message_when_negatedObject Also known as: negative_failure_message



261
262
263
264
265
266
267
# File 'lib/email_spec/matchers.rb', line 261

def failure_message_when_negated
  if @expected_subject.is_a?(String)
    "expected no email with the subject #{@expected_subject.inspect} but found at least one. Subjects were #{@given_emails.map(&:subject).inspect}"
  else
    "expected no email to have a subject matching #{@expected_subject.inspect} but found at least one. Subjects were #{@given_emails.map(&:subject).inspect}"
  end
end

#matches?(emails) ⇒ Boolean

Returns:

  • (Boolean)


244
245
246
247
248
249
250
251
# File 'lib/email_spec/matchers.rb', line 244

def matches?(emails)
  @given_emails = emails
  if @expected_subject.is_a?(String)
    @given_emails.map(&:subject).include?(@expected_subject)
  else
    !!(@given_emails.any?{ |mail| mail.subject =~ @expected_subject })
  end
end