Class: Webrat::Matchers::HaveSelector

Inherits:
HaveXpath show all
Defined in:
lib/webrat/core/matchers/have_selector.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from HaveXpath

#add_attributes_conditions_to, #add_content_condition_to, #add_options_conditions_to, #initialize, #matches, #matches?, #nokogiri_matches

Constructor Details

This class inherits a constructor from Webrat::Matchers::HaveXpath

Instance Method Details

#failure_messageObject

Returns

String

The failure message.



9
10
11
# File 'lib/webrat/core/matchers/have_selector.rb', line 9

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.



15
16
17
# File 'lib/webrat/core/matchers/have_selector.rb', line 15

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

#queryObject



38
39
40
41
42
# File 'lib/webrat/core/matchers/have_selector.rb', line 38

def query
  Nokogiri::CSS.parse(@expected.to_s).map do |ast|
    ast.to_xpath
  end.first
end

#tag_inspectObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/webrat/core/matchers/have_selector.rb', line 19

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

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

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

  html
end