Class: Capybara::Query
- Inherits:
-
Object
- Object
- Capybara::Query
- Defined in:
- lib/capybara/query.rb
Instance Attribute Summary collapse
-
#locator ⇒ Object
Returns the value of attribute locator.
-
#options ⇒ Object
Returns the value of attribute options.
-
#selector ⇒ Object
Returns the value of attribute selector.
-
#xpaths ⇒ Object
Returns the value of attribute xpaths.
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message(type, node) ⇒ Object
-
#initialize(*args) ⇒ Query
constructor
A new instance of Query.
- #matches_filters?(node) ⇒ Boolean
- #name ⇒ Object
- #negative_failure_message(type, node) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Query
Returns a new instance of Query.
5 6 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 5 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[1] @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) if xpath.respond_to?(:to_xpaths) @xpaths = xpath.to_xpaths else @xpaths = [xpath.to_s].flatten end end |
Instance Attribute Details
#locator ⇒ Object
Returns the value of attribute locator.
3 4 5 |
# File 'lib/capybara/query.rb', line 3 def locator @locator 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 |
#xpaths ⇒ Object
Returns the value of attribute xpaths.
3 4 5 |
# File 'lib/capybara/query.rb', line 3 def xpaths @xpaths end |
Instance Method Details
#description ⇒ Object
45 46 47 48 49 |
# File 'lib/capybara/query.rb', line 45 def description @description = "#{name} #{locator.inspect}" @description << " with text #{[:text].inspect}" if [:text] @description end |
#failure_message(type, node) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/capybara/query.rb', line 28 def (type, node) = selector..call(node, self) if selector. ||= [:message] if type == :assert ||= "expected #{description} to return something" else ||= "Unable to find #{description}" end end |
#matches_filters?(node) ⇒ Boolean
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/capybara/query.rb', line 51 def matches_filters?(node) 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 |
#name ⇒ Object
43 |
# File 'lib/capybara/query.rb', line 43 def name; selector.name; end |
#negative_failure_message(type, node) ⇒ Object
39 40 41 |
# File 'lib/capybara/query.rb', line 39 def (type, node) "expected #{description} not to return anything" end |