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

#descriptionObject

Returns

String

The default description for the spec when it is not provided.


10
11
12
13
14
15
16
# File 'lib/webrat/core/matchers/have_selector.rb', line 10

def description
  "have selector #{@expected.inspect}" + if @options && @options.any?
    " with #{@options.inspect}"
  else
    ''
  end
end

#failure_messageObject

Returns

String

The failure message.


20
21
22
# File 'lib/webrat/core/matchers/have_selector.rb', line 20

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.


26
27
28
# File 'lib/webrat/core/matchers/have_selector.rb', line 26

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

#queryObject


49
50
51
52
53
# File 'lib/webrat/core/matchers/have_selector.rb', line 49

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

#tag_inspectObject


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/webrat/core/matchers/have_selector.rb', line 30

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