Package org.jruby

Examples of org.jruby.RubyRuntimeAdapter.eval()


        config.processArguments(new String[]{"--debug"});
        Ruby rt = JavaEmbedUtils.initialize(Collections.emptyList(), config);
        NativeTracer tracer = new NativeTracer();
        rt.addEventHook(tracer);
        RubyRuntimeAdapter evaler = JavaEmbedUtils.newRuntimeAdapter();
        evaler.eval(rt, "sleep 0.01\nsleep 0.01\nsleep 0.01");
        assertEquals("expected tracing", Arrays.asList(1,1,1,2,2,2,3,3,3), tracer.lines);
    }

    private final static class NativeTracer extends EventHook {
       
View Full Code Here


    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());
        }
    }
View Full Code Here

  public TextReport<?> buildReport(Resource resource) throws Exception {
    Ruby runtime = JavaEmbedUtils.initialize(new ArrayList());
    RubyRuntimeAdapter evaler = JavaEmbedUtils.newRuntimeAdapter();

    String script = getContent(resource);
    IRubyObject eval = evaler.eval(runtime, script);

    TextReport textReport = (TextReport) JavaEmbedUtils.rubyToJava(runtime, eval, TextReport.class);

    if (textReport instanceof RbReport) {
      ((RbReport) textReport).setRuntime(runtime);
View Full Code Here

        runtime = JavaEmbedUtils.initialize(new LinkedList());
    }

    protected IRubyObject getConnectionUri(String uri) {
        final RubyRuntimeAdapter evaler = JavaEmbedUtils.newRuntimeAdapter();
        final IRubyObject result = evaler.eval(runtime, "require 'rubygems'\nrequire 'data_objects'\nDataObjects::URI.parse('" + uri + "')");
        assertEquals("DataObjects::URI", result.getType().getName());

        return result;
    }
View Full Code Here

    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());
        }
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.