allure-ruby-commons 2.13.3 → 2.13.6

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: 63f3f8681c7437dcc8be0da1a0da44ba238d3103b56f6146746ae910d38ed76d
4
- data.tar.gz: e0a6e79db8e67121bfe250c1bc576d18dcbeb1bfa5f3679513dba37759d97d64
3
+ metadata.gz: 12cb6b2b1132dd43b17becb6b9a32c47cb9aa44a3be793dc09f083d7e5784370
4
+ data.tar.gz: a34abfd6a9dff13b8b6b1d571b33f348549c59848579220c4a8add6d5317004c
5
5
  SHA512:
6
- metadata.gz: 3e6d27dc40e461f96695f5c7a93ad9b27bdd12982ea77e669aad7d5dc3fb76bec86149fe267124bcf1711a153bda175f44ae5f80f872723035bc714d7a20e361
7
- data.tar.gz: d0905aa7da8b94c983614db9f7693cfa7c37e8fca7655eb4b40084fe650e92f00883c4158d83adbcb5c2c7608bd5e5604c62e7cd0b6733e9d8d7d2aaef2cdf2e
6
+ metadata.gz: 1d6bf42ce012302f708869666f94ea4a8a408dc2c17f4989e2b469b3a100458a36226d5b9790ba497b4b69c87306ee437f6825187255f1c00dc9d1a579e5d322
7
+ data.tar.gz: f15cadf664ae40f2152a86f541bd2a3ef68de4bc60bc72908b04ace4a90753088a6342a3eb63846a95a38b5e311c573223fe5d901fc29c78b2f4cd76f5958ddc
data/README.md CHANGED
@@ -11,7 +11,7 @@ you can just create the report of any other kind using the basic Allure terms.
11
11
  Add the dependency to your Gemfile
12
12
 
13
13
  ```ruby
14
- gem 'allure-ruby-commons'
14
+ gem "allure-ruby-commons"
15
15
  ```
16
16
 
17
17
  ## Configuration
@@ -19,13 +19,13 @@ Add the dependency to your Gemfile
19
19
  Following configuration options are supported:
20
20
 
21
21
  ```ruby
22
- Allure.configure do |c|
23
- c.results_directory = "/whatever/you/like"
24
- c.clean_results_directory = true
25
- c.logging_level = Logger::INFO
22
+ Allure.configure do |config|
23
+ config.results_directory = "/whatever/you/like"
24
+ config.clean_results_directory = true
25
+ config.logging_level = Logger::INFO
26
26
  # these are used for creating links to bugs or test cases where {} is replaced with keys of relevant items
27
- c.link_tms_pattern = "http://www.jira.com/browse/{}"
28
- c.link_issue_pattern = "http://www.jira.com/browse/{}"
27
+ config.link_tms_pattern = "http://www.jira.com/browse/{}"
28
+ config.link_issue_pattern = "http://www.jira.com/browse/{}"
29
29
  end
30
30
  ```
31
31
 
@@ -9,30 +9,30 @@ require_rel "allure_ruby_commons/**/*rb"
9
9
  module Allure
10
10
  class << self
11
11
  # Get thread specific allure lifecycle object
12
- # @return [Allure::AllureLifecycle]
12
+ # @return [AllureLifecycle]
13
13
  def lifecycle
14
14
  Thread.current[:lifecycle] ||= AllureLifecycle.new
15
15
  end
16
16
 
17
17
  # Set lifecycle object
18
- # @param [Allure::AllureLifecycle] lifecycle
18
+ # @param [AllureLifecycle] lifecycle
19
19
  # @return [void]
20
20
  def lifecycle=(lifecycle)
21
21
  Thread.current[:lifecycle] = lifecycle
22
22
  end
23
23
 
24
24
  # Get allure configuration
25
- # @return [Allure::Config]
25
+ # @return [Config]
26
26
  def configuration
27
- Config
27
+ Config.instance
28
28
  end
29
29
 
30
30
  # Set allure configuration
31
- # @yieldparam [Allure::Config]
31
+ # @yieldparam [Config]
32
32
  # @yieldreturn [void]
33
33
  # @return [void]
34
34
  def configure
35
- yield(Config)
35
+ yield(configuration)
36
36
  end
37
37
 
38
38
  # Add epic to current test case
@@ -131,7 +131,7 @@ module Allure
131
131
  # Add attachment to current test case or step
