Class: EmailSpec::Matchers::IncludeEmailWithSubject
- Inherits:
-
Object
- Object
- EmailSpec::Matchers::IncludeEmailWithSubject
- Defined in:
- lib/email_spec/matchers.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(subject) ⇒ IncludeEmailWithSubject
constructor
A new instance of IncludeEmailWithSubject.
- #matches?(emails) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(subject) ⇒ IncludeEmailWithSubject
Returns a new instance of IncludeEmailWithSubject.
213 214 215 |
# File 'lib/email_spec/matchers.rb', line 213 def initialize(subject) @expected_subject = subject end |
Instance Method Details
#description ⇒ Object
217 218 219 220 221 222 223 |
# File 'lib/email_spec/matchers.rb', line 217 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_message ⇒ Object
234 235 236 237 238 239 240 |
# File 'lib/email_spec/matchers.rb', line 234 def 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 |
#matches?(emails) ⇒ Boolean
225 226 227 228 229 230 231 232 |
# File 'lib/email_spec/matchers.rb', line 225 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 |
#negative_failure_message ⇒ Object
242 243 244 245 246 247 248 |
# File 'lib/email_spec/matchers.rb', line 242 def 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 |