Class: Capybara::Query
- Inherits:
-
Object
- Object
- Capybara::Query
- Defined in:
- lib/capybara/query.rb
Constant Summary collapse
- VALID_KEYS =
[:text, :visible, :between, :count, :maximum, :minimum]
Instance Attribute Summary collapse
-
#find ⇒ Object
Returns the value of attribute find.
-
#locator ⇒ Object
Returns the value of attribute locator.
-
#negative ⇒ Object
Returns the value of attribute negative.
-
#options ⇒ Object
Returns the value of attribute options.
-
#selector ⇒ Object
Returns the value of attribute selector.
-
#xpath ⇒ Object
Returns the value of attribute xpath.
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(*args) ⇒ Query
constructor
A new instance of Query.
- #label ⇒ Object
- #matches_count?(count) ⇒ Boolean
- #matches_filters?(node) ⇒ Boolean
- #name ⇒ Object
Constructor Details
#initialize(*args) ⇒ Query
Returns a new instance of Query.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/capybara/query.rb', line 7 def initialize(*args) @options = if args.last.is_a?(Hash) then args.pop.dup else {} end unless .has_key?(:visible) @options[:visible] = Capybara.ignore_hidden_elements 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] @xpath = @selector.call(@locator).to_s assert_valid_keys! end |
Instance Attribute Details
#find ⇒ Object
Returns the value of attribute find.
3 4 5 |
# File 'lib/capybara/query.rb', line 3 def find @find end |
#locator ⇒ Object
Returns the value of attribute locator.
3 4 5 |
# File 'lib/capybara/query.rb', line 3 def locator @locator end |
#negative ⇒ Object
Returns the value of attribute negative.
3 4 5 |
# File 'lib/capybara/query.rb', line 3 def negative @negative end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/capybara/query.rb', line 3 def @options end |
#selector ⇒ Object
Returns the value of attribute selector.
3 4 5 |
# File 'lib/capybara/query.rb', line 3 def selector @selector end |
#xpath ⇒ Object
Returns the value of attribute xpath.
3 4 5 |
# File 'lib/capybara/query.rb', line 3 def xpath @xpath end |
Instance Method Details
#description ⇒ Object
31 32 33 34 35 |
# File 'lib/capybara/query.rb', line 31 def description @description = "#{label} #{locator.inspect}" @description << " with text #{[:text].inspect}" if [:text] @description end |
#label ⇒ Object
29 |
# File 'lib/capybara/query.rb', line 29 def label; selector.label or selector.name; end |
#matches_count?(count) ⇒ Boolean
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/capybara/query.rb', line 51 def matches_count?(count) case when [:between] [:between] === count when [:count] [:count].to_i == count when [:maximum] [:maximum].to_i >= count when [:minimum] [:minimum].to_i <= count else count > 0 end end |
#matches_filters?(node) ⇒ Boolean
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/capybara/query.rb', line 37 def matches_filters?(node) node.unsynchronized do if [:text] regexp = [:text].is_a?(Regexp) ? [:text] : Regexp.escape([:text]) return false if not node.text.match(regexp) end return false if [:visible] and not node.visible? selector.custom_filters.each do |name, block| return false if .has_key?(name) and not block.call(node, [name]) end true end end |
#name ⇒ Object
28 |
# File 'lib/capybara/query.rb', line 28 def name; selector.name; end |