From 3290a4ab28692b00071cb8e0206788d6295a19d9 Mon Sep 17 00:00:00 2001 From: HassanAkbar Date: Fri, 8 Mar 2024 20:02:28 +0500 Subject: [PATCH] Removed tmp directory logic for sqlite3 --- spec/acceptance/xlsx2db_spec.rb | 43 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/spec/acceptance/xlsx2db_spec.rb b/spec/acceptance/xlsx2db_spec.rb index 28e2e0e..17372f4 100644 --- a/spec/acceptance/xlsx2db_spec.rb +++ b/spec/acceptance/xlsx2db_spec.rb @@ -5,36 +5,39 @@ RSpec.describe "IEV" do let(:sample_xlsx_file) { fixture_path("sample-file.xlsx") } + let(:tmp_db_dir) { "tmp-db-dir" } describe "xlsx2db" do it "imports XLSX document to database" do - Dir.mktmpdir("iev-test") do |dir| - dbfile = "#{dir}/test.sqlite3" - command = %W(xlsx2db #{sample_xlsx_file} -o #{dbfile}) - silence_output_streams { IEV::CLI.start(command) } + FileUtils.rm_rf(tmp_db_dir) if Dir.exist?(tmp_db_dir) - expect(dbfile).to satisfy { |p| File.file? p } + Dir.mkdir tmp_db_dir - db = SQLite3::Database.new(dbfile) + dbfile = File.join(tmp_db_dir, "test.sqlite3") + command = %W(xlsx2db #{sample_xlsx_file} -o #{dbfile}) + silence_output_streams { IEV::CLI.start(command) } - sql = <<~SQL - select count(*) - from concepts - where language = 'en' - SQL + expect(dbfile).to satisfy { |p| File.file? p } - expect(db.execute(sql).first.first).to eq(2) + db = SQLite3::Database.new(dbfile) - sql = <<~SQL - select term - from concepts - where language = 'en' and ievref = '103-01-01' - SQL + sql = <<~SQL + select count(*) + from concepts + where language = 'en' + SQL - expect(db.execute(sql).first.first).to eq("function") + expect(db.execute(sql).first.first).to eq(2) - FileUtils.rm_rf Dir.glob(File.join(dir, "*")) - end + sql = <<~SQL + select term + from concepts + where language = 'en' and ievref = '103-01-01' + SQL + + expect(db.execute(sql).first.first).to eq("function") + + FileUtils.rm_rf(tmp_db_dir) end end end