Module: OnlyofficeTestrailWrapper::TestrailTools

Defined in:
lib/onlyoffice_testrail_wrapper/testrail_tools/testrail_tools.rb

Overview

Module for Tools for Testrail

Defined Under Namespace

Classes: TestrailConfig

Class Method Summary collapse

Class Method Details

.check_config(*args) ⇒ Object



88
89
90
91
92
93
# File 'lib/onlyoffice_testrail_wrapper/testrail_tools/testrail_tools.rb', line 88

def self.check_config(*args)
  return if @testrail_config && (@testrail_config.instance_variables & args[1..]) == args[1..]

  raise "Method: #{args.shift} - some of needed parameters are missing: #{args.join(', ')}. To configure them, type:\n
         TestrailTools.configure do |config|\n\t\tconfig.param_name = value\n\tend"
end

.close_all_plans_older_than(time) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/onlyoffice_testrail_wrapper/testrail_tools/testrail_tools.rb', line 49

def self.close_all_plans_older_than(time)
  check_config(__method__, :@project)
  loop do
    old_plans = project.plans(is_completed: 0).reject { |e| e.created_on > time.to_i }
    return if old_plans.empty?

    old_plans.each(&:close)
  end
end

.close_all_runs_older_than(time) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/onlyoffice_testrail_wrapper/testrail_tools/testrail_tools.rb', line 39

def self.close_all_runs_older_than(time)
  check_config(__method__, :@project)
  loop do
    old_runs = project.runs(is_completed: 0).reject { |e| e.created_on > time.to_i }
    return if old_runs.empty?

    old_runs.each(&:close)
  end
end

.configure {|@testrail_config| ... } ⇒ Object

Yields:

  • (@testrail_config)


25
26
27
28
# File 'lib/onlyoffice_testrail_wrapper/testrail_tools/testrail_tools.rb', line 25

def self.configure
  @testrail_config ||= TestrailConfig.new
  yield(@testrail_config) if block_given?
end

.get_all_plans_younger_than(time) ⇒ Object



34
35
36
37
# File 'lib/onlyoffice_testrail_wrapper/testrail_tools/testrail_tools.rb', line 34

def self.get_all_plans_younger_than(time)
  check_config(__method__, :@project)
  project.get_plans(is_completed: 0).reject { |e| e['created_on'] < time.to_i }
end

.get_most_failedObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/onlyoffice_testrail_wrapper/testrail_tools/testrail_tools.rb', line 95

def self.get_most_failed
  failed_tests = TestrailTools.get_tests_report(:failed)[@plan.name]
  aborted_tests = TestrailTools.get_tests_report(:aborted)[@plan.name]
  untested_tests = TestrailTools.get_tests_report(:untested)[@plan.name]

  problem_tests = {}
  problem_tests = problem_tests.deep_merge(failed_tests)
  problem_tests = problem_tests.deep_merge(aborted_tests)
  problem_tests = problem_tests.deep_merge(untested_tests)
  problem_result = problem_tests.sort_by { |_key, value| value.length }.reverse
  problem_result.each do |cur|
    p cur[0]
  end
end

.get_runs_durationsObject



64
65
66
67
68
69
70
# File 'lib/onlyoffice_testrail_wrapper/testrail_tools/testrail_tools.rb', line 64

def self.get_runs_durations
  check_config(__method__, :@project, :@plan)
  sorted_durations = plan.plan_durations
  sorted_durations.each do |run|
    OnlyofficeLoggerHelper.log "'#{run.first}' took about #{run[1]} hours"
  end
end

.get_tests_report(status) ⇒ Object



59
60
61
62
# File 'lib/onlyoffice_testrail_wrapper/testrail_tools/testrail_tools.rb', line 59

def self.get_tests_report(status)
  check_config(__method__, :@project, :@plan)
  { plan.name => plan.entries.inject({}) { |a, e| a.merge!({ e.name => e.runs.first.get_tests.filter_map { |test| test['title'] if TestrailResult::RESULT_STATUSES.key(test['status_id']) == status } }.delete_if { |_, value| value.empty? }) } }
end

.planObject



80
81
82
# File 'lib/onlyoffice_testrail_wrapper/testrail_tools/testrail_tools.rb', line 80

def self.plan
  @plan ||= project.plan(@testrail_config.plan)
end

.projectObject



72
73
74
# File 'lib/onlyoffice_testrail_wrapper/testrail_tools/testrail_tools.rb', line 72

def self.project
  @project ||= Testrail2.new.project(@testrail_config.project)
end

.runObject



76
77
78
# File 'lib/onlyoffice_testrail_wrapper/testrail_tools/testrail_tools.rb', line 76

def self.run
  @run ||= project.test_run(@testrail_config.run)
end

.suiteObject



84
85
86
# File 'lib/onlyoffice_testrail_wrapper/testrail_tools/testrail_tools.rb', line 84

def self.suite
  @suite ||= project.suite(@testrail_config.suite)
end

.testrailObject



30
31
32
# File 'lib/onlyoffice_testrail_wrapper/testrail_tools/testrail_tools.rb', line 30

def self.testrail
  @testrail_config
end