Class: Test::Unit::Assertions::AssertXPathArguments
- Inherits:
-
Object
- Object
- Test::Unit::Assertions::AssertXPathArguments
- Defined in:
- lib/assert2/xpath.rb
Instance Attribute Summary collapse
-
#subs ⇒ Object
readonly
Returns the value of attribute subs.
-
#xpath ⇒ Object
readonly
Returns the value of attribute xpath.
Instance Method Summary collapse
-
#initialize(path = '', id = nil, options = {}) ⇒ AssertXPathArguments
constructor
A new instance of AssertXPathArguments.
- #to_conditions(hash) ⇒ Object
- #to_predicate(hash, options) ⇒ Object
- #to_xpath(path, id, options) ⇒ Object
Constructor Details
#initialize(path = '', id = nil, options = {}) ⇒ AssertXPathArguments
Returns a new instance of AssertXPathArguments.
60 61 62 63 64 |
# File 'lib/assert2/xpath.rb', line 60 def initialize(path = '', id = nil, = {}) @subs = {} @xpath = '' to_xpath(path, id, ) end |
Instance Attribute Details
#subs ⇒ Object (readonly)
Returns the value of attribute subs.
66 67 68 |
# File 'lib/assert2/xpath.rb', line 66 def subs @subs end |
#xpath ⇒ Object (readonly)
Returns the value of attribute xpath.
67 68 69 |
# File 'lib/assert2/xpath.rb', line 67 def xpath @xpath end |
Instance Method Details
#to_conditions(hash) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/assert2/xpath.rb', line 69 def to_conditions(hash) xml_attribute_name = /^[a-z][_a-z0-9]+$/i # CONSIDER is that an XML attribute name match? @xpath << hash.map{|k, v| sk = k.to_s sk = '_text' if sk == '.' or k == 46 k = '.' if k == 46 and RUBY_VERSION < '1.9.0' @subs[sk] = v.to_s "#{ '@' if k.to_s =~ xml_attribute_name }#{k} = $#{sk}" }.join(' and ') end |
#to_predicate(hash, options) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/assert2/xpath.rb', line 81 def to_predicate(hash, ) hash = { :id => hash } if hash.kind_of? Symbol hash.merge! @xpath << '[ ' to_conditions(hash) @xpath << ' ]' end |
#to_xpath(path, id, options) ⇒ Object
89 90 91 92 93 |
# File 'lib/assert2/xpath.rb', line 89 def to_xpath(path, id, ) @xpath = path @xpath = "descendant-or-self::#{ @xpath }" if @xpath.kind_of? Symbol to_predicate(id, ) if id end |