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.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/testrail/test_suite.rb', line 9

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



33
34
35
# File 'lib/testrail/test_suite.rb', line 33

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

#create_section(section_name) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/testrail/test_suite.rb', line 45

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



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

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



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

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



41
42
43
# File 'lib/testrail/test_suite.rb', line 41

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



24
25
26
27
# File 'lib/testrail/test_suite.rb', line 24

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



29
30
31
# File 'lib/testrail/test_suite.rb', line 29

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