Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

RedBridge for Nokogiri

View gist:1095486
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
package canna;
 
/**
* modified after yokolet - http://gist.github.com/424212
*/
 
import java.util.Arrays;
import java.util.List;
 
import org.jruby.embed.LocalContextScope;
import org.jruby.embed.ScriptingContainer;
 
public class JavaToRubyTestRunner {
private String jrubyhome = "/Users/sglee77/work/git/jruby";
private String basePath = "/Users/sglee77/work/git/nokogiri";
private String minitestPath = jrubyhome + "/lib/ruby/gems/1.8/gems/minitest-2.3.1/lib/";
private JavaToRubyTestRunner() {
ScriptingContainer container = new ScriptingContainer(LocalContextScope.SINGLETHREAD);
container.setHomeDirectory(jrubyhome);
String[] paths = {basePath + "/test", basePath + "/lib", minitestPath};
List<String> loadPaths = Arrays.asList(paths);
container.setLoadPaths(loadPaths);
container.runScriptlet("require 'rubygems'");
container.runScriptlet("require 'helper'");
runTest(container, "xml", "test_dtd.rb");
runInspect(container);
container.terminate();
}
 
private void runTest(ScriptingContainer container, String dir, String test_name) {
try {
container.runScriptlet("ROOT_DIR = File.dirname(__FILE__)");
container.runScriptlet("MODULE_DIR = File.join('" + basePath + "', 'test', '" + dir + "')");
container.runScriptlet("load File.join(MODULE_DIR, '" + test_name + "')");
} catch (Exception e) {
e.printStackTrace();
}
}
private void runInspect(ScriptingContainer container) {
System.out.println("[inspect]");
String script =
"node = Nokogiri::XML::Text.new('hello world', Nokogiri::XML::Document.new)\n" +
"p \"#<#{node.class.name}:#{sprintf(\"0x%x\",node.object_id)} #{node.text.inspect}>\", node.inspect";
 
container.runScriptlet(script);
}
 
public static void main(String[] args) {
new JavaToRubyTestRunner();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.