132
132
  # @param [String] name Attachment name
133
133
  # @param [File, String] source File or string to save as attachment
134
- # @param [String] type attachment type defined in {Allure::ContentType} or any other valid mime type
134
+ # @param [String] type attachment type defined in {ContentType} or any other valid mime type
135
135
  # @param [Boolean] test_case add attachment to current test case instead of test step
136
136
  # @return [void]
137
137
  def add_attachment(name:, source:, type:, test_case: false)
@@ -146,7 +146,7 @@ module Allure
146
146
  end
147
147
 
148
148
  # Add categories info
149
- # @param [File, Array<Allure::Category>] categories
149
+ # @param [File, Array<Category>] categories
150
150
  # @return [void]
151
151
  def add_categories(categories)
152
152
  lifecycle.write_categories(categories)
@@ -154,10 +154,11 @@ module Allure
154
154
 
155
155
  # Add step with provided name and optional status to current test step, fixture or test case
156
156
  # @param [String] name
157
- # @param [Symbol] status <Allure::Status>, <Allure::Status::PASSED> by default
157
+ # @param [Symbol] status {Status}, {Status::PASSED} by default
158
158
  # @return [void]
159
159
  def step(name:, status: nil)
160
160
  lifecycle.add_test_step(StepResult.new(name: name, status: status || Status::PASSED, stage: Stage::FINISHED))
161
+ lifecycle.stop_test_step
161
162
  end
162
163
 
163
164
  # Run passed block as step with given name
@@ -11,6 +11,8 @@ module Allure
11
11
  def initialize
12
12
  @test_context = []
13
13
  @step_context = []
14
+ @logger = Logger.new(STDOUT, level: Config.instance.logging_level)
15
+ @file_writer = FileWriter.new
14
16
  end
15
17
 
16
18
  def_delegators :file_writer, :write_attachment, :write_environment, :write_categories
@@ -193,7 +195,7 @@ module Allure
193
195
  # @param [Boolean] test_case add attachment to current test case
194
196
  # @return [void]
195
197
  def add_attachment(name:, source:, type:, test_case: false)
196
- attachment = prepare_attachment(name, type) || begin
198
+ attachment = ResultUtils.prepare_attachment(name, type) || begin
197
199
  return logger.error("Can't add attachment, unrecognized mime type: #{type}")
198
200
  end
199
201
  executable_item = (test_case && @current_test_case) || current_executable
@@ -203,16 +205,6 @@ module Allure
203
205
  write_attachment(source, attachment)
204
206
  end
205
207
 
206
- # Create attachment object
207
- # @param [String] name
208
- # @param [String] type
209
- # @return [Allure::Attachment]
210
- def prepare_attachment(name, type)
211
- extension = ContentType.to_extension(type) || return
212
- file_name = "#{UUID.generate}-attachment.#{extension}"
213
- Attachment.new(name: name, source: file_name, type: type)
214
- end
215
-
216
208
  # Add step to current fixture|step|test case
217
209
  # @param [Allure::StepResult] step_result
218
210
  # @return [Allure::StepResult]
@@ -232,13 +224,7 @@ module Allure
232
224
 
233
225
  private
234
226
 
235
- def logger
236
- @logger ||= Logger.new(STDOUT, level: Config.logging_level)
237
- end
238
-
239
- def file_writer
240
- @file_writer ||= FileWriter.new
241
- end
227
+ attr_accessor :logger, :file_writer
242
228
 
243
229
  def current_executable
244
230
  current_test_step || @current_fixture || @current_test_case
@@ -1,26 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "logger"
4
+ require "singleton"
4
5
 
5
6
  module Allure
6
7
  # Allure configuration class
7
8
  class Config
9
+ include Singleton
10
+
8
11
  # @return [String] default allure results directory
9
12
  DEFAULT_RESULTS_DIRECTORY = "reports/allure-results"
10
13
  # @return [String] default loggin level
11
14
  DEFAULT_LOGGING_LEVEL = Logger::INFO
12
15
 
13
- class << self
14
- attr_accessor :link_tms_pattern, :link_issue_pattern, :clean_results_directory
15
- attr_writer :results_directory, :logging_level
16
+ attr_accessor :link_tms_pattern, :link_issue_pattern, :clean_results_directory
17
+ attr_writer :results_directory, :logging_level
16
18
 
