allure-rspec 0.8.0 → 2.15.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
- SHA1:
3
- metadata.gz: 6f7cae6b08f0509c5b7830ccf1108034c9becd88
4
- data.tar.gz: 19b250c168c6db5d4d1f27878cee086b4748592c
2
+ SHA256:
3
+ metadata.gz: 3e6c5bb377f6a90b6ef4d6927421c61f6a273d160fbf6ff571e34fc8826cc62a
4
+ data.tar.gz: b32ba8c7ab41c07aa02a6ff0d4f4285ef1bbaffd37a15857176ac651cb333138
5
5
  SHA512:
6
- metadata.gz: f8f472e50e1b2c4e5e399f6bcbfe773b2ab47fea722436447794a67a12c7d54616799fa39bcc07c097df239221d34291d55b694fceef6c9ab12151fe3180eb2b
7
- data.tar.gz: f45f2993559ee15598f2a3111ee80ecdd4c585bf7702c0e5cf645d348ea231932c6978abc82de78a34e456529ca7316a6a827392b71b1274bd93d08535d4943f
6
+ metadata.gz: a37fcab764248deb65cfff370cb92d4b3bc16c7cbda92487faf593aca77e62401f1aa094df659e1c1c075333ab982709e53c26f343b12fb7b9244bb41eda69b5
7
+ data.tar.gz: 1fd4ffd1c21d2a575a2bdd9925e71f08c18bed8ab7668558456ac754c0e5e22b7e6ffac5bbfb9b5f2eb93570d7de1117d886fd9f3d90b940650c70d611d65107
data/README.md CHANGED
@@ -1,74 +1,224 @@
1
- # Allure RSpec Adaptor
1
+ # allure-rspec
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/allure-rspec.svg)](http://badge.fury.io/rb/allure-rspec)
3
+ [![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://www.rubydoc.info/gems/allure-rspec)
4
4
 
5
- Adaptor to use the Allure framework along with the RSpec. See [an example](https://github.com/allure-examples/allure-rspec-example) project to take a quick tour.
5
+ Allure adapter for [rspec](https://rspec.info/) testing framework
6
6
 
7
- ## What's new
7
+ ## Installation
8
8
 
9
- See the [releases](https://github.com/allure-framework/allure-rspec/releases) tab.
9
+ Add it to gemfile:
10
10
 
11
+ ```ruby
12
+ gem "allure-rspec"
13
+ ```
14
+
15
+ Require in `spec_helper` or any other setup file:
16
+
17
+ ```ruby
18
+ require "allure-rspec"
19
+ ```
11
20
 
12
- ## Setup
21
+ ## Configuration
13
22
 
14
- Add the dependency to your Gemfile. Choose the version carefully:
15
- * 0.5.x - for RSpec2.
16
- * <= 0.6.7 - for RSpec < 3.2.
17
- * >= 0.6.9 - for RSpec >= 3.2.
23
+ Following configuration options are supported:
18
24
 
19
25
  ```ruby
20
- gem 'allure-rspec'
26
+ AllureRspec.configure do |config|
27
+ config.results_directory = "report/allure-results"
28
+ config.clean_results_directory = true
29
+ config.logging_level = Logger::INFO
30
+ config.logger = Logger.new($stdout, Logger::DEBUG)
31
+ config.environment = "staging"
32
+
33
+ # these are used for creating links to bugs or test cases where {} is replaced with keys of relevant items
34
+ config.link_tms_pattern = "http://www.jira.com/browse/{}"
35
+ config.link_issue_pattern = "http://www.jira.com/browse/{}"
36
+
37
+ # additional metadata
38
+ # environment.properties
39
+ config.environment_properties = {
40
+ custom_attribute: "foo"
41
+ }
42
+ # categories.json
43
+ config.categories = File.new("my_custom_categories.json")
44
+ end
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ Via commandline arguments, simply add:
50
+
51
+ ```bash
52
+ --format AllureRspecFormatter
21
53
  ```
22
54
 
23
- And then include it in your spec_helper.rb:
55
+ or
56
+
57
+ Via RSpec configuration:
24
58
 
25
59
  ```ruby
26
- RSpec.configure do |c|
27
- c.include AllureRSpec::Adaptor
28
- end
60
+ RSpec.configure do |config|
61
+ config.formatter = AllureRspecFormatter
62
+ end
29
63
  ```
30
64
 
31
- ## Advanced options
65
+ ### Adding tms links
32
66
 
33
- You can specify the directory where the Allure test results will appear. By default it would be 'gen/allure-results'
34
- within your current directory.
67
+ Configure tms link pattern and rspec tag:
35
68
 
36
69
  ```ruby
37
- AllureRSpec.configure do |c|
38
- c.output_dir = "/whatever/you/like" # default: gen/allure-results
39
- c.clean_dir = false # clean the output directory first? (default: true)
40
- c.logging_level = Logger::DEBUG # logging level (default: DEBUG)
41
- end
70
+ AllureRspec.configure do |config|
71
+ config.link_tms_pattern = "http://www.jira.com/browse/{}"
72
+ config.tms_tag = :tms
73
+ end
42
74
  ```
43
75
 
44
- ## Usage examples
76
+ Add tag to rspec test:
45
77
 
46
78
  ```ruby
47
- describe MySpec, :feature => "Some feature", :severity => :normal do
79
+ it "some test case", tms: "QA-123" do
80
+ # test
81
+ end
82
+ ```
48
83
 
49
- before(:step) do |s|
50
- puts "Before step #{s.current_step}"
51
- end
84
+ It's possible to add multiple tms links using `tms_` pattern:
52
85
 
53
- it "should be critical", :story => "First story", :severity => :critical, :testId => 99 do
54
- "string".should == "string"
55
- end
86
+ ```ruby
87
+ it "some test case", tms_1: "QA-123", tms_2: "QA-124" do
88
+ # test
89
+ end
90
+ ```
56
91
 
57
- it "should be steps enabled", :story => ["First story", "Second story"], :testId => 31 do |e|
92
+ ### Adding issue links
58
93
 
59
- e.step "step1" do |s|
60
- s.attach_file "screenshot1", take_screenshot_as_file
61
- end
94
+ Configure issue link pattern:
62
95
 
63
- e.step "step2" do
64
- 5.should be > 0
65
- end
96
+ ```ruby
97
+ AllureRspec.configure do |config|
98
+ config.link_issue_pattern = "http://www.jira.com/browse/{}"
99
+ config.issue_tag = :issue
100
+ end
101
+ ```
102
+
103
+ Add tag to rspec test:
104
+
105
+ ```ruby
106
+ it "some test case", issue: "QA-123" do
107
+ # test
108
+ end
109
+ ```
110
+
111
+ It's possible to add multiple tms links using `issue_` pattern:
112
+
113
+ ```ruby
114
+ it "some test case", issue_1: "QA-123", issue_2: "QA-124" do
115
+ # test
116
+ end
117
+ ```
118
+
119
+ ### Adding custom severity and status details
120
+
121
+ Configure severity tag:
122
+
123
+ ```ruby
124
+ AllureRspec.configure do |config|
125
+ config.severity_tag = :severity
126
+ end
127
+ ```
128
+
129
+ Test severity is set to `normal` by default:
130
+
131
+ ```ruby
132
+ it "some test case", severity: :critical do
133
+ # test
134
+ end
135
+ ```
66
136
 
67
- e.step "step3" do
68
- 0.should == 0
69
- end
137
+ Custom status details can be set via `muted`, `known`, `flaky` tags:
70
138
 
71
- e.attach_file "screenshot2", take_screenshot_as_file
139
+ ```ruby
140
+ it "some test case", flaky: true, muted: false, known: true do
141
+ # test
142
+ end
143
+ ```
144
+
145
+ ### Adding additional labels to allure test case
146
+
147
+ Additional labels can be added using `allure_` pattern:
148
+
149
+ ```ruby
150
+ it "some test case", allure_1: "visual_test", allure_2: "core_functionality" do
151
+ # test
152
+ end
153
+ ```
154
+
155
+ All other metadata tags are also automatically added as labels:
156
+
157
+ ```ruby
158
+ it "some test case", :visual_test, :core_functionality do
159
+ # test
160
+ end
161
+ ```
162
+
163
+ #### Skipping certain tags
164
+
165
+ To skip adding certain tags as labels, following configuration can be added:
166
+
167
+ ```ruby
168
+ AllureRspec.configure do |config|
169
+ config.ignored_tags = [:core_functionality, :generic_metadata_to_ignore]
170
+ end
171
+ ```
172
+
173
+ ### Behavior driven test grouping
174
+
175
+ Marking tests with tags `:epic, :feature, :story`, will group tests accordingly in Behavior report tab.\
176
+ Tag values can also be configured:
177
+
178
+ ```ruby
179
+ AllureRspec.configure do |config|
180
+ config.epic_tag = :epic
181
+ config.feature_tag = :feature
182
+ config.story_tag = :story
183
+ end
184
+ ```
185
+
186
+ ```ruby
187
+ context "context", feature: "my feature" do
188
+ it "some test case", story: "user story" do
189
+ # test
190
+ end
191
+ end
192
+
193
+ context "context 2", feature: "my feature" do
194
+ it "some test case 2", story: "user story" do
195
+ # test
196
+ end
197
+ end
198
+ ```
199
+
200
+ ### Custom actions
201
+
202
+ Rspec example object has access to [Allure](https://www.rubydoc.info/github/allure-framework/allure-ruby/Allure) helper methods.
203
+ It can be used to add or run steps, add attachments, modify test case etc.
204
+
205
+ ```ruby
206
+ it "some test case" do |e|
207
+ e.run_step("my custom step") do
208
+ # some action
72
209
  end
210
+ e.add_attachment(name: "attachment", source: "Some string", type: Allure::ContentType::TXT)
73
211
  end
74
212
  ```
213
+
214
+ ### Steps
215
+
216
+ [Step annotations](../allure-ruby-commons/README.md#steps)
217
+
218
+ ### Example project
219
+
220
+ [RSpec Example](https://github.com/allure-examples/allure-rspec-example)
221
+
222
+ ## HTML report generation
223
+
224
+ Report is generated using allure commandline tool. [Allure wiki](https://docs.qameta.io/allure/#_reporting).
data/lib/allure-rspec.rb CHANGED
@@ -1,56 +1,28 @@
1
- require 'allure-ruby-adaptor-api'
2
- require 'allure-rspec/version'
3
- require 'allure-rspec/formatter'
4
- require 'allure-rspec/adaptor'
5
- require 'allure-rspec/dsl'
6
- require 'allure-rspec/hooks'
1
+ # rubocop:disable Naming/FileName
2
+ # frozen_string_literal: true
7
3
 
8
- module AllureRSpec
9
- module Config
10
- class << self
11
- attr_accessor :output_dir
12
- attr_accessor :clean_dir
13
- attr_accessor :logging_level
4
+ require "allure-ruby-commons"
14
5
 
15
- DEFAULT_OUTPUT_DIR = 'gen/allure-results'
16
- DEFAULT_LOGGING_LEVEL = Logger::DEBUG
17
-
18
- def output_dir
19
- @output_dir || DEFAULT_OUTPUT_DIR
20
- end
21
-
22
- def clean_dir?
23
- @clean_dir.nil? ? true : @clean_dir
24
- end
25
-
26
- def logging_level
27
- @logging_level || DEFAULT_LOGGING_LEVEL
28
- end
29
- end
30
- end
31
-
32
- class Context
33
- attr_accessor :rspec
34
-
35
- def rspec
36
- @rspec
37
- end
38
- end
6
+ require_rel "allure_rspec/**/*.rb"
39
7
 
8
+ module AllureRspec
40
9
  class << self
41
- def context
42
- @context ||= Context.new
10
+ # Get allure cucumber configuration
11
+ # @return [AllureRspec::RspecConfig]
12
+ def configuration
13
+ RspecConfig.instance
43
14
  end
44
- end
45
15
 
46
- class << self
47
- def configure(&block)
48
- yield Config
49
- AllureRubyAdaptorApi.configure { |c|
50
- c.output_dir = Config.output_dir
51
- c.logging_level = Config.logging_level
52
- }
16
+ # Set allure configuration
17
+ # @yieldparam [AllureRspec::RspecConfig]
18
+ # @yieldreturn [void]
19
+ # @return [void]
20
+ def configure
21
+ yield(configuration)
53
22
  end
54
23
  end
55
-
56
24
  end
25
+
26
+ # Rspec formatter class shorthand
27
+ AllureRspecFormatter = AllureRspec::RSpecFormatter
28
+ # rubocop:enable Naming/FileName
@@ -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,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "singleton"
4
+
5
+ module AllureRspec
6
+ # Allure RSpec configuration class
7
+ #
8
+ # @!attribute results_directory
9
+ # @return [String]
10
+ # @!attribute clean_results_directory
11
+ # @return [Boolean]
12
+ # @!attribute link_issue_pattern
13
+ # @return [String]
14
+ # @!attribute link_tms_pattern
15
+ # @return [String]
16
+ # @!attribute logging_level
17
+ # @return [Integer]
18
+ # @!attribute [r] logger
19
+ # @return [Logger]
20
+ # @!attribute environment
21
+ # @return [String]
22
+ class RspecConfig
23
+ include Singleton
24
+ extend Forwardable
25
+
26
+ # @return [Symbol] default tms tag
27
+ DEFAULT_TMS_TAG = :tms
28
+ # @return [Symbol] default issue tag
29
+ DEFAULT_ISSUE_TAG = :issue
30
+ # @return [Symbol] default severity tag
31
+ DEFAULT_SEVERITY_TAG = :severity
32
+ # @return [Symbol] default epic tag
33
+ DEFAULT_EPIC_TAG = :epic
34
+ # @return [Symbol] default feature tag
35
+ DEFAULT_FEATURE_TAG = :feature
36
+ # @return [Symbol] default story tag
37
+ DEFAULT_STORY_TAG = :story
38
+
39
+ def_delegators :@allure_config,
40
+ :clean_results_directory,
41
+ :clean_results_directory=,
42
+ :link_issue_pattern,
43
+ :link_issue_pattern=,
44
+ :link_tms_pattern,
45
+ :link_tms_pattern=,
46
+ :logging_level,
47
+ :logging_level=,
48
+ :logger,
49
+ :logger=,
50
+ :results_directory,
51
+ :results_directory=,
52
+ :environment,
53
+ :environment=,
54
+ :environment_properties,
55
+ :environment_properties=,
56
+ :categories,
57
+ :categories=
58
+
59
+ def initialize
60
+ @allure_config = Allure.configuration
61
+ end
62
+
63
+ attr_writer :tms_tag,
64
+ :issue_tag,
65
+ :severity_tag,
66
+ :epic_tag,
67
+ :feature_tag,
68
+ :story_tag,
69
+ :ignored_tags
70
+
71
+ # @return [Symbol]
72
+ def tms_tag
73
+ @tms_tag || DEFAULT_TMS_TAG
74
+ end
75
+
76
+ # @return [Symbol]
77
+ def issue_tag
78
+ @issue_tag || DEFAULT_ISSUE_TAG
79
+ end
80
+
81
+ # @return [Symbol]
82
+ def severity_tag
83
+ @severity_tag || DEFAULT_SEVERITY_TAG
84
+ end
85
+
86
+ # @return [Symbol]
87
+ def epic_tag
88
+ @epic_tag || DEFAULT_EPIC_TAG
89
+ end
90
+
91
+ # @return [Symbol]
92
+ def feature_tag
93
+ @feature_tag || DEFAULT_FEATURE_TAG
94
+ end
95
+
96
+ # @return [Symbol]
97
+ def story_tag
98
+ @story_tag || DEFAULT_STORY_TAG
99
+ end
100
+
101
+ # @return [Array]
102
+ def ignored_tags
103
+ @ignored_tags || []
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,141 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspec/core"
4
+ require "rspec/core/formatters/base_formatter"
5
+
6
+ # Main allure-rspec module
7
+ module AllureRspec
8
+ # Main rspec formatter class translating rspec events to allure lifecycle
9
+ class RSpecFormatter < RSpec::Core::Formatters::BaseFormatter
10
+ include Utils
11
+
12
+ # @return [Hash] allure statuses mapping
13
+ ALLURE_STATUS = {
14
+ failed: Allure::Status::FAILED,
15
+ pending: Allure::Status::SKIPPED,
16
+ passed: Allure::Status::PASSED
17
+ }.freeze
18
+
19
+ RSpec::Core::Formatters.register(
20
+ self,
21
+ :start,
22
+ :stop,
23
+ :example_group_started,
24
+ :example_group_finished,
25
+ :example_started,
26
+ :example_finished
27
+ )
28
+
29
+ RSpec.configure do |config|
30
+ ids = Allure::TestPlan.test_ids
31
+ names = Allure::TestPlan.test_names
32
+
33
+ config.filter_run_when_matching(*ids.map { |id| { allure_id: id } }) if ids
34
+ config.full_description = names if names
35
+ end
36
+
37
+ def initialize(output)
38
+ super
39
+
40
+ @allure_config = AllureRspec.configuration
41
+ Allure.lifecycle = @lifecycle = Allure::AllureLifecycle.new(@allure_config)
42
+ end
43
+
44
+ # Start test run
45
+ # @param [RSpec::Core::Notifications::StartNotification] _start_notification
46
+ # @return [void]
47
+ def start(_start_notification)
48
+ lifecycle.clean_results_dir
49
+ lifecycle.write_categories
50
+
51
+ RSpec::Core::Example.class_eval do
52
+ include Allure
53
+ end
54
+ end
55
+
56
+ # Start test run
57
+ # @param [RSpec::Core::Notifications::StopNotification] _stop_notification
58
+ # @return [void]
59
+ def stop(_stop_notification)
60
+ lifecycle.write_environment
61
+ end
62
+
63
+ # Starts example group
64
+ # @param [RSpec::Core::Notifications::GroupNotification] example_group_notification
65
+ # @return [void]
66
+ def example_group_started(example_group_notification)
67
+ description = example_group_notification.group.description.yield_self do |desc|
68
+ desc.empty? ? "Anonymous" : desc
69
+ end
70
+ lifecycle.start_test_container(Allure::TestResultContainer.new(name: description))
71
+ end
72
+
73
+ # Starts example
74
+ # @param [RSpec::Core::Notifications::ExampleNotification] example_notification
75
+ # @return [void]
76
+ def example_started(example_notification)
77
+ lifecycle.start_test_case(test_result(example_notification.example))
78
+ end
79
+
80
+ # Finishes example
81
+ # @param [RSpec::Core::Notifications::ExampleNotification] example_notification
82
+ # @return [void]
83
+ def example_finished(example_notification)
84
+ lifecycle.update_test_case(&update_test_proc(example_notification.example.execution_result))
85
+ lifecycle.stop_test_case
86
+ end
87
+
88
+ # Starts example group
89
+ # @param [RSpec::Core::Notifications::GroupNotification] _example_group_notification
90
+ # @return [void]
91
+ def example_group_finished(_example_group_notification)
92
+ lifecycle.stop_test_container
93
+ end
94
+
95
+ private
96
+
97
+ attr_reader :lifecycle, :allure_config
98
+
99
+ # Transform example to <Allure::TestResult>
100
+ # @param [RSpec::Core::Example] example
101
+ # @return [Allure::TestResult]
102
+ def test_result(example)
103
+ parser = RspecMetadataParser.new(example, allure_config)
104
+
105
+ Allure::TestResult.new(
106
+ name: example.description,
107
+ description: "Location - #{strip_relative(example.location)}",
108
+ description_html: "Location - #{strip_relative(example.location)}",
109
+ history_id: example.id,
110
+ full_name: example.full_description,
111
+ labels: parser.labels,
112
+ links: parser.links,
113
+ status_details: parser.status_details,
114
+ environment: allure_config.environment
115
+ )
116
+ end
117
+
118
+ # Update test status on finish
119
+ # @param [RSpec::Core::Example::ExecutionResult] result
120
+ # @return [Proc]
121
+ def update_test_proc(result)
122
+ Allure::ResultUtils.status_details(result.exception).yield_self do |status_detail|
123
+ proc do |test_case|
124
+ test_case.stage = Allure::Stage::FINISHED
125
+ test_case.status = status(result)
126
+ test_case.status_details.message = status_detail.message
127
+ test_case.status_details.trace = status_detail.trace
128
+ end
129
+ end
130
+ end
131
+
132
+ # Get allure status from result
133
+ # @param [RSpec::Core::Example::ExecutionResult] result
134
+ # @return [Symbol]
135
+ def status(result)
136
+ return Allure::ResultUtils.status(result.exception) if result.status == :failed
137
+
138
+ ALLURE_STATUS[result.status]
139
+ end
140
+ end
141
+ end