Skip to content
Browse files

Writing combinator specs

  E F, E > F, E + F, E ~ F
  • Loading branch information...
1 parent d27e66f commit 6554322ab536a291f8503136593ac7ca5ca3a180 Carl Lerche committed Oct 21, 2008
View
25 spec/combinator_adjacent_to_spec.rb
@@ -0,0 +1,25 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe "The adjacent to combinator" do
+
+ it "<div + p> should return the p tag" do
+ HTML.should have_nodes("div + p", 1)
+ end
+
+ it "<span + span> should return the last 3 span tags" do
+ HTML.should have_nodes("span[foo] + span", 3)
+ end
+
+ it "<span[foo] + span> should return the last 3 span tags" do
+ HTML.should have_nodes("span[foo] + span", 2)
+ end
+
+ it "<body + div> should not return anything" do
+ HTML.should have_nodes("body + div", 0)
+ end
+
+ it "<p + body> should not return anything" do
+ HTML.should have_nodes("p + body", 0)
+ end
+
+end
View
33 spec/combinator_child_of_spec.rb
@@ -0,0 +1,33 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe "The child of combinator" do
+
+ it "<body > *> should return all the child nodes of the body" do
+ HTML.should have_nodes("body > *", 5)
+ end
+
+ it "<div > *> should return all the child nodes of the div" do
+ HTML.should have_nodes("div > *", 5)
+ end
+
+ it "<body > p> should return the p" do
+ HTML.should have_nodes("body > p", 3)
+ end
+
+ it "<body > span> should return nothing" do
+ HTML.should have_nodes("body > span", 0)
+ end
+
+ it "<div > body> should return nothing" do
+ HTML.should have_nodes("div > body", 0)
+ end
+
+ it "<body > div > span> should return the spans" do
+ HTML.should have_nodes("body > div > span", 4)
+ end
+
+ it "<html > div > span> should return nothing" do
+ HTML.should have_nodes("html > div > span", 0)
+ end
+
+end
View
25 spec/combinator_descendant_of_spec.rb
@@ -0,0 +1,25 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe "The descendant of combinator" do
+
+ it "<body *> should return all the child nodes of the body" do
+ HTML.should have_nodes("body *", 10)
+ end
+
+ it "<div *> should return all the child nodes of the div" do
+ HTML.should have_nodes("div *", 5)
+ end
+
+ it "<body p> should return the p" do
+ HTML.should have_nodes("body p", 3)
+ end
+
+ it "<div body> should return nothing" do
+ HTML.should have_nodes("div body", 0)
+ end
+
+ it "<html div span> should return the spans" do
+ HTML.should have_nodes("html div span", 4)
+ end
+
+end
View
9 spec/combinator_sibling_of_spec.rb
@@ -0,0 +1,9 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe "The simbling of combinator" do
+
+ it "should be awesome" do
+
+ end
+
+end
View
2 spec/spec_helper.rb
@@ -1,4 +1,6 @@
+require "rubygems"
require "libxml"
+require 'spec'
require File.join(File.dirname(__FILE__), "..", "css")
HTML = <<HERE

0 comments on commit 6554322

Please sign in to comment.
Something went wrong with that request. Please try again.