Skip to content
Browse files

Johnson::Runtime.require works now

  • Loading branch information...
1 parent 8e1223c commit fc0354b99bc1c9d39393d5d0d995d1a2df4aaf17 @clbustos committed Sep 28, 2010
Showing with 19 additions and 13 deletions.
  1. +3 −5 lib/johnson/js/prelude.js
  2. +3 −0 test/fixtures/test.js
  3. +1 −0 test/helper.rb
  4. +1 −1 test/johnson/browser_test.rb
  5. +11 −7 test/johnson/prelude_test.rb
View
8 lib/johnson/js/prelude.js
@@ -123,12 +123,10 @@ Johnson.required = {};
Johnson.require = function(file) {
file = Ruby.File.join(Ruby.File.dirname(file),
Ruby.File.basename(file, ".js") + ".js");
-
if(Johnson.required[file]) return false;
-
- for(var directory in Ruby["$LOAD_PATH"]) {
- var path = Ruby.File.join(directory, file);
-
+ var load_path=Ruby["$LOAD_PATH"]
+ for(i=0; i<load_path.size();i++) {
+ var path = Ruby.File.join(load_path[i], file)
if(Ruby.File.send("file?", path)) {
Johnson.required[file] = true;
Johnson.runtime.load(path);
View
3 test/fixtures/test.js
@@ -0,0 +1,3 @@
+function js_test() {
+ return "test";
+}
View
1 test/helper.rb
@@ -1,3 +1,4 @@
+$:.unshift(File.dirname(__FILE__)+"/../lib")
require "rubygems"
require "test/unit"
View
2 test/johnson/browser_test.rb
@@ -38,6 +38,6 @@ def may_thread(&block)
end
end
end
-rescue LoadError
+rescue LoadError =>e
# Yehuda is teh lame.
end
View
18 test/johnson/prelude_test.rb
@@ -1,3 +1,4 @@
+$:.unshift(File.dirname(__FILE__)+"/../")
require "helper"
module Johnson
@@ -33,14 +34,17 @@ def test_all_of_ruby_is_available
assert_kind_of(Set, @runtime.evaluate("Ruby.Set.new()"))
end
- # def test_require_an_existing_js_file_without_extension
- # assert_js("Johnson.require('johnson/template')")
- # end
+ def test_require_an_existing_js_file_without_extension
+ file=File.dirname(__FILE__)+"/../fixtures/test"
+ assert_js("Johnson.require('#{file}')")
+ assert_equal("test",@runtime.evaluate("js_test()"))
+ end
- # def test_require_returns_false_the_second_time_around
- # assert_js("Johnson.require('johnson/template')")
- # assert(!@runtime.evaluate("Johnson.require('johnson/template')"))
- # end
+ def test_require_returns_false_the_second_time_around
+ file=File.dirname(__FILE__)+"/../fixtures/test"
+ assert_js("Johnson.require('#{file}')")
+ assert(!@runtime.evaluate("Johnson.require('#{file}')"))
+ end
def test_missing_requires_throw_LoadError
assert_js(<<-END)

0 comments on commit fc0354b

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