Created
May 13, 2013 14:42
-
-
Save renato-zannon/5568800 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
require 'rspec' | |
describe "nth-child" do | |
let(:doc) do | |
Nokogiri::HTML(<<-HTML) | |
<html> | |
<body> | |
<p id="first"></p> | |
<p id="second"></p> | |
</body> | |
</html> | |
HTML | |
end | |
let(:first) { doc.at_css("#first") } | |
let(:second) { doc.at_css("#second") } | |
it "returns both nodes with '1n'" do | |
nodes = doc.css("p:nth-child(1n)") | |
expect(nodes).to include(first) | |
expect(nodes).to include(second) | |
end | |
it "returns only the second node with '2n'" do | |
nodes = doc.css("p:nth-child(2n)") | |
expect(nodes).to include(second) | |
end | |
it "returns only the first node with '2n + 1'" do | |
nodes = doc.css("p:nth-child(2n + 1)") | |
expect(nodes).to include(first) | |
end | |
it "returns only the first node with '1'" do | |
nodes = doc.css("p:nth-child(1)") | |
expect(nodes).to include(first) | |
end | |
it "returns only the second node with '2'" do | |
nodes = doc.css("p:nth-child(2)") | |
expect(nodes).to include(second) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment