Class: Test::Unit::Assertions::AssertXPathArguments

Inherits:
Object
  • Object
show all
Defined in:
lib/assert2/xpath.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @subs = {}
  @xpath = ''
  to_xpath(path, id, options)
end

Instance Attribute Details

#subsObject (readonly)

Returns the value of attribute subs.



66
67
68
# File 'lib/assert2/xpath.rb', line 66

def subs
  @subs
end

#xpathObject (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, options)
  hash = { :id => hash } if hash.kind_of? Symbol
  hash.merge! options
  @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, options)
  @xpath = path
  @xpath = "descendant-or-self::#{ @xpath }" if @xpath.kind_of? Symbol
  to_predicate(id, options) if id
end