allure-ruby-commons 2.29.1 → 2.30.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: e3c7cc28f5738388cce1d85afab6a9248c501a09a3bbe2a8a0469f0d23980d05
4
- data.tar.gz: 7a883ae369f1aad7ece45aa735b911b12c4e0fd3c6a7c4beff289b1e25ad0da2
3
+ metadata.gz: 98dba29e4163a15ada4fb2d5097aee68764e97423f7bea00f0ed20b0810d7fd9
4
+ data.tar.gz: 7a6be418174a478614942fff81b7c305efa1b2f8074eb450c94ce8ec40869d07
5
5
  SHA512:
6
- metadata.gz: 855f38ae5530bf583a2dc2aae3ed81c6091d83db3eb79f33c5559b75699e368521daebdeb40af7640bdb54f6b9e5ada3dc26142301c5c4953876b0c57f17413e
7
- data.tar.gz: f44bbb71e3bb02a18e20729e7df33c64340df4e2bbe7c46430dd852003d51794a7ba6f37d376685e3275eb8125af5256e32b728270aa894ac9fe4aaed61df45a
6
+ metadata.gz: c012649c7bd0e48d24630c5f09c3cd58a39a0959ffaf31fc405bd4ba7d3bcde0f0b09eda97093eeb1f98caa24105e3cfa447b968ff2c933331f43c7d963a1b40
7
+ data.tar.gz: fbd9d29cc963268f5809fbb99b1c2e574fbde2760d6180b484a0a22fb47888075d809d818616cc31b33a92598a364b4ebb0fe7ff257cb58439da5aab524a3403
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # Allure Ruby Adaptor API
1
+ # Allure Ruby adapter API
2
2
 
