Class: Appydays::SpecHelpers::HaveALineMatching

Inherits:
Object
  • Object
show all
Includes:
RSpec::Matchers::Composable
Defined in:
lib/appydays/spec_helpers.rb

Overview

:section: Matchers

Instance Method Summary collapse

Constructor Details

#initialize(regexp) ⇒ HaveALineMatching

Returns a new instance of HaveALineMatching.



24
25
26
# File 'lib/appydays/spec_helpers.rb', line 24

def initialize(regexp)
  @regexp = regexp
end

Instance Method Details

#failure_messageObject Also known as: failure_message_for_should



36
37
38
# File 'lib/appydays/spec_helpers.rb', line 36

def failure_message
  return "expected %p to have at least one line matching %p" % [@target, @regexp]
end

#failure_message_when_negatedObject Also known as: failure_message_for_should_not



42
43
44
# File 'lib/appydays/spec_helpers.rb', line 42

def failure_message_when_negated
  return "expected %p not to have any lines matching %p, but it has at least one" % [@target, @regexp]
end

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'lib/appydays/spec_helpers.rb', line 28

def matches?(target)
  @target = target
  @target = @target.lines if @target.is_a?(String)
  return @target.find do |obj|
    obj.to_s.match(@regexp)
  end
end