Skip to content

Commit cccc731

Browse files
committed
JRubyTest: fix JRuby unit tests
They need to use global variables (prepended with $) where appropriate. Clearing the bindings is also very tricky with the JRuby script engine, so let's remove that test for the time being. (I explored setting the "org.jruby.embed.clear.variables" attribute to true and/or "org.jruby.embed.localvariable.behavior" system property to "transient", but then the variables are cleared immediately following evaluation of the script, making them unretrievable from the bindings afterwards.)
1 parent 96812fe commit cccc731

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/test/java/org/scijava/plugins/scripting/jruby/JRubyTest.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
import java.io.IOException;
3737
import java.util.concurrent.ExecutionException;
3838

39-
import javax.script.Bindings;
40-
import javax.script.ScriptContext;
4139
import javax.script.ScriptEngine;
4240
import javax.script.ScriptException;
4341

@@ -76,16 +74,11 @@ public void testLocals() throws ScriptException {
7674
final String engineClassName = engine.getClass().getName();
7775
assertEquals("org.jruby.embed.jsr223.JRubyEngine", engineClassName);
7876
engine.put("hello", 17);
79-
assertEquals("17", engine.eval("hello").toString());
80-
assertEquals("17", engine.get("hello").toString());
81-
82-
final Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
83-
bindings.clear();
84-
assertEquals("", engine.get("hello").toString());
77+
assertEquals(17L, engine.eval("$hello"));
78+
assertEquals(17, engine.get("hello"));
8579
}
8680

87-
// FIXME: This test currently fails due to input injection failure.
88-
// @Test
81+
@Test
8982
public void testParameters() throws InterruptedException, ExecutionException,
9083
IOException, ScriptException
9184
{
@@ -95,12 +88,12 @@ public void testParameters() throws InterruptedException, ExecutionException,
9588
final String script = "" + //
9689
"# @ScriptService ss\n" + //
9790
"# @OUTPUT String language\n" + //
98-
"language = ss.getLanguageByName(\"Ruby\").getLanguageName\n";
91+
"$language = $ss.getLanguageByName(\"ruby\").getLanguageName\n";
9992
final ScriptModule m = scriptService.run("hello.rb", script, true).get();
10093

10194
final Object actual = m.getOutput("language");
10295
final String expected =
103-
scriptService.getLanguageByName("Ruby").getLanguageName();
96+
scriptService.getLanguageByName("ruby").getLanguageName();
10497
assertEquals(expected, actual);
10598

10699
final Object result = m.getReturnValue();

0 commit comments

Comments
 (0)