Skip to content

Instantly share code, notes, and snippets.

@deepfryed
Created March 12, 2011 01:50
Show Gist options
  • Save deepfryed/866940 to your computer and use it in GitHub Desktop.
Save deepfryed/866940 to your computer and use it in GitHub Desktop.
should nokogiri css multiple selector work like xpath alternation ?
#!/usr/bin/ruby
require 'nokogiri'
require 'minitest/spec'
describe 'nokogiri css selectors' do
before do
@doc = Nokogiri::HTML %Q{
<html>
<body>
<div>
<span> span 1 </span>
<abbr> abbr 1 </abbr>
<span> span 2 </span>
<abbr> abbr 2 </abbr>
</div>
</body>
</html>
}
end
it 'should emulate xpath alternation' do
xpath = @doc.xpath('.//div/span | .//div/abbr').map(&:text)
css = @doc.css('div > span, div > abbr').map(&:text)
assert_equal xpath, css
end
end
MiniTest::Unit.autorun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment