test/helper.rb in iruby-0.7.4 vs test/helper.rb in iruby-0.8.0

- old
+ new

@@ -1,21 +1,39 @@ require "iruby" require "json" require 'multi_json' require "pathname" +require "rbconfig" require "test/unit" require "test/unit/rr" require "tmpdir" - IRuby.logger = IRuby::MultiLogger.new(*Logger.new(STDERR, level: Logger::Severity::INFO)) module IRubyTest class TestBase < Test::Unit::TestCase + TEST_DIR = File.expand_path("..", __FILE__).freeze + EXE_DIR = File.expand_path("../exe", TEST_DIR).freeze + LIB_DIR = File.expand_path("../lib", TEST_DIR).freeze + + RUBY = RbConfig.ruby.freeze + IRUBY_PATH = File.join(EXE_DIR, "iruby").freeze + + def iruby_command(*args) + [RUBY, "-I#{LIB_DIR}", IRUBY_PATH, *args] + end + def self.startup - @__config_dir = Dir.mktmpdir("iruby-test") + @__work_dir = Dir.mktmpdir("iruby-test-data") + + @__jupyter_data_dir = File.join(@__work_dir, "jupyter") + @__save_jupyter_data_dir = ENV["JUPYTER_DATA_DIR"] + ENV["JUPYTER_DATA_DIR"] = @__jupyter_data_dir + + @__config_dir = File.join(@__work_dir, "config") @__config_path = Pathname.new(@__config_dir) + "config.json" + @__config_path.dirname.mkpath File.write(@__config_path, { control_port: 50160, shell_port: 57503, transport: "tcp", signature_scheme: "hmac-sha256", @@ -28,10 +46,11 @@ @__original_kernel_instance = IRuby::Kernel.instance end def self.shutdown - FileUtils.remove_entry_secure(@__config_dir) + FileUtils.remove_entry_secure(@__work_dir) + ENV["JUPYTER_DATA_DIR"] = @__save_jupyter_data_dir end def self.test_config_filename @__config_path.to_s end