Navigation Menu

Skip to content

Commit

Permalink
Merge branch 'master' of github.com:tenderlove/taka
Browse files Browse the repository at this point in the history
* '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
tenderlove committed Jan 4, 2010
2 parents 2331c87 + d27b6d3 commit aa2ff90
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 31 deletions.
37 changes: 7 additions & 30 deletions Rakefile
@@ -1,7 +1,6 @@
# -*- ruby -*-

require 'rubygems'
require 'johnson'
require 'rake'
require 'hoe'

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/taka/dom/document.rb
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/taka/dom/node.rb
Expand Up @@ -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
31 changes: 31 additions & 0 deletions test/helper.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
31 changes: 31 additions & 0 deletions 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.