Class: Capybara::Query Deprecated

Inherits:
Capybara::Queries::BaseQuery show all
Defined in:
lib/capybara/query.rb

Overview

Deprecated.

This class and its methods are not supposed to be used by users of Capybara's public API. It may be removed in future versions of Capybara.

Constant Summary

VALID_KEYS =
[:text, :visible, :between, :count, :maximum, :minimum, :exact, :match, :wait]
VALID_MATCH =
[:first, :smart, :prefer_exact, :one]

Constants inherited from Capybara::Queries::BaseQuery

Capybara::Queries::BaseQuery::COUNT_KEYS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Capybara::Queries::BaseQuery

#wait

Constructor Details

#initialize(*args) ⇒ Query

Returns a new instance of Query



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/capybara/query.rb', line 10

def initialize(*args)
  @options = if args.last.is_a?(Hash) then args.pop.dup else {} end

  if args[0].is_a?(Symbol)
    @selector = Selector.all[args[0]]
    @locator = args[1]
  else
    @selector = Selector.all.values.find { |s| s.match?(args[0]) }
    @locator = args[0]
  end
  @selector ||= Selector.all[Capybara.default_selector]

  # for compatibility with Capybara 2.0
  if Capybara.exact_options and @selector == Selector.all[:option]
    @options[:exact] = true
  end

  @expression = @selector.call(@locator)
  assert_valid_keys
end

Instance Attribute Details

#expressionObject

Returns the value of attribute expression



5
6
7
# File 'lib/capybara/query.rb', line 5

def expression
  @expression
end

#findObject

Returns the value of attribute find



5
6
7
# File 'lib/capybara/query.rb', line 5

def find
  @find
end

#locatorObject

Returns the value of attribute locator



5
6
7
# File 'lib/capybara/query.rb', line 5

def locator
  @locator
end

#negativeObject

Returns the value of attribute negative



5
6
7
# File 'lib/capybara/query.rb', line 5

def negative
  @negative
end

#optionsObject

Returns the value of attribute options



5
6
7
# File 'lib/capybara/query.rb', line 5

def options
  @options
end

#selectorObject

Returns the value of attribute selector



5
6
7
# File 'lib/capybara/query.rb', line 5

def selector
  @selector
end

Instance Method Details

#cssObject



100
101
102
# File 'lib/capybara/query.rb', line 100

def css
  @expression
end

#descriptionObject



34
35
36
37
38
39
# File 'lib/capybara/query.rb', line 34

def description
  @description = "#{label} #{locator.inspect}"
  @description << " with text #{options[:text].inspect}" if options[:text]
  @description << selector.description(options)
  @description
end

#exact?Boolean

Returns:

  • (Boolean)


75
76
77
78
79
80
81
# File 'lib/capybara/query.rb', line 75

def exact?
  if options.has_key?(:exact)
    @options[:exact]
  else
    Capybara.exact
  end
end

#labelObject



32
# File 'lib/capybara/query.rb', line 32

def label; selector.label or selector.name; end

#matchObject



83
84
85
86
87
88
89
# File 'lib/capybara/query.rb', line 83

def match
  if options.has_key?(:match)
    @options[:match]
  else
    Capybara.match
  end
end

#matches_filters?(node) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/capybara/query.rb', line 41

def matches_filters?(node)
  if options[:text]
    regexp = options[:text].is_a?(Regexp) ? options[:text] : Regexp.escape(options[:text].to_s)
    return false if not node.text(visible).match(regexp)
  end
  case visible
    when :visible then return false unless node.visible?
    when :hidden then return false if node.visible?
  end
  selector.custom_filters.each do |name, filter|
    if options.has_key?(name)
      return false unless filter.matches?(node, options[name])
    elsif filter.default?
      return false unless filter.matches?(node, filter.default)
    end
  end
end

#nameObject



31
# File 'lib/capybara/query.rb', line 31

def name; selector.name; end

#resolve_for(node, exact = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/capybara/query.rb', line 105

def resolve_for(node, exact = nil)
  node.synchronize do
    children = if selector.format == :css
      node.find_css(self.css)
    else
      node.find_xpath(self.xpath(exact))
    end.map do |child|
      if node.is_a?(Capybara::Node::Base)
        Capybara::Node::Element.new(node.session, child, node, self)
      else
        Capybara::Node::Simple.new(child)
      end
    end
    Capybara::Result.new(children, self)
  end
end

#visibleObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/capybara/query.rb', line 59

def visible
  if options.has_key?(:visible)
    case @options[:visible]
      when true then :visible
      when false then :all
      else @options[:visible]
    end
  else
    if Capybara.ignore_hidden_elements
      :visible
    else
      :all
    end
  end
end

#xpath(exact = nil) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/capybara/query.rb', line 91

def xpath(exact=nil)
  exact = self.exact? if exact == nil
  if @expression.respond_to?(:to_xpath) and exact
    @expression.to_xpath(:exact)
  else
    @expression.to_s
  end
end