Module: Allure::ResultUtils

Defined in:
allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb

Overview

Variouse helper methods

Constant Summary collapse

"issue"
"tms"
ALLURE_ID_LABEL_NAME =
"AS_ID"
SUITE_LABEL_NAME =
"suite"
PARENT_SUITE_LABEL_NAME =
"parentSuite"
SUB_SUITE_LABEL_NAME =
"subSuite"
EPIC_LABEL_NAME =
"epic"
FEATURE_LABEL_NAME =
"feature"
STORY_LABEL_NAME =
"story"
SEVERITY_LABEL_NAME =
"severity"
TAG_LABEL_NAME =
"tag"
OWNER_LABEL_NAME =
"owner"
LEAD_LABEL_NAME =
"lead"
HOST_LABEL_NAME =
"host"
THREAD_LABEL_NAME =
"thread"
TEST_METHOD_LABEL_NAME =
"testMethod"
TEST_CLASS_LABEL_NAME =
"testClass"
PACKAGE_LABEL_NAME =
"package"
FRAMEWORK_LABEL_NAME =
"framework"
LANGUAGE_LABEL_NAME =
"language"

Class Method Summary collapse

Class Method Details

.epic_label(value) ⇒ Allure::Label

Epic label

Parameters:

  • value (String)

Returns:



66
67
68
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 66

def epic_label(value)
  Label.new(EPIC_LABEL_NAME, value)
end

.feature_label(value) ⇒ Allure::Label

Feature label

Parameters:

  • value (String)

Returns:



73
74
75
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 73

def feature_label(value)
  Label.new(FEATURE_LABEL_NAME, value)
end

.framework_label(value) ⇒ Allure::Label

Framework label

Parameters:

  • value (String)

Returns:



59
60
61
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 59

def framework_label(value)
  Label.new(FRAMEWORK_LABEL_NAME, value)
end

.host_labelAllure::Label

Host label

Returns:



46
47
48
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 46

def host_label
  Label.new(HOST_LABEL_NAME, Socket.gethostname)
end

Issue link

Parameters:

  • value (String)
  • link_pattern (String)

Returns:



146
147
148
149
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 146

def issue_link(name, value, link_pattern)
  link_name = url?(value) ? name : value
  Link.new(ISSUE_LINK_TYPE, link_name, url(value, link_pattern))
end

.language_labelAllure::Label

Language label

Returns:



52
53
54
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 52

def language_label
  Label.new(LANGUAGE_LABEL_NAME, "ruby")
end

.package_label(value) ⇒ Allure::Label

Package label

Parameters:

  • value (String)

Returns:



87
88
89
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 87

def package_label(value)
  Label.new(PACKAGE_LABEL_NAME, value)
end

.parent_suite_label(value) ⇒ Allure::Label

Parent suite label

Parameters:

  • value (String)

Returns:



101
102
103
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 101

def parent_suite_label(value)
  Label.new(PARENT_SUITE_LABEL_NAME, value)
end

.prepare_attachment(name, type) ⇒ Allure::Attachment

Allure attachment object

Parameters:

  • name (String)
  • type (String)

Returns:



169
170
171
172
173
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 169

def prepare_attachment(name, type)
  extension = ContentType.to_extension(type) || return
  file_name = "#{UUID.generate}-attachment.#{extension}"
  Attachment.new(name: name, source: file_name, type: type)
end

.severity_label(value) ⇒ Allure::Label

Severity label

Parameters:

  • value (String)

Returns:



129
130
131
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 129

def severity_label(value)
  Label.new(SEVERITY_LABEL_NAME, value)
end

.status(exception) ⇒ Symbol

Get status based on exception type

Parameters:

  • exception (Exception)

Returns:

  • (Symbol)


154
155
156
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 154

def status(exception)
  exception.is_a?(RSpec::Expectations::ExpectationNotMetError) ? Status::FAILED : Status::BROKEN
end

.status_details(exception) ⇒ Allure::StatusDetails

Get exception status detail

Parameters:

  • exception (Exception)

Returns:



161
162
163
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 161

def status_details(exception)
  StatusDetails.new(message: exception&.message, trace: exception&.backtrace&.join("\n"))
end

.story_label(value) ⇒ Allure::Label

Story label

Parameters:

  • value (String)

Returns:



80
81
82
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 80

def (value)
  Label.new(STORY_LABEL_NAME, value)
end

.sub_suite_label(value) ⇒ Allure::Label

Parent suite label

Parameters:

  • value (String)

Returns:



108
109
110
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 108

def sub_suite_label(value)
  Label.new(SUB_SUITE_LABEL_NAME, value)
end

.suite_label(value) ⇒ Allure::Label

Suite label

Parameters:

  • value (String)

Returns:



94
95
96
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 94

def suite_label(value)
  Label.new(SUITE_LABEL_NAME, value)
end

.tag_label(value) ⇒ Allure::Label

Tag label

Parameters:

  • value (String)

Returns:



122
123
124
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 122

def tag_label(value)
  Label.new(TAG_LABEL_NAME, value)
end

.test_class_label(value) ⇒ Allure::Label

Test case label

Parameters:

  • value (String)

Returns:



115
116
117
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 115

def test_class_label(value)
  Label.new(TEST_CLASS_LABEL_NAME, value)
end

.thread_labelAllure::Label

Current thread label

Returns:



40
41
42
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 40

def thread_label
  Label.new(THREAD_LABEL_NAME, Thread.current.object_id)
end

.timestamp(time = nil) ⇒ Number

Parameters:

  • time (Time) (defaults to: nil)

Returns:

  • (Number)


34
35
36
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 34

def timestamp(time = nil)
  ((time || Time.now).to_f * 1000).to_i
end

TMS link

Parameters:

  • value (String)
  • link_pattern (String)

Returns:



137
138
139
140
# File 'allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb', line 137

def tms_link(name, value, link_pattern)
  link_name = url?(value) ? name : value
  Link.new(TMS_LINK_TYPE, link_name, url(value, link_pattern))
end