allure-ruby-commons 2.32.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 158481dc0f3a21a190859fa2ed209bc93dc94185393c9c6767a83481c01e1dac
4
- data.tar.gz: 94f52c299af1494c6e6c372f562a196ba7c9000cb489f9b7effea335c2f8e9e7
3
+ metadata.gz: 4f277003a74d66895231ecfa3a779322248cef35ff42f4df103cada8f0911490
4
+ data.tar.gz: bfa71c941b4365761b15842964f7bb6ab5c943a3c25f7d6488b0fbe590f50523
5
5
  SHA512:
6
- metadata.gz: db735212d318744aa39642149273e407104a7cb3d881590fbf12cc478431053ede8eb9ff5e56e01560ade8bf9d585a953d188aa39a7bdb2453b89f00340e50b5
7
- data.tar.gz: 3d80679f0439e64299f62948621db0931ddbc34125e59c47722d2891468ca4810c00f58df0422772857d0a9a13acbe8dd2bb72cadd70aa118a591ff2495b921a
6
+ metadata.gz: 2d51daad1f6de28c006d2f45607e8457ebb57564a2c484faf1aae11011968e6fd08a144fcf5e4d3b1ec701f90ed7f378945991eac437c25bfd19cb461612ce87
7
+ data.tar.gz: 53ceb1c66485a483f4dc4354fff8989c11183bf1cc3a35e6fb15174ed1a13eec37468c5546f3590b64c534d8c89db3b51135d774957f1181b721c0f551e62a24
@@ -115,6 +115,42 @@ module Allure
115
115
  end
116
116
  end
117
117
 
118
+ # Add precondition to current test case
119
+ # @param [String] precondition
120
+ # @return [void]
121
+ def add_precondition(precondition)
122
+ lifecycle.update_test_case do |test_case|
123
+ test_case.precondition = precondition
124
+ end
125
+ end
126
+
127
+ # Add html precondition to current test case
128
+ # @param [String] precondition_html
129
+ # @return [void]
130
+ def precondition_html(precondition_html)
131
+ lifecycle.update_test_case do |test_case|
132
+ test_case.precondition_html = precondition_html
133
+ end
134
+ end
135
+
136
+ # Add expected result to current test case
137
+ # @param [String] expected_result
138
+ # @return [void]
139
+ def add_expected_result(expected_result)
140
+ lifecycle.update_test_case do |test_case|
141
+ test_case.expected_result = expected_result
142
+ end
143
+ end
144
+
145
+ # Add html expected result to current test case
146
+ # @param [String] expected_result_html
147
+ # @return [void]
148
+ def expected_result_html(expected_result_html)
149
+ lifecycle.update_test_case do |test_case|
150
+ test_case.expected_result_html = expected_result_html
151
+ end
152
+ end
153
+
118
154
  # Add parameter to current test case
119
155
  # @param [String] name
120
156
  # @param [String] value
@@ -9,9 +9,14 @@ module Allure
9
9
  # @param [Hash] options
10
10
  # @option options [String] :name
11
11
  # @option options [String] :full_name
12
+ # @option options [String] :test_case_id
12
13
  # @option options [Array<String>] :title_path
13
14
  # @option options [String] :description
14
15
  # @option options [String] :description_html
16
+ # @option options [String] :precondition
17
+ # @option options [String] :precondition_html
18
+ # @option options [String] :expected_result
19
+ # @option options [String] :expected_result_html
15
20
  # @option options [String] :status ('broken')
16
21
  # @option options [String] :stage ('scheduled')
17
22
  # @option options [Allure::StatusDetails] :status_details
@@ -27,7 +32,12 @@ module Allure
27
32
  @uuid = uuid
28
33
  @history_id = history_id
29
34
  @full_name = options[:full_name] || "Unnamed"
35
+ @test_case_id = options[:test_case_id]
30
36
  @title_path = options[:title_path]
37
+ @precondition = options[:precondition]
38
+ @precondition_html = options[:precondition_html]
39
+ @expected_result = options[:expected_result]
40
+ @expected_result_html = options[:expected_result_html]
31
41
  @labels = options[:labels] || []
32
42
  @links = options[:links] || []
33
43
  @parameters << Parameter.new("environment", environment) if environment
@@ -35,7 +45,12 @@ module Allure
35
45
 
36
46
  attr_accessor :uuid,
37
47
  :full_name,
48
+ :test_case_id,
38
49
  :title_path,
50
+ :precondition,
51
+ :precondition_html,
52
+ :expected_result,
53
+ :expected_result_html,
39
54
  :labels,
40
55
  :links
41
56
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "pathname"
3
4
  require "socket"
4
5
  require "uri"
5
6
 
@@ -29,6 +30,16 @@ module Allure
29
30
  LANGUAGE_LABEL_NAME = "language"
30
31
 
31
32
  class << self
33
+ # Stable test case identity independent of source line and parameter values
34
+ # @param [String] file_path
35
+ # @param [String] full_name
36
+ # @return [String]
37
+ def full_name(file_path, full_name)
38
+ relative_path = Pathname.new(File.expand_path(file_path)).relative_path_from(Pathname.pwd).to_s
39
+
40
+ "#{relative_path}##{full_name}"
41
+ end
42
+
32
43
  # @param [Time] time
33
44
  # @return [Number]
