KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jruby > test > TestVariableCreation


1 package org.jruby.test;
2
3 import junit.framework.TestCase;
4
5 import org.jruby.Ruby;
6 import org.jruby.exceptions.RaiseException;
7
8 public class TestVariableCreation extends TestCase {
9     private static Ruby r;
10     private static RaiseException failed;
11     public void testLocalVars() {
12         r = Ruby.getDefaultInstance();
13         // define new method
14
r.evalScript("a = 1\n");
15         r.evalScript("a.to_s");
16         
17         // will run on non main thread
18
Runnable JavaDoc run = new Runnable JavaDoc(){
19             public void run(){
20                 try {
21                     r.evalScript("a.to_s");
22                 } catch(RaiseException ex){
23                     failed = ex;
24                 }
25             }
26         };
27         Thread JavaDoc n = new Thread JavaDoc(run);
28         
29         n.start();
30         try {
31             n.join();
32             assertNotNull(failed);
33             assertEquals("NameError", failed.getException().getMetaClass().getName());
34         } catch (InterruptedException JavaDoc e) {
35             fail();
36         }
37         
38         
39         
40
41     }
42
43 }
44
Popular Tags