Class: Webrat::Selenium::Matchers::HasContent

Inherits:
Object
  • Object
show all
Defined in:
lib/webrat/selenium/matchers/have_content.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ HasContent

Returns a new instance of HasContent.



5
6
7
# File 'lib/webrat/selenium/matchers/have_content.rb', line 5

def initialize(content)
  @content = content
end

Instance Method Details

#content_messageObject



35
36
37
38
39
40
41
42
# File 'lib/webrat/selenium/matchers/have_content.rb', line 35

def content_message
  case @content
  when String
    "include \"#{@content}\""
  when Regexp
    "match #{@content.inspect}"
  end
end

#failure_messageObject

Returns

String

The failure message.



25
26
27
# File 'lib/webrat/selenium/matchers/have_content.rb', line 25

def failure_message
  "expected the following element's content to #{content_message}:\n#{@element}"
end

#matches?(response) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/webrat/selenium/matchers/have_content.rb', line 9

def matches?(response)
  if @content.is_a?(Regexp)
    text_finder = "regexp:#{@content.source}"
  else
    text_finder = @content
  end

  response.session.wait_for do
    response.selenium.is_text_present(text_finder)
  end
  rescue Webrat::TimeoutError
    false
end

#negative_failure_messageObject

Returns

String

The failure message to be displayed in negative matches.



31
32
33
# File 'lib/webrat/selenium/matchers/have_content.rb', line 31

def negative_failure_message
  "expected the following element's content to not #{content_message}:\n#{@element}"
end