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



39
40
41
42
43
44
45
46
# File 'lib/webrat/selenium/matchers/have_content.rb', line 39

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

#does_not_match?(response) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
# File 'lib/webrat/selenium/matchers/have_content.rb', line 18

def does_not_match?(response)
  response.session.wait_for do
    !response.selenium.is_text_present(text_finder)
  end
rescue Webrat::TimeoutError => e
  @error_message = e.message
  false
end

#failure_messageObject

Returns

String

The failure message.



29
30
31
# File 'lib/webrat/selenium/matchers/have_content.rb', line 29

def failure_message
  "expected the response to #{content_message}:\n#{@error_message}"
end

#matches?(response) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(response)
  response.session.wait_for do
    response.selenium.is_text_present(text_finder)
  end
rescue Webrat::TimeoutError => e
  @error_message = e.message
  false
end

#negative_failure_messageObject

Returns

String

The failure message to be displayed in negative matches.



35
36
37
# File 'lib/webrat/selenium/matchers/have_content.rb', line 35

def negative_failure_message
  "expected the response to not #{content_message}"
end

#text_finderObject



48
49
50
51
52
53
54
# File 'lib/webrat/selenium/matchers/have_content.rb', line 48

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