Class: Modsvaskr::TestsSuite

Inherits:
Object
  • Object
show all
Includes:
Logger, RunCmd
Defined in:
lib/modsvaskr/tests_suite.rb

Overview

Common functionality for any tests suite

Instance Method Summary collapse

Methods included from Logger

#log

Methods included from RunCmd

#run_cmd

Constructor Details

#initialize(tests_suite, game) ⇒ TestsSuite

Constructor

Parameters
  • tests_suite (Symbol): The tests suite name

  • game (Game): The game for which this test type is instantiated



18
19
20
21
# File 'lib/modsvaskr/tests_suite.rb', line 18

def initialize(tests_suite, game)
  @tests_suite = tests_suite
  @game = game
end

Instance Method Details

#clear_testsObject

Remove all tests from this suite



53
54
55
# File 'lib/modsvaskr/tests_suite.rb', line 53

def clear_tests
  File.unlink(json_statuses_file) if File.exist?(json_statuses_file)
end

#set_statuses(statuses) ⇒ Object

Set test statuses. Add new ones and overwrites existing ones.

Parameters
  • statuses (Array<[String, String]>): Ordered list of [test name, test status]



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/modsvaskr/tests_suite.rb', line 36

def set_statuses(statuses)
  current_statuses = self.statuses
  statuses.each do |(test_name, test_status)|
    test_status_info = current_statuses.find { |(search_test_name, _search_test_status)| search_test_name == test_name }
    if test_status_info.nil?
      # New one. Add it to the end.
      current_statuses << [test_name, test_status]
    else
      # Already existing. Just change its status.
      test_status_info[1] = test_status
    end
  end
  FileUtils.mkdir_p File.dirname(json_statuses_file)
  File.write(json_statuses_file, JSON.pretty_generate(current_statuses))
end

#statusesObject

Get test statuses

Result
  • Array<[String, String]>: Ordered list of [test name, test status]



27
28
29
# File 'lib/modsvaskr/tests_suite.rb', line 27

def statuses
  File.exist?(json_statuses_file) ? JSON.parse(File.read(json_statuses_file)) : []
end