allure-rspec 2.13.8.3 → 2.13.8.4

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: 64cc3df4ca4fdc6d5c03ffd350636fdd1adf1d1b380adf676729baedf20cd558
4
- data.tar.gz: 43b4c2d026e4d73ccd13c3389ac1094d9f87aa49b7daf3861b7b6c5ee275dacd
3
+ metadata.gz: d01ab27cd9cc6ad5c060178bd137332f40c5c13627f2f7e5ca05d64b56ccf8dd
4
+ data.tar.gz: 98779dfe52f3359c2c99a8c28283b8572b078522a68a1a221cc660a179e7297b
5
5
  SHA512:
6
- metadata.gz: 5bf9d35a82ab0f3a36d1bd134489ac02e16660d584fd42e076966de82e8ae7e6c2546024eee7851155f6cd06fc02ef4db93b828dcac2abd27b4dc9c2124175dc
7
- data.tar.gz: ffcc4cc2d5907e2fee29de24648f39fdc8414b3f816a7ce0eb27a21786f241e60d4345b29f2f29a2d1a7f5213756dba948776d938d638528ae1f8cdae86dde5f
6
+ metadata.gz: 4ee00f85efe8744c61be183eac83be011d38f59d17600373e3e4e5d561939c95c3ae5e680c202bdb8d1cf9a347e5ea527a9b553cadfa2cf1c3084f5143870180
7
+ data.tar.gz: 2f274e54aea447b7aff6f2b5d3d457f1f6334f59afcf737de101d407dda1ec2c87eba89f1c9445b67d288715d40ddea22d8e4310c62b77c852cfdabb0ff7f106
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 `:story, :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.
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
+ ]
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] || example.description
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.3
4
+ version: 2.13.8.4
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-19 00:00:00.000000000 Z
11
+ date: 2021-02-27 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.3
19
+ version: 2.13.8.4
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.3
26
+ version: 2.13.8.4
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
@@ -1,106 +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
- metadata.reject { |k| RSPEC_IGNORED_METADATA.include?(k) }.map do |k, v|
11
- allure?(k) ? Allure::ResultUtils.tag_label(v) : Allure::ResultUtils.tag_label(k.to_s)
12
- end
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
- RSPEC_IGNORED_METADATA = %i[
50
- absolute_file_path
51
- block
52
- described_class
53
- description
54
- description_args
55
- example_group
56
- execution_result
57
- file_path
58
- full_description
59
- last_run_status
60
- line_number
61
- location
62
- rerun_file_path
63
- retry
64
- retry_attempts
65
- retry_exceptions
66
- scoped_id
67
- shared_group_inclusion_backtrace
68
- type
69
- ].freeze
70
-
71
- # @param [Hash] metadata
72
- # @param [Symbol] type
73
- # @return [Array<Allure::Link>]
74
- def matching_links(metadata, type)
75
- unless AllureRspec.configuration.public_send("link_#{type}_pattern") &&
76
- metadata.keys.any? { |k| __send__("#{type}?", k) }
77
- return []
78
- end
79
-
80
- metadata
81
- .select { |k| __send__("#{type}?", k) }.values
82
- .map { |v| Allure::ResultUtils.public_send("#{type}_link", v) }
83
- end
84
-
85
- # Does key match custom allure label
86
- # @param [Symbol] key
87
- # @return [boolean]
88
- def allure?(key)
89
- key.to_s.match?(/allure(_\d+)?/i)
90
- end
91
-
92
- # Does key match tms pattern
93
- # @param [Symbol] key
94
- # @return [boolean]
95
- def tms?(key)
96
- key.to_s.match?(/tms(_\d+)?/i)
97
- end
98
-
99
- # Does key match issue pattern
100
- # @param [Symbol] key
101
- # @return [boolean]
102
- def issue?(key)
103
- key.to_s.match?(/issue(_\d+)?/i)
104
- end
105
- end
106
- end