Class: Webrat::Selenium::Matchers::HaveSelector

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

Direct Known Subclasses

HaveTag

Instance Method Summary collapse

Constructor Details

#initialize(expected, options = {}, &block) ⇒ HaveSelector

Returns a new instance of HaveSelector.



5
6
7
8
9
10
# File 'lib/webrat/selenium/matchers/have_selector.rb', line 5

def initialize(expected, options = {}, &block)
  @expected = expected
  @options  = options
  @block    = block
  @content  = @options.delete(:content)||@options.delete(:text)
end

Instance Method Details

#failure_messageObject

Returns

String

The failure message.



37
38
39
# File 'lib/webrat/selenium/matchers/have_selector.rb', line 37

def failure_message
  "expected following text to match selector #{@expected}:\n#{@document}"
end

#matches?(response) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/webrat/selenium/matchers/have_selector.rb', line 12

def matches?(response)
  response.session.wait_for do
#            if @content
#              @element=response.selenium.get_text("css=#{@expected}")
#              case @content
#              when String
#                @element.include?(@content)
#              when Regexp
#                @element.match(@content)
#              end
#              
#            else
      response.selenium.is_element_present(selector)
#            end
  end
  rescue Webrat::TimeoutError
    false
end

#negative_failure_messageObject

Returns

String

The failure message to be displayed in negative matches.



43
44
45
# File 'lib/webrat/selenium/matchers/have_selector.rb', line 43

def negative_failure_message
  "expected following text to not match selector #{@expected}:\n#{@document}"
end

#selectorObject



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

def selector
  "css=#{@expected}" + ((@content && ":contains('#{@content}')") || '')
end