allure-rspec 2.13.8.1 → 2.13.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55f2f8820b6daa5d3c02e82351e4d2e96eb3ef2855e7f9996fc443fa1c365732
4
- data.tar.gz: 20f57610fa0c184bb8a760a072bac74aef030dfab41f455afa539009d06c7a75
3
+ metadata.gz: 77fad060fb1fbcbbb4399244a58df51707defcfe9a2e7b5a5b193fb1a4940420
4
+ data.tar.gz: 73d4d50f964562c583158da41999dc8c8390f8b977cf3c532da7da50f8524835
5
5
  SHA512:
6
- metadata.gz: 102c88482e735b89b351725c099429f3d1637a156bd5e86f8f2893ecc3d30501f41439e95544fa0aedb17f3c85e875aa455dec746df97355d9e3b70ae78969dc
7
- data.tar.gz: 0b64c2312ab9c7d17f1ae1fc196403c60207224400f77e2260aa5a17a05563ccafbd90d9b05ca87713566b2c6b7c0e27f84239ae3d2b8cc2bbab7b7661cd1356
6
+ metadata.gz: 5344896aeb24c28fb6f424c2485f61e1f2656f5f0639bf25f981f88a50d432a3afa947e3b2f4f6967218c8896f9759de8f07f3aca880b6d22f9dbf46def8ca23
7
+ data.tar.gz: 3f3201b3da9e3997bdcc368a274b39830569612621d0af206457aa046a507f4185679674d419971f39697da9ecae6b79acd5e05eff1ebe02a38cdda5ddf7fed4
data/README.md CHANGED
@@ -131,6 +131,24 @@ it "some test case", allure_1: "visual_test", allure_2: "core_functionality" do
131
131
  end
132
132
  ```
133
133
 
134
+ ### Behavior driven test grouping
135
+
136
+ Marking tests with tags `:epic, :feature, :story`, will group tests accordingly in Behavior report tab:
137
+
138
+ ```ruby
139
+ context "context", feature: "my feature" do
140
+ it "some test case", story: "user story" do
141
+ # test
142
+ end
143
+ end
144
+
145
+ context "context 2", feature: "my feature" do
146
+ it "some test case 2", story: "user story" do
147
+ # test
148
+ end
149
+ end
150
+ ```
151
+
134
152
  ### Custom actions
135
153
 
136
154
  Rspec example object has access to [Allure](https://www.rubydoc.info/github/allure-framework/allure-ruby/Allure) helper methods.
@@ -145,6 +163,10 @@ it "some test case" do |e|
145
163
  end
146
164
  ```
147
165
 
