public void testRubyExceptionWithoutCause() throws Exception { try { RubyRuntimeAdapter evaler = JavaEmbedUtils.newRuntimeAdapter(); evaler.eval(runtime, "no_method_with_this_name"); fail("Expected ScriptException"); } catch (RaiseException re) { assertEquals( "(NameError) undefined local variable or method `no_method_with_this_name' for main:Object", re.getMessage()); } }
@Initialize public void initialize() { _ruby = JavaEmbedUtils.initialize(Collections.EMPTY_LIST); _runtimeAdapter = JavaEmbedUtils.newRuntimeAdapter(); // load the class def _runtimeAdapter.eval(_ruby, _code); _transformerObject = _runtimeAdapter.eval(_ruby, "Transformer.new()"); logger.info("Evaluated Ruby code to: {}", _transformerObject); JavaEmbedUtils.invokeMethod( _ruby, _transformerObject, "init", new Object[0], IRubyObject.class); }
public RubyObject eval(String code) { Object obj = evaler.eval(runtime, code); if (obj == null) return null; if (obj instanceof RubyObject) { return (RubyObject) obj; } // hopefully this should never happen because everything in Ruby is an object... // but I may be missing something here... System.err.println("Object created by eval is not a RubyObject: " + obj.getClass()); return null; }