Class: ContainsText

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

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ ContainsText

this is what the matcher is called on. In this case:

foo.should contains(:bars)

foo would be passed to the initialize



7
8
9
# File 'lib/rwebunit/matchers/contains_text.rb', line 7

def initialize(expected)
  @expected = expected
end

Instance Method Details

#actual_textObject



16
17
18
# File 'lib/rwebunit/matchers/contains_text.rb', line 16

def actual_text
  @actual.to_s.length > 1000000 ? @actual[0, 1000] : @actual
end

#failure_messageObject

error message for should



21
22
23
# File 'lib/rwebunit/matchers/contains_text.rb', line 21

def failure_message
  "expected #{actual_text} not to contains #{@expected}, but it did't"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/rwebunit/matchers/contains_text.rb', line 11

def matches?(actual)
  @actual = actual
  return actual && actual.include?(@expected)
end

#negative_failure_messageObject

error message for should_not



26
27
28
# File 'lib/rwebunit/matchers/contains_text.rb', line 26

def negative_failure_message
  "expected #{actual_text} not to contains #{@expected}, but it did"
end