Class: RSpec::MailMatcher::SubjectMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/mail_matcher/subject_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ SubjectMatcher

Returns a new instance of SubjectMatcher.



3
4
5
# File 'lib/rspec/mail_matcher/subject_matcher.rb', line 3

def initialize(expected)
  @expected = expected
end

Instance Method Details

#descriptionObject



16
17
18
19
20
21
22
# File 'lib/rspec/mail_matcher/subject_matcher.rb', line 16

def description
  if @expected.kind_of?(String)
    "have subject including #{@expected.inspect}"
  else
    "have subject matching #{@expected.inspect}"
  end
end

#failure_messageObject



24
25
26
27
28
29
30
# File 'lib/rspec/mail_matcher/subject_matcher.rb', line 24

def failure_message
  if @expected.kind_of?(String)
    "expected the subject to contain #{@expected.inspect} but was #{@mail.subject.inspect}"
  else
    "expected the subject to match #{@expected.inspect}, but did not. Actual body was: #{@mail.subject.inspect}"
  end
end

#matches?(mail) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
# File 'lib/rspec/mail_matcher/subject_matcher.rb', line 7

def matches?(mail)
  @mail = mail
  if @expected.kind_of?(String)
    @mail.subject.include?(@expected)
  else
    !!(@mail.subject =~ @expected)
  end
end