lib/rubocop/cop/capybara/mixin/css_selector.rb in rubocop-capybara-2.19.0 vs lib/rubocop/cop/capybara/mixin/css_selector.rb in rubocop-capybara-2.20.0

- old
+ new

@@ -53,19 +53,13 @@ # @return [Array<String>] # @example # attributes('a[foo-bar_baz]') # => {"foo-bar_baz=>nil} # attributes('button[foo][bar=baz]') # => {"foo"=>nil, "bar"=>"'baz'"} # attributes('table[foo=bar]') # => {"foo"=>"'bar'"} + # attributes('[foo="bar[baz][qux]"]') # => {"foo"=>"'bar[baz][qux]'"} def attributes(selector) - # Extract the inner strings of attributes. - # For example, extract the following: - # 'button[foo][bar=baz]' => 'foo][bar=baz' - inside_attributes = selector.scan(/\[(.*)\]/).flatten.join - inside_attributes.split('][').to_h do |attr| - key, value = attr.split('=') - [key, normalize_value(value)] - end + CssAttributesParser.new(selector).parse end # @param selector [String] # @return [Array<String>] # @example @@ -86,25 +80,9 @@ # multiple_selectors?('a.cls b#id') # => true # multiple_selectors?('a.cls') # => false def multiple_selectors?(selector) normalize = selector.gsub(/(\\[>,+~]|\(.*\))/, '') normalize.match?(/[ >,+~]/) - end - - # @param value [String] - # @return [Boolean, String] - # @example - # normalize_value('true') # => true - # normalize_value('false') # => false - # normalize_value(nil) # => nil - # normalize_value("foo") # => "'foo'" - def normalize_value(value) - case value - when 'true' then true - when 'false' then false - when nil then nil - else "'#{value.gsub(/"|'/, '')}'" - end end end end end end