34
45
  def timestamp(time = nil)
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "set"
4
+
5
+ module Allure
6
+ class TestPlan
7
+ extend JsonHelper
8
+
9
+ # @return [String] test plan path env var name
10
+ TESTPLAN_PATH = "ALLURE_TESTPLAN_PATH"
11
+
12
+ class << self
13
+ # Allure id's of executable tests
14
+ #
15
+ # @return [Array]
16
+ def test_ids
17
+ @test_ids ||= tests&.filter_map { |test| test[:id] }
18
+ end
19
+
20
+ # Test names of executable tests
21
+ #
22
+ # @return [Array]
23
+ def test_names
24
+ @test_names ||= tests&.filter_map { |test| test[:selector] }
25
+ end
26
+
27
+ # Match an Allure ID first, falling back to the selector and generated identity
28
+ #
29
+ # @param [String, Integer, nil] allure_id
30
+ # @param [String, nil] selector file-qualified full name
31
+ # @param [String] test_case_id
32
+ # @return [Boolean]
33
+ def excluded?(allure_id:, selector:, test_case_id:)
34
+ return true if allure_id && excluded_allure_ids.include?(allure_id.to_s)
35
+ return true if excluded_selectors.include?(selector)
36
+
37
+ excluded_test_ids.include?(test_case_id)
38
+ end
39
+
40
+ # Whether the test plan contains any excluded identities
41
+ #
42
+ # @return [Boolean]
43
+ def excluded_tests?
44
+ excluded_allure_ids.any? || excluded_test_ids.any? || excluded_selectors.any?
45
+ end
46
+
47
+ private
48
+
49
+ # Excluded explicit Allure ids
50
+ #
51
+ # @return [Set]
52
+ def excluded_allure_ids
53
+ @excluded_allure_ids ||= Set.new(excluded_tests&.filter_map { |test| test[:id]&.to_s }).freeze
54
+ end
55
+
56
+ # Excluded test case ids
57
+ #
58
+ # @return [Set]
59
+ def excluded_test_ids
60
+ @excluded_test_ids ||= Set.new(excluded_tests&.filter_map { |test| test[:testCaseId] }).freeze
61
+ end
62
+
63
+ # Excluded file-qualified full-name selectors
64
+ #
65
+ # @return [Set]
66
+ def excluded_selectors
67
+ @excluded_selectors ||= Set.new(excluded_tests&.filter_map { |test| test[:selector] }).freeze
68
+ end
69
+
70
+ # Parsed test plan object
71
+ #
72
+ # @return [Hash]
73
+ def test_plan
74
+ @test_plan ||= load_json(test_plan_path)
75
+ end
76
+
77
+ # Tests to execute from allure testplan.json
78
+ #
79
+ # @return [Array<Hash>]
80
+ def tests
81
+ @tests ||= test_plan&.fetch(:tests, nil) if test_plan_path
82
+ end
83
+
84
+ # Tests to skip from allure testplan.json
85
+ #
86
+ # @return [Array<Hash>]
87
+ def excluded_tests
88
+ @excluded_tests ||= test_plan&.fetch(:excludedTests, nil) if test_plan_path
89
+ end
90
+
91
+ # Fetch test plan path
92
+ #
93
+ # @return [<String, nil>]
94
+ def test_plan_path
95
+ return @test_plan_path if defined?(@test_plan_path)
96
+
97
+ @test_plan_path = ENV[TESTPLAN_PATH].then do |path|
98
+ next unless path
99
+ next path if File.file?(path)
100
+
101
+ json = File.join(path, "testplan.json")
102
+ next json if File.exist?(json)
103
+
104
+ Allure.configuration.logger.warn("'ALLURE_TESTPLAN_PATH' env var is set, but no testplan.json found!")
105
+ nil
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: allure-ruby-commons
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.32.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrejs Cunskis
@@ -96,7 +96,7 @@ files:
96
96
  - lib/allure_ruby_commons/model/test_result_container.rb
97
97
  - lib/allure_ruby_commons/result_utils.rb
98
98
  - lib/allure_ruby_commons/step_annotation.rb
99
- - lib/allure_ruby_commons/testplan.rb
99
+ - lib/allure_ruby_commons/test_plan.rb
100
100
  homepage: https://github.com/allure-framework/allure-ruby
101
101
  licenses:
102
102
  - Apache-2.0
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Allure
4
- class TestPlan
5
- extend JsonHelper
6
-
7
- # @return [String] test plan path env var name
8
- TESTPLAN_PATH = "ALLURE_TESTPLAN_PATH"
9
-
10
- class << self
11
- # Allure id's of executable tests
12
- #
13
- # @return [Array]
14
- def test_ids
15
- @test_ids ||= tests&.map { |test| test[:id] }
16
- end
17
-
18
- # Test names of executable tests
19
- #
20
- # @return [Array]
21
- def test_names
22
- @test_names ||= tests&.map { |test| test[:selector] }
23
- end
24
-
25
- private
26
-
27
- # Tests to execute from allure testplan.json
28
- #
29
- # @return [Array<Hash>]
30
- def tests
31
- @tests ||= load_json(test_plan_path)&.fetch(:tests) if test_plan_path
32
- end
33
-
34
- # Fetch test plan path
35
- #
36
- # @return [<String, nil>]
37
- def test_plan_path
38
- return @test_plan_path if defined?(@test_plan_path)
39
-
40
- @test_plan_path = ENV[TESTPLAN_PATH].then do |path|
41
- next unless path
42
- next path if File.file?(path)
43
-
44
- json = File.join(path, "testplan.json")
45
- next json if File.exist?(json)
46
-
47
- Allure.configuration.logger.warn("'ALLURE_TESTPLAN_PATH' env var is set, but no testplan.json found!")
48
- nil
49
- end
50
- end
51
- end
52
- end
53
- end