166
+ ### Steps
167
+
168
+ [Step annotations](../allure-ruby-commons/README.md#steps)
169
+
148
170
  ### Example project
149
171
 
150
172
  [RSpec Example](https://github.com/allure-examples/allure-rspec-example)
data/lib/allure-rspec.rb CHANGED
@@ -2,8 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "allure-ruby-commons"
5
- require "allure_rspec/config"
6
- require "allure_rspec/formatter"
5
+
6
+ require_rel "allure_rspec/**/*.rb"
7
7
 
8
8
  module AllureRspec
9
9
  class << self
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AllureRspec
4
+ module Utils
5
+ # Strip relative ./ form path
6
+ # @param [String] path
7
+ # @return [String]
8
+ def strip_relative(path)
9
+ path.gsub("./", "")
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,218 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AllureRspec
4
+ # Suite label generator
5
+ #
6
+ class SuiteLabels
7
+ include Utils
8
+
9
+ def initialize(example_group)
10
+ @example_group = example_group
11
+ end
12
+
13
+ # Get test suite labels
14
+ # @return [Array<Allure::Label>]
15
+ def fetch
16
+ parents = example_group.parent_groups.map do |group|
17
+ group.description.empty? ? "Anonymous" : group.description
18
+ end
19
+
20
+ labels = []
21
+ labels << Allure::ResultUtils.suite_label(suite(parents))
22
+ labels << Allure::ResultUtils.parent_suite_label(parent_suite(parents)) if parent_suite(parents)
23
+ labels << Allure::ResultUtils.sub_suite_label(sub_suites(parents)) if sub_suites(parents)
24
+
25
+ labels
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :example_group
31
+
32
+ # @param [Array<String>] parents
33
+ # @return [String]
34
+ def suite(parents)
35
+ parents.length == 1 ? parents.last : parents[-2]
36
+ end
37
+
38
+ # @param [Array<String>] parents
39
+ # @return [String]
40
+ def parent_suite(parents)
41
+ parents.length > 1 ? parents.last : nil
42
+ end
43
+
44
+ # @param [Array<String>] parents
45
+ # @return [String]
46
+ def sub_suites(parents)
47
+ parents.length > 2 ? parents[0..-3].join(" > ") : nil
48
+ end
49
+ end
50
+
51
+ # RSpec metadata parser
52
+ #
53
+ class RspecMetadataParser
54
+ include Utils
55
+
56
+ RSPEC_IGNORED_METADATA = %i[
57
+ absolute_file_path
58
+ block
59
+ described_class
60
+ description
61
+ description_args
62
+ example_group
63
+ execution_result
64
+ file_path
65
+ full_description
66
+ last_run_status
67
+ line_number
68
+ location
69
+ rerun_file_path
70
+ retry
71
+ retry_attempts
72
+ retry_exceptions
73
+ scoped_id
74
+ shared_group_inclusion_backtrace
75
+ type
76
+ ].freeze
77
+
78
+ def initialize(example)
79
+ @example = example
80
+ end
81
+
82
+ # Get allure labels
83
+ # @return [Array<Allure::Label>]
84
+ def labels
85
+ [
86
+ framework_label,
87
+ package_label,
88
+ test_class_label,
89
+ severity,
90
+ *tag_labels,
91
+ *behavior_labels,
92
+ *suite_labels
93
+ ].select(&:value)
94
+ end
95
+
96
+ # Get attachable links
97
+ # @return [Array<Allure::Link>]
98
+ def links
99
+ matching_links(:tms) + matching_links(:issue)
100
+ end
101
+
102
+ # Get status details
103
+ # @return [Allure::StatusDetails]
104
+ def status_details
105
+ Allure::StatusDetails.new(
106
+ flaky: !metadata[:flaky].nil?,
107
+ muted: !metadata[:muted].nil?,
108
+ known: !metadata[:known].nil?
109
+ )
110
+ end
111
+
112
+ private
113
+
114
+ # @param [RSpec::Core::Example] example
115
+ attr_reader :example
116
+
117
+ # Example metadata
118
+ #
119
+ # @return [Hash]
120
+ def metadata
121
+ @metadata ||= example.metadata
122
+ end
123
+
124
+ # Get package label
125
+ # @return [Allure::Label]
126
+ def package_label
127
+ Allure::ResultUtils.package_label(Pathname.new(strip_relative(example.file_path)).parent.to_s)
128
+ end
129
+
130
+ # Get test class label
131
+ #
132
+ # @return [Allure::Label]
133
+ def test_class_label
134
+ Allure::ResultUtils.test_class_label(File.basename(example.file_path, ".rb"))
135
+ end
136
+
137
+ # Get framework label
138
+ # @return [Allure::Label]
139
+ def framework_label
140
+ Allure::ResultUtils.framework_label("rspec")
141
+ end
142
+
143
+ # Get severity
144
+ # @return [String]
145
+ def severity
146
+ Allure::ResultUtils.severity_label(metadata[:severity] || "normal")
147
+ end
148
+
149
+ # Get test suite labels
150
+ # @return [Array<Allure::Label>]
151
+ def suite_labels
152
+ SuiteLabels.new(example.example_group).fetch
153
+ end
154
+
155
+ # Get custom labels
156
+ # @return [Array<Allure::Label>]
157
+ def tag_labels
158
+ metadata
159
+ .reject { |k| RSPEC_IGNORED_METADATA.include?(k) || special_metadata_tag?(k) }
160
+ .map { |k, v| allure?(k) ? Allure::ResultUtils.tag_label(v) : Allure::ResultUtils.tag_label(k.to_s) }
161
+ end
162
+
163
+ # Get behavior labels
164
+ # @return [Array<Allure::Label>]
165
+ def behavior_labels
166
+ metadata = example.metadata
167
+ epic = metadata[:epic] || Pathname.new(strip_relative(example.file_path)).parent.to_s
168
+ feature = metadata[:feature] || example.example_group.description
169
+ story = metadata[:story]
170
+
171
+ [
172
+ Allure::ResultUtils.epic_label(epic),
173
+ Allure::ResultUtils.feature_label(feature),
174
+ Allure::ResultUtils.story_label(story)
175
+ ]
176
+ end
177
+
178
+ # tms and issue links
179
+ # @param [Symbol] type
180
+ # @return [Array<Allure::Link>]
181
+ def matching_links(type)
182
+ return [] unless AllureRspec.configuration.public_send("link_#{type}_pattern")
183
+
184
+ metadata
185
+ .select { |k| __send__("#{type}?", k) }.values
186
+ .map { |v| Allure::ResultUtils.public_send("#{type}_link", v) }
187
+ end
188
+
189
+ # Special allure metadata tags
190
+ #
191
+ # @param [Symbol] key
192
+ # @return [boolean]
193
+ def special_metadata_tag?(key)
194
+ tms?(key) || issue?(key) || %i[severity epic feature story].include?(key)
195
+ end
196
+
197
+ # Does key match custom allure label
198
+ # @param [Symbol] key
199
+ # @return [boolean]
200
+ def allure?(key)
201
+ key.to_s.match?(/allure(_\d+)?/i)
202
+ end
203
+
204
+ # Does key match tms pattern
205
+ # @param [Symbol] key
206
+ # @return [boolean]
207
+ def tms?(key)
208
+ key.to_s.match?(/tms(_\d+)?/i)
209
+ end
210
+
211
+ # Does key match issue pattern
212
+ # @param [Symbol] key
213
+ # @return [boolean]
214
+ def issue?(key)
215
+ key.to_s.match?(/issue(_\d+)?/i)
216
+ end
217
+ end
218
+ end
@@ -3,12 +3,10 @@
3
3
  require "digest"
4
4
  require "pathname"
5
5
 
6
- require_relative "tag_parser"
7
-
8
6
  module AllureRspec
9
7
  # Support class for transforming rspec test entities in to allure model entities
10
8
  module AllureRspecModel
11
- include TagParser
9
+ include AllureRspec::Utils
12
10
 
13
11
  # @return [Hash] allure statuses mapping
14
12
  ALLURE_STATUS = {
@@ -21,15 +19,17 @@ module AllureRspec
21
19
  # @param [RSpec::Core::Example] example
22
20
  # @return [Allure::TestResult]
23
21
  def test_result(example)
22
+ parser = RspecMetadataParser.new(example)
23
+
24
24
  Allure::TestResult.new(
25
25
  name: example.description,
26
26
  description: "Location - #{strip_relative(example.location)}",
27
27
  description_html: "Location - #{strip_relative(example.location)}",
28
28
  history_id: Digest::MD5.hexdigest(example.id),
29
29
  full_name: example.full_description,
30
- labels: labels(example),
31
- links: links(example),
32
- status_details: Allure::StatusDetails.new(**status_detail_tags(example.metadata))
30
+ labels: parser.labels,
31
+ links: parser.links,
32
+ status_details: parser.status_details
33
33
  )
34
34
  end
35
35
 
@@ -49,12 +49,6 @@ module AllureRspec
49
49
 
50
50
  private
51
51
 
52
- # @param [RSpec::Core::Example] example
53
- # @return [Array<Allure::Label>]
54
- def links(example)
55
- tms_links(example.metadata) + issue_links(example.metadata)
56
- end
57
-
58
52
  # Get allure status from result
59
53
  # @param [RSpec::Core::Example::ExecutionResult] result
60
54
  # @return [Symbol]
@@ -63,59 +57,5 @@ module AllureRspec
63
57
 
64
58
  ALLURE_STATUS[result.status]
65
59
  end
66
-
67
- # @param [RSpec::Core::Example] example
68
- # @return [Array<Allure::Label>]
69
- def labels(example)
70
- labels = []
71
- labels << Allure::ResultUtils.framework_label("rspec")
72
- labels << Allure::ResultUtils.feature_label(example.example_group.description)
73
- labels << Allure::ResultUtils.package_label(Pathname.new(strip_relative(example.file_path)).parent.to_s)
74
- labels << Allure::ResultUtils.story_label(example.description)
75
- labels << Allure::ResultUtils.test_class_label(File.basename(example.file_path, ".rb"))
76
- labels << severity(example.metadata)
77
- labels.push(*tag_labels(example.metadata))
78
- labels.push(*suite_labels(example.example_group))
79
-
80
- labels
81
- end
82
-
83
- # Add suite labels
84
- # @param [RSpec::Core::ExampleGroup] example_group
85
- # @return [Array<Allure::Label>]
86
- def suite_labels(example_group)
87
- parents = example_group.parent_groups.map { |group| group.description.empty? ? "Anonymous" : group.description }
88
- labels = []
89
- labels << Allure::ResultUtils.suite_label(suite(parents))
90
- labels << Allure::ResultUtils.parent_suite_label(parent_suite(parents)) if parent_suite(parents)
91
- labels << Allure::ResultUtils.sub_suite_label(sub_suites(parents)) if sub_suites(parents)
92
-
93
- labels
94
- end
95
-
96
- # @param [Array<String>] parents
97
- # @return [String]
98
- def suite(parents)
99
- parents.length == 1 ? parents.last : parents[-2]
100
- end
101
-
102
- # @param [Array<String>] parents
103
- # @return [String]
104
- def parent_suite(parents)
105
- parents.length > 1 ? parents.last : nil
106
- end
107
-
108
- # @param [Array<String>] parents
109
- # @return [String]
110
- def sub_suites(parents)
111
- parents.length > 2 ? parents[0..-3].join(" > ") : nil
112
- end
113
-
114
- # Strip relative ./ form path
115
- # @param [String] path
116
- # @return [String]
117
- def strip_relative(path)
118
- path.gsub("./", "")
119
- end
120
60
  end
121
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: allure-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.8.1
4
+ version: 2.13.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrejs Cunskis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-14 00:00:00.000000000 Z
11
+ date: 2021-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: allure-ruby-commons
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.13.8.1
19
+ version: 2.13.9
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.13.8.1
26
+ version: 2.13.9
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec-core
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,10 +66,11 @@ extra_rdoc_files: []
66
66
  files:
67
67
  - README.md
68
68
  - lib/allure-rspec.rb
69
+ - lib/allure_rspec/01_utils.rb
69
70
  - lib/allure_rspec/config.rb
70
71
  - lib/allure_rspec/formatter.rb
72
+ - lib/allure_rspec/metadata_parser.rb
71
73
  - lib/allure_rspec/rspec_model.rb
72
- - lib/allure_rspec/tag_parser.rb
73
74
  homepage: https://github.com/allure-framework/allure-ruby/tree/master/allure-rspec
74
75
  licenses:
75
76
  - Apache-2.0
@@ -94,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  - !ruby/object:Gem::Version
95
96
  version: '0'
96
97
  requirements: []
97
- rubygems_version: 3.2.3
98
+ rubygems_version: 3.2.15
98
99
  signing_key:
99
100
  specification_version: 4
100
101
  summary: Allure rspec ruby adaptor
@@ -1,84 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module AllureRspec
4
- # RSpec custom tag parser
5
- module TagParser
6
- # Get custom labels
7
- # @param [Hash] metadata
8
- # @return [Array<Allure::Label>]
9
- def tag_labels(metadata)
10
- return [] unless metadata.keys.any? { |k| allure?(k) }
11
-
12
- metadata.select { |k| allure?(k) }.values.map { |v| Allure::ResultUtils.tag_label(v) }
13
- end
14
-
15
- # Get tms links
16
- # @param [Hash] metadata
17
- # @return [Array<Allure::Link>]
18
- def tms_links(metadata)
19
- matching_links(metadata, :tms)
20
- end
21
-
22
- # Get issue links
23
- # @param [Hash] metadata
24
- # @return [Array<Allure::Link>]
25
- def issue_links(metadata)
26
- matching_links(metadata, :issue)
27
- end
28
-
29
- # Get severity
30
- # @param [Hash] metadata
31
- # @return [String]
32
- def severity(metadata)
33
- Allure::ResultUtils.severity_label(metadata[:severity] || "normal")
34
- end
35
-
36
- # Get status details
37
- # @param [Hash] metadata
38
- # @return [Hash<Symbol, Boolean>]
39
- def status_detail_tags(metadata)
40
- {
41
- flaky: !metadata[:flaky].nil?,
42
- muted: !metadata[:muted].nil?,
43
- known: !metadata[:known].nil?
44
- }
45
- end
46
-
47
- private
48
-
49
- # @param [Hash] metadata
50
- # @param [Symbol] type
51
- # @return [Array<Allure::Link>]
52
- def matching_links(metadata, type)
53
- unless AllureRspec.configuration.public_send("link_#{type}_pattern") &&
54
- metadata.keys.any? { |k| __send__("#{type}?", k) }
55
- return []
56
- end
57
-
58
- metadata
59
- .select { |k| __send__("#{type}?", k) }.values
60
- .map { |v| Allure::ResultUtils.public_send("#{type}_link", v) }
61
- end
62
-
63
- # Does key match custom allure label
64
- # @param [Symbol] key
65
- # @return [boolean]
66
- def allure?(key)
67
- key.to_s.match?(/allure(_\d+)?/i)
68
- end
69
-
70
- # Does key match tms pattern
71
- # @param [Symbol] key
72
- # @return [boolean]
73
- def tms?(key)
74
- key.to_s.match?(/tms(_\d+)?/i)
75
- end
76
-
77
- # Does key match issue pattern
78
- # @param [Symbol] key
79
- # @return [boolean]
80
- def issue?(key)
81
- key.to_s.match?(/issue(_\d+)?/i)
82
- end
83
- end
84
- end