Class: Webrat::Selenium::Matchers::HaveTag

Inherits:
HaveSelector show all
Defined in:
lib/webrat/selenium/matchers/have_tag.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from HaveSelector

#does_not_match?, #initialize, #matches?

Constructor Details

This class inherits a constructor from Webrat::Selenium::Matchers::HaveSelector

Instance Method Details

#failure_messageObject

Returns

String

The failure message.


8
9
10
# File 'lib/webrat/selenium/matchers/have_tag.rb', line 8

def failure_message
  "expected following output to contain a #{tag_inspect} tag:\n#{@document}"
end

#negative_failure_messageObject

Returns

String

The failure message to be displayed in negative matches.


14
15
16
# File 'lib/webrat/selenium/matchers/have_tag.rb', line 14

def negative_failure_message
  "expected following output to omit a #{tag_inspect}:\n#{@document}"
end

#queryObject


36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/webrat/selenium/matchers/have_tag.rb', line 36

def query
  options  = @expected.last.dup
  selector = @expected.first.to_s

  selector << ":contains('#{options.delete(:content)}')" if options[:content]

  options.each do |key, value|
    selector << "[#{key}='#{value}']"
  end

  Nokogiri::CSS.parse(selector).map { |ast| ast.to_xpath }
end

#tag_inspectObject


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/webrat/selenium/matchers/have_tag.rb', line 18

def tag_inspect
  options = @expected.last.dup
  content = options.delete(:content)

  html = "<#{@expected.first}"
  options.each do |k,v|
    html << " #{k}='#{v}'"
  end

  if content
    html << ">#{content}</#{@expected.first}>"
  else
    html << "/>"
  end

  html
end