Class: Crspec::Matchers::StartWithMatcher

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

Instance Attribute Summary

Attributes inherited from BaseMatcher

#actual, #expected

Instance Method Summary collapse

Methods inherited from BaseMatcher

#and, #failure_message_when_negated, #initialize, #or

Constructor Details

This class inherits a constructor from Crspec::Matchers::BaseMatcher

Instance Method Details

#failure_messageObject



563
564
565
# File 'lib/crspec/matchers.rb', line 563

def failure_message
  "Expected #{@actual.inspect} to start with #{@expected.inspect}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


552
553
554
555
556
557
558
559
560
561
# File 'lib/crspec/matchers.rb', line 552

def matches?(actual)
  @actual = actual
  if actual.respond_to?(:start_with?)
    actual.start_with?(@expected)
  elsif actual.is_a?(Array)
    actual.first(Array(@expected).size) == Array(@expected)
  else
    false
  end
end