Module: SibaTest

Extended by:
Siba::TmpDirPlug
Defined in:
lib/siba/helpers/test/removable_constants.rb,
lib/siba/helpers/test/helper.rb,
lib/siba/helpers/test/file_mock.rb,
lib/siba/helpers/test/kernel_mock.rb

Overview

Defined Under Namespace

Modules: RemovableConstants Classes: FileMock, KernelMock

Constant Summary collapse

IS_WINDOWS =
!(RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/).nil?
UNICODE_FILE_NAME =
"алиен学"
TmpDirMocked =
"/tmp"

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Siba::TmpDirPlug

cleanup_tmp_dir, tmp_dir, tmp_dir_clean?

Methods included from Siba::LoggerPlug

close, create, logger, #logger, opened?

Methods included from Siba::FilePlug

#siba_file, siba_file, siba_file=

Class Attribute Details

.setup_hooksObject

Returns the value of attribute setup_hooks.



11
12
13
# File 'lib/siba/helpers/test/helper.rb', line 11

def setup_hooks
  @setup_hooks
end

.teardown_hooksObject

Returns the value of attribute teardown_hooks.



12
13
14
# File 'lib/siba/helpers/test/helper.rb', line 12

def teardown_hooks
  @teardown_hooks
end

Class Method Details

.initObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/siba/helpers/test/helper.rb', line 14

def init
  require 'minitest/pride' unless SibaTest::IS_WINDOWS

  @loaded_options = {}
  @current_dir = siba_file.file_utils_pwd
  @setup_hooks = []
  @teardown_hooks = []

  @setup_hooks << -> do
    Siba::SibaLogger.quiet = true
    Siba::SibaLogger.no_log = true
    Siba::LoggerPlug.create "Test", nil
    Siba::SibaLogger.messages = []
    Siba.settings = {}
    Siba.current_dir = @current_dir
    Siba.backup_name = "siba"
    SibaTest::KernelMock.mock_all_methods # prevents tests from accessing Kernel methods
  end

  @teardown_hooks << -> { Siba::LoggerPlug.close }
end

.init_integrationObject



44
45
46
47
48
49
50
51
52
# File 'lib/siba/helpers/test/helper.rb', line 44

def init_integration
  init
  @teardown_hooks << -> do
    # cleanup after each integration test
    Siba.current_dir = @current_dir
    Siba.cleanup_tmp_dir
    SibaTest.cleanup_tmp_dir
  end
end

.init_unitObject



36
37
38
39
40
41
42
# File 'lib/siba/helpers/test/helper.rb', line 36

def init_unit
  init
  @setup_hooks << -> do
    SibaTest::FileMock.mock_all_methods # prevents tests from doing file operations
    Siba.class_eval {@tmp_dir = SibaTest::TmpDirMocked}
  end
end

.load_options(path_to_yml) ⇒ Object



54
55
56
# File 'lib/siba/helpers/test/helper.rb', line 54

def load_options(path_to_yml)
  @loaded_options[path_to_yml] ||= Siba::OptionsLoader.load_yml(path_to_yml)
end