Class: EmailSpec::Matchers::HaveSubject

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

Instance Method Summary collapse

Constructor Details

#initialize(subject) ⇒ HaveSubject

Returns a new instance of HaveSubject.



184
185
186
# File 'lib/email_spec/matchers.rb', line 184

def initialize(subject)
  @expected_subject = subject
end

Instance Method Details

#descriptionObject



188
189
190
191
192
193
194
# File 'lib/email_spec/matchers.rb', line 188

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

#failure_messageObject



205
206
207
208
209
210
211
# File 'lib/email_spec/matchers.rb', line 205

def failure_message
  if @expected_subject.is_a?(String)
    "expected the subject to be #{@expected_subject.inspect} but was #{@given_subject.inspect}"
  else
    "expected the subject to match #{@expected_subject.inspect}, but did not.  Actual subject was: #{@given_subject.inspect}"
  end
end

#failure_message_when_negatedObject Also known as: negative_failure_message



213
214
215
216
217
218
219
# File 'lib/email_spec/matchers.rb', line 213

def failure_message_when_negated
  if @expected_subject.is_a?(String)
    "expected the subject not to be #{@expected_subject.inspect} but was"
  else
    "expected the subject not to match #{@expected_subject.inspect} but #{@given_subject.inspect} does match it."
  end
end

#matches?(email) ⇒ Boolean

Returns:

  • (Boolean)


196
197
198
199
200
201
202
203
# File 'lib/email_spec/matchers.rb', line 196

def matches?(email)
  @given_subject = email.subject
  if @expected_subject.is_a?(String)
    @given_subject == @expected_subject
  else
    !!(@given_subject =~ @expected_subject)
  end
end