Class: Matchers::EndWith

Inherits:
BaseMatcher show all
Defined in:
lib/pidgin_spec/matchers/end_with.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ EndWith

Returns a new instance of EndWith.



3
4
5
# File 'lib/pidgin_spec/matchers/end_with.rb', line 3

def initialize(expected)
  @expected = expected.length == 1 ? expected.first : expected 
end

Instance Method Details

#failure_messageObject



26
27
28
# File 'lib/pidgin_spec/matchers/end_with.rb', line 26

def failure_message
  "You bin dey expect make #{@value} end with #{@expected}, but e no con end with am"
end

#failure_message_when_negatedObject



22
23
24
# File 'lib/pidgin_spec/matchers/end_with.rb', line 22

def failure_message_when_negated
  "You bin dey expect say #{@value} no go end with #{@expected}, but e con end with am"
end

#matches?(value) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pidgin_spec/matchers/end_with.rb', line 7

def matches?(value)
  @value = value
  if @expected.is_a?(String) || @expected.is_a?(Array)
    @value[-@expected.length, @expected.length] == @expected
  else
    @value.last == @expected
  end
  # if value.is_a?(String) && @expected.is_a?(String)
  #   @value[-@expected[0].length, @expected[0].length] == @expected[0]
  # elsif value.is_a? Array
  #   array_len = @expected.length
  #   @value.last(array_len) == @expected
  # end
end