Class: TestRail::TestSuite

Inherits:
Object
  • Object
show all
Defined in:
lib/testrail/test_suite.rb

Instance Method Summary collapse

Constructor Details

#initialize(project_id:, suite_id:, testrail_client:) ⇒ TestSuite

Returns a new instance of TestSuite.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/testrail/test_suite.rb', line 23

def initialize(project_id:, suite_id:, testrail_client:)
  @project_id = project_id
  @suite_id = suite_id
  @testrail_client = testrail_client
  sections = testrail_client.get_sections(project_id: project_id, suite_id: suite_id)
                            .map { |s| new_test_section(s) }
  @sections_by_name = Hash[sections.map { |s| [s.name, s] }]
  @sections_by_id = Hash[sections.map { |s| [s.id, s] }]
  @test_cases = Hash[testrail_client.get_test_cases(project_id: project_id, suite_id: suite_id)
                                    .lazy
                                    .map { |t| new_test_case(t) }
                                    .map { |t| [test_case_key(t.section.id, t.name), t] }
                .to_a]
end

Instance Method Details

#close_test_run(run_id) ⇒ Object



47
48
49
# File 'lib/testrail/test_suite.rb', line 47

def close_test_run(run_id)
  @testrail_client.close_test_run(run_id)
end

#create_section(section_name) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/testrail/test_suite.rb', line 59

def create_section(section_name)
  section = new_test_section(@testrail_client.create_section(
                               project_id: @project_id,
                               suite_id: @suite_id,
                               section_name: section_name))
  @sections_by_name[section_name] = section
  @sections_by_id[section.id] = section
end

#create_test_case(section_id:, name:) ⇒ Object



68
69
70
71
72
73
# File 'lib/testrail/test_suite.rb', line 68

def create_test_case(section_id:, name:)
  test_case = new_test_case(@testrail_client.create_test_case(
                              section_id: section_id,
                              name: name))
  @test_cases[test_case_key(test_case.section.id, test_case.name)] = test_case
end

#get_or_create_section(section_name) ⇒ Object



51
52
53
# File 'lib/testrail/test_suite.rb', line 51

def get_or_create_section(section_name)
  @sections_by_name[section_name] || create_section(section_name)
end

#get_or_create_test_case(section_id:, name:) ⇒ Object



55
56
57
# File 'lib/testrail/test_suite.rb', line 55

def get_or_create_test_case(section_id:, name:)
  @test_cases[test_case_key(section_id, name)] || create_test_case(section_id: section_id, name: name)
end

#start_test_runObject



38
39
40
41
# File 'lib/testrail/test_suite.rb', line 38

def start_test_run
  run = @testrail_client.start_test_run(project_id: @project_id, suite_id: @suite_id)
  TestRun.new(suite: self, id: run['id'])
end

#submit_test_results(run_id:, results:) ⇒ Object



43
44
45
# File 'lib/testrail/test_suite.rb', line 43

def submit_test_results(run_id:, results:)
  @testrail_client.submit_test_results(run_id: run_id, results: results.map(&:to_hash))
end