22require "json"
33require 'multi_json'
44require "pathname"
5+ require "rbconfig"
56require "test/unit"
67require "test/unit/rr"
78require "tmpdir"
1112
1213module IRubyTest
1314 class TestBase < Test ::Unit ::TestCase
15+ TEST_DIR = File . expand_path ( ".." , __FILE__ ) . freeze
16+ BIN_DIR = File . expand_path ( "../bin" , TEST_DIR ) . freeze
17+ LIB_DIR = File . expand_path ( "../lib" , TEST_DIR ) . freeze
18+
19+ RUBY = RbConfig . ruby . freeze
20+ IRUBY_PATH = File . join ( BIN_DIR , "iruby" ) . freeze
21+
22+ def iruby_command ( *args )
23+ [ RUBY , "-I#{ LIB_DIR } " , IRUBY_PATH , *args ]
24+ end
25+
1426 def self . startup
15- @__config_dir = Dir . mktmpdir ( "iruby-test" )
27+ @__work_dir = Dir . mktmpdir ( "iruby-test-data" )
28+
29+ @__jupyter_data_dir = File . join ( @__work_dir , "jupyter" )
30+ ENV [ "JUPYTER_DATA_DIR" ] = @__jupyter_data_dir
31+ system ( RUBY , "-I#{ LIB_DIR } " , IRUBY_PATH , "register" ,
32+ err : :out , out : File ::NULL )
33+
34+ @__config_dir = File . join ( @__work_dir , "config" )
1635 @__config_path = Pathname . new ( @__config_dir ) + "config.json"
36+ @__config_path . dirname . mkpath
1737 File . write ( @__config_path , {
1838 control_port : 50160 ,
1939 shell_port : 57503 ,
@@ -30,7 +50,7 @@ def self.startup
3050 end
3151
3252 def self . shutdown
33- FileUtils . remove_entry_secure ( @__config_dir )
53+ FileUtils . remove_entry_secure ( @__work_dir )
3454 end
3555
3656 def self . test_config_filename
0 commit comments