3
3
  [![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://www.rubydoc.info/gems/allure-ruby-commons)
4
4
 
5
- This is a helper library containing the basics for any ruby-based Allure adaptor.
6
- Using it you can easily implement the adaptor for your favorite ruby testing library or
5
+ This is a helper library containing the basics for any ruby-based Allure adapter.
6
+ Using it you can easily implement the adapter for your favorite ruby testing library or
7
7
  you can just create the report of any other kind using the basic Allure terms.
8
8
 
9
9
  ## Setup
@@ -26,6 +26,12 @@ Following configuration options are supported:
26
26
  config.logger = Logger.new($stdout, Logger::DEBUG)
27
27
  config.environment = "staging"
28
28
 
29
+ # labels added to every test result
30
+ config.global_labels = [
31
+ { name: "owner", value: "qa" },
32
+ { name: "tag", value: "global" }
33
+ ]
34
+
29
35
  # these are used for creating links to bugs or test cases where {} is replaced with keys of relevant items
30
36
  config.link_tms_pattern = "http://www.jira.com/browse/{}"
31
37
  config.link_issue_pattern = "http://www.jira.com/browse/{}"
@@ -40,6 +46,9 @@ Following configuration options are supported:
40
46
  end
41
47
  ```
42
48
 
49
+ `global_labels` defaults to `[]`. Each entry is a hash with symbol keys `:name` and `:value`.
50
+ Labels are prepended to every completed test's labels without replacing test-specific labels, including those with the same name.
51
+
43
52
  Getting the configuration object:
44
53
 
45
54
  ```ruby
@@ -7,7 +7,7 @@ require "securerandom"
7
7
 
8
8
  require_rel "allure_ruby_commons/**/*rb"
9
9
 
10
- # Namespace for classes that handle allure report generation and different framework adaptors
10
+ # Namespace for classes that handle allure report generation and different framework adapters
11
11
  module Allure
12
12
  # Set lifecycle object
13
13
  # @param [AllureLifecycle] lifecycle
@@ -14,13 +14,14 @@ module Allure
14
14
  def initialize(config = Config.instance)
15
15
  @test_context = []
16
16
  @step_context = []
17
+ @globals = Globals.new
17
18
  @config = config
18
19
  @logger = config.logger
19
20
  end
20
21
 
21
22
  attr_reader :config
22
23
 
23
- def_delegators :file_writer, :write_attachment, :write_globals
24
+ def_delegators :file_writer, :write_attachment
24
25
 
25
26
  # Start test result container
26
27
  # @param [Allure::TestResultContainer] test_result_container
@@ -102,6 +103,7 @@ module Allure
102
103
  logger.debug { "Stopping test case: #{@current_test_case.name}" }
103
104
  @current_test_case.stop = ResultUtils.timestamp
104
105
  @current_test_case.stage = Stage::FINISHED
106
+ @current_test_case.labels.unshift(*global_labels)
105
107
  file_writer.write_test_result(@current_test_case)
106
108
  clear_current_test_case
107
109
  clear_step_context
@@ -231,7 +233,7 @@ module Allure
231
233
 
232
234
  logger.debug { "Adding global attachment '#{name}'" }
233
235
  write_attachment(source, attachment)
234
- write_globals(Globals.new(attachments: [attachment]))
236
+ @globals.add_attachment(attachment)
235
237
  end
236
238
 
237
239
  # Add run-level error
@@ -246,7 +248,7 @@ module Allure
246
248
  error = ResultUtils.prepare_global_error(timestamp: ResultUtils.timestamp, **details)
247
249
 
248
250
  logger.debug { "Adding global error '#{error.message}'" }
249
- write_globals(Globals.new(errors: [error]))
251
+ @globals.add_error(error)
250
252
  end
251
253
 
252
254
  # Add environment.properties file
@@ -270,6 +272,12 @@ module Allure
270
272
  file_writer.write_categories(categories)
271
273
  end
272
274
 
275
+ # Write global errors and attachments
276
+ # @return [void]
277
+ def write_globals
278
+ file_writer.write_globals(@globals)
279
+ end
280
+
273
281
  # Add step to current fixture|step|test case
274
282
  # @param [Allure::StepResult] step_result
275
283
  # @return [Allure::StepResult]
@@ -289,6 +297,10 @@ module Allure
289
297
 
290
298
  attr_reader :logger
291
299
 
300
+ def global_labels
301
+ @global_labels ||= config.global_labels.map { |label| Label.new(label[:name], label[:value]) }
302
+ end
303
+
292
304
  def file_writer
293
305
  @file_writer ||= FileWriter.new(config.results_directory)
294
306
  end
@@ -20,10 +20,12 @@ module Allure
20
20
  :link_issue_pattern,
21
21
  :clean_results_directory,
22
22
  :environment_properties,
23
- :categories
23
+ :categories,
24
+ :global_labels
24
25
 
25
26
  def initialize
26
27
  @results_directory = "reports/allure-results"
28
+ @global_labels = []
27
29
  @logging_level = LOGLEVELS.index(ENV.fetch("ALLURE_LOG_LEVEL", "INFO")) || Logger::INFO
28
30
  end
29
31
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "tempfile"
4
+
3
5
  module Allure
4
6
  # Allure result file writer
5
7
  class FileWriter
@@ -83,12 +85,30 @@ module Allure
83
85
  end
84
86
 
85
87
  def write(name, source)
86
- filename = File.join(output_dir, name)
87
- File.write(filename, source)
88
+ atomic_write(name) { |temp_file| temp_file.write(source) }
88
89
  end
89
90
 
90
91
  def copy(from, to)
91
- FileUtils.cp(from, File.join(output_dir, to))
92
+ atomic_write(to) { |temp_file| IO.copy_stream(from, temp_file) }
93
+ end
94
+
95
+ def atomic_write(name)
96
+ filename = File.join(output_dir, name)
97
+ target_mode = begin
98
+ File.stat(filename).mode
99
+ rescue Errno::ENOENT
100
+ 0o644
101
+ end
102
+
103
+ Tempfile.create("#{name}.tmp", output_dir) do |temp_file|
104
+ temp_file.binmode
105
+
106
+ yield temp_file
107
+
108
+ temp_file.chmod(target_mode)
109
+ temp_file.close
110
+ File.rename(temp_file.path, filename)
111
+ end
92
112
  end
93
113
  end
94
114
  end
@@ -13,5 +13,19 @@ module Allure
13
13
  end
14
14
 
15
15
  attr_accessor :attachments, :errors
16
+
17
+ # Add an error to the globals
18
+ # @param [Allure::GlobalError] error
19
+ # @return [void]
20
+ def add_error(error)
21
+ @errors.push(error)
22
+ end
23
+
24
+ # Add an attachment to the globals
25
+ # @param [Allure::GlobalAttachment] attachment
26
+ # @return [void]
27
+ def add_attachment(attachment)
28
+ @attachments.push(attachment)
29
+ end
16
30
  end
17
31
  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.29.1
4
+ version: 2.30.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrejs Cunskis
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0'
123
123
  requirements: []
124
- rubygems_version: 3.6.9
124
+ rubygems_version: 4.0.20
125
125
  specification_version: 4
126
126
  summary: Common library for allure results generation
127
127
  test_files: []