Browse files

Merge branch 'master' of github.com:tenderlove/taka

* 'master' of github.com:tenderlove/taka:
  adding some necessary JS properties to DOM::Document and DOM::Node
  fixing the load-path for jquery test js files
  yo dawg, I hear you like console.log when you shave yaks
  refactored jquery tests into separate file, and made it a little nicer to use a dev version of johnson.
  • Loading branch information...
2 parents 2331c87 + d27b6d3 commit aa2ff90fa14dbe851eb32f9082fa6f36199fc680 @tenderlove committed Jan 4, 2010
Showing with 77 additions and 31 deletions.
  1. +7 −30 Rakefile
  2. +2 −1 lib/taka/dom/document.rb
  3. +6 −0 lib/taka/dom/node.rb
  4. +31 −0 test/helper.rb
  5. +31 −0 test/jquery/test_jquery.rb
View
37 Rakefile
@@ -1,7 +1,6 @@
# -*- ruby -*-
require 'rubygems'
-require 'johnson'
require 'rake'
require 'hoe'
@@ -24,38 +23,16 @@ file 'vendor/jquery/jquery/dist/jquery.js' do
end
end
-class FakeWindow
-end
-
-class FakeNavigator
- def userAgent
- "hello world"
- end
-
- def js_property? name
- [:userAgent].include? name
- end
-end
-
namespace :test do
+ desc "run jquery tests"
task :jquery => 'vendor/jquery/jquery/dist/jquery.js' do
- Dir.chdir 'vendor/jquery/jquery' do
- doc = Taka::DOM::HTML(File.read('test/index.html'))
- scripts = doc.getElementsByTagName 'script'
- rt = Johnson::Runtime.new
-
- rt['window'] = FakeWindow.new
- rt['navigator'] = FakeNavigator.new
- rt['document'] = doc
+ require 'test/jquery/test_jquery'
+ end
- scripts.each do |tag|
- if tag['src']
- filename = File.expand_path(tag['src'].sub('..', '.'))
- rt.evaluate File.read(filename), filename, 1
- else
- rt.evaluate tag.content
- end
- end
+ desc "run dom tests"
+ task :dom do
+ Dir.glob('test/dom/**/*.rb').each do |file|
+ require file
end
end
end
View
3 lib/taka/dom/document.rb
@@ -157,7 +157,8 @@ def decorate node
end
def js_property? name
- [:body].include?(name)
+ return true if [:body, :documentElement].include?(name)
+ false
end
end
end
View
6 lib/taka/dom/node.rb
@@ -333,6 +333,12 @@ def can_append? new_child
true
end
+
+ def js_property? name
+ return true if [:firstChild].include?(name)
+ false
+ end
+
end
end
end
View
31 test/helper.rb
@@ -6,10 +6,12 @@
end
$LOAD_PATH << ENV['NOKOGIRI_DEV'] if ENV['NOKOGIRI_DEV']
+$LOAD_PATH << ENV['JOHNSON_DEV'] if ENV['JOHNSON_DEV']
require 'rubygems'
require 'nokogiri'
require 'taka'
+require 'johnson'
module DOM
class TestCase < Test::Unit::TestCase
@@ -90,3 +92,32 @@ def DOMTestCase(test_case_name, &block)
test_klass = Class.new(DOM::TestCase, &block)
Object.const_set(klass.to_sym, test_klass)
end
+
+module JQuery
+ class FakeWindow
+ end
+
+ class FakeNavigator
+ def userAgent
+ "hello world"
+ end
+
+ def js_property? name
+ [:userAgent].include? name
+ end
+ end
+
+ class TestCase < Test::Unit::TestCase
+ undef :default_test
+ end
+
+ class PoorMansFirebug
+ def log *args
+ puts args.inspect
+ end
+ alias_method :debug, :log
+ alias_method :info, :log
+ alias_method :warn, :log
+ alias_method :error, :log
+ end
+end
View
31 test/jquery/test_jquery.rb
@@ -0,0 +1,31 @@
+
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))
+
+module JQuery
+ class TestJQuery < TestCase
+
+ def test_jquery
+ Dir.chdir 'vendor/jquery' do
+ doc = Taka::DOM::HTML(File.read('jquery/test/index.html'))
+ scripts = doc.getElementsByTagName 'script'
+ rt = Johnson::Runtime.new
+
+ rt['window'] = FakeWindow.new
+ rt['navigator'] = FakeNavigator.new
+ rt['console'] = PoorMansFirebug.new
+ rt['document'] = doc
+
+ scripts.each do |tag|
+ if tag['src']
+ filename = File.expand_path(tag['src'].sub('../dist', 'jquery/dist'))
+ puts "(running #{tag['src']} ...)" ; STDOUT.flush
+ rt.evaluate File.read(filename), filename, 1
+ else
+ rt.evaluate tag.content
+ end
+ end
+ end
+ end
+
+ end
+end

0 comments on commit aa2ff90

Please sign in to comment.