lib/rspec_html/search.rb in rspec-html-0.3.4 vs lib/rspec_html/search.rb in rspec-html-0.3.5
- old
+ new
@@ -81,18 +81,24 @@
"#{text[0..max]}...#{text[-max..-1]}"
end
def attributes
- @element&.attributes&.to_h { |key, val| [key.to_sym, val.to_s] } || {}
+ @element&.attributes.to_h { |key, val| [key.to_sym, val.to_s] }
end
def size
return @element.size if @element.respond_to?(:size)
@siblings&.size || 0
end
alias length size
+
+ def children(text: false) # rubocop:disable Metrics/CyclomaticComplexity
+ @element&.children
+ &.map { |child| Element.new(child, child.name, siblings: @element.children) }
+ &.reject { |child| text ? false : child.name == 'text' } || []
+ end
def new_from_find(tag, options)
Element.new(
find(tag),
tag,