17
- def results_directory
18
- @results_directory || DEFAULT_RESULTS_DIRECTORY
19
- end
19
+ def results_directory
20
+ @results_directory || DEFAULT_RESULTS_DIRECTORY
21
+ end
20
22
 
21
- def logging_level
22
- @logging_level || DEFAULT_LOGGING_LEVEL
23
- end
23
+ def logging_level
24
+ @logging_level || DEFAULT_LOGGING_LEVEL
24
25
  end
25
26
  end
26
27
  end
@@ -59,7 +59,7 @@ module Allure
59
59
  private
60
60
 
61
61
  def output_dir
62
- @output_dir ||= FileUtils.mkpath(Allure::Config.results_directory).first
62
+ @output_dir ||= FileUtils.mkpath(Config.instance.results_directory).first
63
63
  end
64
64
 
65
65
  def write(name, source)
@@ -3,8 +3,8 @@
3
3
  require_relative "jsonable"
4
4
 
5
5
  module Allure
6
+ # Defects category
6
7
  class Category < JSONable
7
- # Defects category
8
8
  # @param [String] name
9
9
  # @param [Array<Allure::Status>] matched_statuses
10
10
  # @param [String, Regexp] message_regex
@@ -5,6 +5,9 @@ require "json"
5
5
  module Allure
6
6
  # General jsonable object implementation
7
7
  class JSONable
8
+ # Return object has represantation
9
+ # @param [Hash] _options
10
+ # @return [Hash]
8
11
  def as_json(_options = {})
9
12
  instance_variables.each_with_object({}) do |var, map|
10
13
  key = camelcase(var.to_s.delete_prefix("@"))
@@ -13,22 +16,33 @@ module Allure
13
16
  end
14
17
  end
15
18
 
19
+ # Convert object to json string
20
+ # @param [Array<Object>] options
21
+ # @return [String]
16
22
  def to_json(*options)
17
23
  as_json(*options).to_json(*options)
18
24
  end
19
25
 
26
+ # Object comparator
27
+ # @param [JSONable] other
28
+ # @return [Booelan]
20
29
  def ==(other)
21
30
  self.class == other.class && state == other.state
22
31
  end
23
32
 
24
33
  protected
25
34
 
35
+ # Object state
36
+ # @return [Array]
26
37
  def state
27
38
  instance_variables.map { |var| instance_variable_get(var) }
28
39
  end
29
40
 
30
41
  private
31
42
 
43
+ # Covert string to camelcase
44
+ # @param [String] str
45
+ # @return [String]
32
46
  def camelcase(str)
33
47
  str = str.gsub(/(?:_+)([a-z])/) { Regexp.last_match(1).upcase }
34
48
  str.gsub(/(\A|\s)([A-Z])/) { Regexp.last_match(1) + Regexp.last_match(2).downcase }
@@ -46,10 +46,15 @@ module Allure
46
46
  Label.new(HOST_LABEL_NAME, Socket.gethostname)
47
47
  end
48
48
 
49
+ # Language label
50
+ # @return [Allure::Label]
49
51
  def language_label
50
52
  Label.new(LANGUAGE_LABEL_NAME, "ruby")
51
53
  end
52
54
 
55
+ # Framework label
56
+ # @param [String] value
57
+ # @return [Allure::Label]
53
58
  def framework_label(value)
54
59
  Label.new(FRAMEWORK_LABEL_NAME, value)
55
60
  end
@@ -145,6 +150,16 @@ module Allure
145
150
  StatusDetails.new(message: exception&.message, trace: exception&.backtrace&.join("\n"))
146
151
  end
147
152
 
153
+ # Allure attachment object
154
+ # @param [String] name
155
+ # @param [String] type
156
+ # @return [Allure::Attachment]
157
+ def prepare_attachment(name, type)
158
+ extension = ContentType.to_extension(type) || return
159
+ file_name = "#{UUID.generate}-attachment.#{extension}"
160
+ Attachment.new(name: name, source: file_name, type: type)
161
+ end
162
+
148
163
  private
149
164
 
150
165
  def tms_url(value)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: allure-ruby-commons
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.3
4
+ version: 2.13.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrejs Cunskis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-07 00:00:00.000000000 Z
11
+ date: 2020-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uuid
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  requirements: []
133
- rubygems_version: 3.0.3
133
+ rubygems_version: 3.1.2
134
134
  signing_key:
135
135
  specification_version: 4
136
136
  summary: Common library for allure results generation