Use singleton in tests

This commit is contained in:
Alex Ling 2020-05-07 09:26:26 +00:00
parent 7448592216
commit 30dea57346
2 changed files with 8 additions and 8 deletions

View File

@ -2,7 +2,7 @@ require "./spec_helper"
describe Config do describe Config do
it "creates config if it does not exist" do it "creates config if it does not exist" do
with_default_config do |_, _, path| with_default_config do |_, path|
File.exists?(path).should be_true File.exists?(path).should be_true
end end
end end

View File

@ -1,6 +1,6 @@
require "spec" require "spec"
require "../src/context"
require "../src/server" require "../src/server"
require "../src/config"
class State class State
@@hash = {} of String => String @@hash = {} of String => String
@ -37,15 +37,15 @@ end
def with_default_config def with_default_config
temp_config = get_tempfile "mango-test-config" temp_config = get_tempfile "mango-test-config"
config = Config.load temp_config.path config = Config.load temp_config.path
logger = Logger.new config.log_level config.set_current
yield config, logger, temp_config.path yield config, temp_config.path
temp_config.delete temp_config.delete
end end
def with_storage def with_storage
with_default_config do |_, logger| with_default_config do
temp_db = get_tempfile "mango-test-db" temp_db = get_tempfile "mango-test-db"
storage = Storage.new temp_db.path, logger storage = Storage.new temp_db.path
clear = yield storage, temp_db.path clear = yield storage, temp_db.path
if clear == true if clear == true
temp_db.delete temp_db.delete
@ -54,9 +54,9 @@ def with_storage
end end
def with_queue def with_queue
with_default_config do |_, logger| with_default_config do
temp_queue_db = get_tempfile "mango-test-queue-db" temp_queue_db = get_tempfile "mango-test-queue-db"
queue = MangaDex::Queue.new temp_queue_db.path, logger queue = MangaDex::Queue.new temp_queue_db.path
clear = yield queue, temp_queue_db.path clear = yield queue, temp_queue_db.path
if clear == true if clear == true
temp_queue_db.delete temp_queue_db.delete