Permalink
Browse files

Nokogiri :text and :password extensions (beginning of full jQuery sel…

…ector support)
  • Loading branch information...
1 parent f6c6d95 commit 31d5595a57e0943734282bc41f150a808ebc4702 @wycats wycats committed Nov 6, 2008
@@ -5,6 +5,7 @@ def initialize(expected, &block)
# Require nokogiri and fall back on rexml
begin
require "nokogiri"
+ require "merb-core/test/test_ext/nokogiri"
rescue LoadError => e
if require "rexml/document"
require "merb-core/vendor/nokogiri/css"
@@ -107,7 +108,7 @@ def failure_message
# ==== Returns
# String:: The failure message to be displayed in negative matches.
def negative_failure_message
- "expected following text to not match selector #{@expected}:\n#{@document}"
+ "expected following text to not match selector #{@expected} (#{@query}):\n#{@document}"
end
def query
@@ -0,0 +1,15 @@
+module Nokogiri
+ module CSS
+ class XPathVisitor
+
+ def visit_pseudo_class_text(node)
+ "@type='text'"
+ end
+
+ def visit_pseudo_class_password(node)
+ "@type='password'"
+ end
+
+ end
+ end
+end
@@ -0,0 +1,72 @@
+require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
+require "merb-core/test"
+
+Merb.start :environment => 'test', :log_level => :fatal
+
+describe "Nokogiri Extension" do
+ before(:each) do
+ @text_and_password = <<-HTML
+ <div>
+ <input type="text"/>
+ <input type="password"/>
+ <span type="text"/>
+ </div>
+ HTML
+
+ @text_only = <<-HTML
+ <div>
+ <input type="text" disabled="disabled" />
+ </div>
+ HTML
+
+ @password_only = <<-HTML
+ <div>
+ <input type="password"/>
+ <div>
+ HTML
+ end
+
+ describe ":text" do
+ it "passes have_selector(:text) if a node with type=text exists" do
+ @text_and_password.should have_selector(":text")
+ end
+
+ it "passes not have_selector(:text) if no node with text=text exists" do
+ @password_only.should_not have_selector(":text")
+ end
+
+ it "fails have_selector(:text) if no node with type=text exists" do
+ lambda { @password_only.should have_selector(":text") }.should fail
+ end
+
+ it "fails not have_selector(:text) if a node with type=text exists" do
+ lambda { @text_only.should_not have_selector(":text") }.should fail
+ end
+
+ it "works together with other selectors" do
+ @text_and_password.should have_selector("input:text[type*='te']")
+ end
+ end
+
+ describe ":password" do
+ it "passes have_selector(:password) if a node with type=password exists" do
+ @text_and_password.should have_selector(":password")
+ end
+
+ it "passes not have_selector(:text) if no node with text=text exists" do
+ @text_only.should_not have_selector(":password")
+ end
+
+ it "fails have_selector(:password) if no node with type=password exists" do
+ lambda { @text_only.should have_selector(":password") }.should fail
+ end
+
+ it "fails not have_selector(:password) if a node with type=password exists" do
+ lambda { @password_only.should_not have_selector(":password") }.should fail
+ end
+
+ it "works together with other selectors" do
+ @text_and_password.should have_selector("input:password[type*='pa']")
+ end
+ end
+end

0 comments on commit 31d5595

Please sign in to comment.