Skip to content

Commit fe6c810

Browse files
authored
Add method for defining custom categories (#65)
* Add method for categories definition * Fix rubocop warnings * Bump ruby version
1 parent 72de146 commit fe6c810

File tree

12 files changed

+86
-10
lines changed

12 files changed

+86
-10
lines changed

.rubocop.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Bundler/InsecureProtocolSource:
2020
Bundler/OrderedGems:
2121
Enabled: true
2222

23+
Layout/LineLength:
24+
Enabled: true
25+
Max: 120
26+
2327
Layout/AccessModifierIndentation:
2428
Enabled: true
2529
EnforcedStyle: indent
@@ -636,10 +640,6 @@ Metrics/ClassLength:
636640
Metrics/CyclomaticComplexity:
637641
Enabled: false
638642

639-
Metrics/LineLength:
640-
Enabled: true
641-
Max: 120
642-
643643
Metrics/MethodLength:
644644
Enabled: true
645645
Max: 12
@@ -1439,7 +1439,7 @@ Style/TrivialAccessors:
14391439
AllowPredicates: true
14401440
AllowDSLWriters: false
14411441
IgnoreClassMethods: false
1442-
AllowedMethod:
1442+
AllowedMethods:
14431443
- to_ary
14441444
- to_a
14451445
- to_c

ALLURE_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.13.2
1+
2.13.3

allure-ruby-commons/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Allure Ruby Adaptor API
2+
23
[![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://www.rubydoc.info/gems/allure-ruby-commons)
34

45
This is a helper library containing the basics for any ruby-based Allure adaptor.

allure-ruby-commons/lib/allure-ruby-commons.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,20 @@ def add_attachment(name:, source:, type:, test_case: false)
138138
lifecycle.add_attachment(name: name, source: source, type: type, test_case: test_case)
139139
end
140140

141-
# Write allure report environment info
141+
# Add allure report environment info
142142
# @param [Hash<Symbol, String>] environment
143143
# @return [void]
144144
def add_environment(environment)
145145
lifecycle.write_environment(environment)
146146
end
147147

148+
# Add categories info
149+
# @param [File, Array<Allure::Category>] categories
150+
# @return [void]
151+
def add_categories(categories)
152+
lifecycle.write_categories(categories)
153+
end
154+
148155
# Add step with provided name and optional status to current test step, fixture or test case
149156
# @param [String] name
150157
# @param [Symbol] status <Allure::Status>, <Allure::Status::PASSED> by default

allure-ruby-commons/lib/allure_ruby_commons/allure_lifecycle.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def initialize
1313
@step_context = []
1414
end
1515

16-
def_delegators :file_writer, :write_attachment, :write_environment
16+
def_delegators :file_writer, :write_attachment, :write_environment, :write_categories
1717

1818
# Start test result container
1919
# @param [Allure::TestResultContainer] test_result_container

allure-ruby-commons/lib/allure_ruby_commons/file_writer.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class FileWriter
99
TEST_RESULT_CONTAINER_SUFFIX = "-container.json"
1010
# @return [String] attachment file suffix
1111
ATTACHMENT_FILE_SUFFIX = "-attachment"
12+
# @return [String] environment info file
13+
ENVIRONMENT_FILE = "environment.properties"
14+
# @return [String] categories definition json
15+
CATEGORIES_FILE = "categories.json"
1216

1317
# Write test result
1418
# @param [Allure::TestResult] test_result
@@ -37,7 +41,18 @@ def write_attachment(source, attachment)
3741
# @return [void]
3842
def write_environment(environment)
3943
environment.reduce("") { |e, (k, v)| e + "#{k}=#{v}\n" }.tap do |env|
40-
write("environment.properties", env)
44+
write(ENVIRONMENT_FILE, env)
45+
end
46+
end
47+
48+
# Write categories info
49+
# @param [File, Array<Allure::Category>] categories
50+
# @return [void]
51+
def write_categories(categories)
52+
if categories.is_a?(File)
53+
copy(categories.path, CATEGORIES_FILE)
54+
else
55+
write(CATEGORIES_FILE, categories.to_json)
4156
end
4257
end
4358

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "jsonable"
4+
5+
module Allure
6+
class Category < JSONable
7+
# Defects category
8+
# @param [String] name
9+
# @param [Array<Allure::Status>] matched_statuses
10+
# @param [String, Regexp] message_regex
11+
# @param [String, Regexp] trace_regex
12+
def initialize(name:, matched_statuses: nil, message_regex: nil, trace_regex: nil)
13+
@name = name
14+
@matched_statuses = matched_statuses
15+
@message_regex = message_regex
16+
@trace_regex = trace_regex
17+
end
18+
end
19+
end

allure-ruby-commons/lib/allure_ruby_commons/model/status.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ class Status
77
BROKEN = :broken
88
PASSED = :passed
99
SKIPPED = :skipped
10+
UNKNOWN = :unknown
1011
end
1112
end

allure-ruby-commons/lib/allure_ruby_commons/model/test_result_container.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require_relative "jsonable"
4+
45
module Allure
56
# Allure model step result container
67
class TestResultContainer < JSONable
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"name": "Ignored test",
4+
"matchedStatuses": [
5+
"skipped"
6+
]
7+
}
8+
]

0 commit comments

Comments
 (0)