allure-cucumber 2.13.0 → 2.13.1

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: a40fd70805beafb477df5371f9e8f7c0f66cee6c8243b484141eb7b32c9a1026
4
- data.tar.gz: f555048bb7569ecee757c15082e384d30f89eb5d15799317084a8655a1f478bb
3
+ metadata.gz: ec242b1ce862dc86cbf68c7856daa57f683796581e4433af79b4ad7a55b9a783
4
+ data.tar.gz: fd36406dead4a7ba6fe504bf48b6a97b6a99ef2063820fe56426619f44df8460
5
5
  SHA512:
6
- metadata.gz: ac13c7c3b417e00809b05c584f695539f585aaf8712c58c15998049c1dc8382a5a8aea4bad87d783a5c3a85f224a53f29939dad7b11ba8a3b428b9ee20a1bd97
7
- data.tar.gz: bb7c69513879f80dd682ff78a896be2dc2d9a6994be249035ed4f9a60eecd4c5b33687ef89486add98e023faa0d0b676317055823b078d22d3b5f6c7d8745121
6
+ metadata.gz: e924c3a2e4a7ea1ce3b8b598f0f1ebed4b7a9299653b412b80588e4926b87e010b79557d0e2c83ef32a3c186b6638c5867d13e99f8af94791ded9e8e0d8bbb98
7
+ data.tar.gz: 6a22c0c59c031df736423e71826d2da0a9a64e3ac3672ff41edc6f85e50dccab817976fe73ae46da4a744ed94b7165133e6405dbe5611e1f414a4484f289c96f
@@ -10,128 +10,126 @@ require_relative "tag_parser"
10
10
 
11
11
  module AllureCucumber
12
12
  # Support class for transforming cucumber test entities in to allure model entities
13
- class AllureCucumberModel
14
- extend AstTransformer
15
- extend TagParser
16
-
17
- class << self
18
- # Convert to allure test result
19
- # @param [Cucumber::Core::Test::Case] test_case
20
- # @return [TestResult]
21
- def test_result(test_case)
22
- Allure::TestResult.new(
23
- name: test_case.name,
24
- description: description(test_case),
25
- description_html: description(test_case),
26
- history_id: Digest::MD5.hexdigest(test_case.inspect),
27
- full_name: "#{test_case.feature.name}: #{test_case.name}",
28
- labels: labels(test_case),
29
- links: links(test_case),
30
- parameters: parameters(test_case) || [],
31
- status_details: Allure::StatusDetails.new(**status_detail_tags(test_case.tags.map(&:name))),
32
- )
33
- end
13
+ module AllureCucumberModel
14
+ include AstTransformer
15
+ include TagParser
16
+
17
+ # Convert to allure test result
18
+ # @param [Cucumber::Core::Test::Case] test_case
19
+ # @return [TestResult]
20
+ def test_result(test_case)
21
+ Allure::TestResult.new(
22
+ name: test_case.name,
23
+ description: description(test_case),
24
+ description_html: description(test_case),
25
+ history_id: Digest::MD5.hexdigest(test_case.inspect),
26
+ full_name: "#{test_case.feature.name}: #{test_case.name}",
27
+ labels: labels(test_case),
28
+ links: links(test_case),
29
+ parameters: parameters(test_case) || [],
30
+ status_details: Allure::StatusDetails.new(**status_detail_tags(test_case.tags.map(&:name))),
31
+ )
32
+ end
34
33
 
35
- # Convert to allure step result
36
- # @param [Cucumber::Core::Test::Step] test_step
37
- # @return [StepResult]
38
- def step_result(test_step)
39
- Allure::StepResult.new(
40
- name: "#{step(test_step).keyword}#{test_step.text}",
41
- attachments: [multiline_arg_attachment(test_step)].compact,
42
- )
43
- end
34
+ # Convert to allure step result
35
+ # @param [Cucumber::Core::Test::Step] test_step
36
+ # @return [StepResult]
37
+ def step_result(test_step)
38
+ Allure::StepResult.new(
39
+ name: "#{step(test_step).keyword}#{test_step.text}",
40
+ attachments: [multiline_arg_attachment(test_step)].compact,
41
+ )
42
+ end
44
43
 
45
- # Convert to allure step result
46
- # @param [Cucumber::Core::Test::Step] test_step
47
- # @return [StepResult]
48
- def fixture_result(test_step)
49
- location = test_step.location.to_s.split("/").last
50
- Allure::FixtureResult.new(name: location)
51
- end
44
+ # Convert to allure step result
45
+ # @param [Cucumber::Core::Test::Step] test_step
46
+ # @return [StepResult]
47
+ def fixture_result(test_step)
48
+ location = test_step.location.to_s.split("/").last
49
+ Allure::FixtureResult.new(name: location)
50
+ end
52
51
 
53
- # Get failure details
54
- # @param [Cucumber::Core::Test::Result] result <description>
55
- # @return [Hash<Symbol, String>]
56
- def failure_details(result)
57
- return { message: result.exception.message, trace: result.exception.backtrace.join("\n") } if result.failed?
58
- return { message: result.message, trace: result.backtrace.join("\n") } if result.undefined?
52
+ # Get failure details
53
+ # @param [Cucumber::Core::Test::Result] result <description>
54
+ # @return [Hash<Symbol, String>]
55
+ def failure_details(result)
56
+ return { message: result.exception.message, trace: result.exception.backtrace.join("\n") } if result.failed?
57
+ return { message: result.message, trace: result.backtrace.join("\n") } if result.undefined?
59
58
 
60
- {}
61
- end
59
+ {}
60
+ end
62
61
 
63
- private
62
+ # Get thread specific lifecycle
63
+ # @return [Allure::AllureLifecycle]
64
+ def lifecycle
65
+ Allure.lifecycle
66
+ end
64
67
 
65
- # Get thread specific lifecycle
66
- # @return [Allure::AllureLifecycle]
67
- def lifecycle
68
- Allure.lifecycle
68
+ private
69
+
70
+ # @param [Cucumber::Core::Test::Case] test_case
71
+ # @return [Array<Allure::Label>]
72
+ def labels(test_case)
73
+ labels = []
74
+ labels << Allure::ResultUtils.framework_label("cucumber")
75
+ labels << Allure::ResultUtils.feature_label(test_case.feature.name)
76
+ labels << Allure::ResultUtils.package_label(test_case.feature.name)
77
+ labels << Allure::ResultUtils.suite_label(test_case.feature.name)
78
+ labels << Allure::ResultUtils.story_label(test_case.name)
79
+ labels << Allure::ResultUtils.test_class_label(test_case.name)
80
+ unless test_case.tags.empty?
81
+ labels.push(*tag_labels(test_case.tags))
82
+ labels << severity(test_case.tags)
69
83
  end
70
84
 
71
- # @param [Cucumber::Core::Test::Case] test_case
72
- # @return [Array<Allure::Label>]
73
- def labels(test_case)
74
- labels = []
75
- labels << Allure::ResultUtils.framework_label("cucumber")
76
- labels << Allure::ResultUtils.feature_label(test_case.feature.name)
77
- labels << Allure::ResultUtils.package_label(test_case.feature.name)
78
- labels << Allure::ResultUtils.suite_label(test_case.feature.name)
79
- labels << Allure::ResultUtils.story_label(test_case.name)
80
- labels << Allure::ResultUtils.test_class_label(test_case.name)
81
- unless test_case.tags.empty?
82
- labels.push(*tag_labels(test_case.tags))
83
- labels << severity(test_case.tags)
84
- end
85
-
86
- labels
87
- end
85
+ labels
86
+ end
88
87
 
89
- # @param [Cucumber::Core::Test::Case] test_case
90
- # @return [Array<Allure::Link>]
91
- def links(test_case)
92
- return [] unless test_case.tags
88
+ # @param [Cucumber::Core::Test::Case] test_case
89
+ # @return [Array<Allure::Link>]
90
+ def links(test_case)
91
+ return [] unless test_case.tags
93
92
 
94
- tms_links(test_case.tags) + issue_links(test_case.tags)
95
- end
93
+ tms_links(test_case.tags) + issue_links(test_case.tags)
94
+ end
96
95
 
97
- # @param [Cucumber::Core::Test::Case] test_case
98
- # @return [Array<Allure::Parameter>]
99
- def parameters(test_case)
100
- example_row(test_case)&.values&.map { |value| Allure::Parameter.new("argument", value) }
101
- end
96
+ # @param [Cucumber::Core::Test::Case] test_case
97
+ # @return [Array<Allure::Parameter>]
98
+ def parameters(test_case)
99
+ example_row(test_case)&.values&.map { |value| Allure::Parameter.new("argument", value) }
100
+ end
102
101
 
103
- # @param [Cucumber::Core::Test::Case] test_case
104
- # @return [String]
105
- def description(test_case)
106
- scenario = scenario(test_case)
107
- scenario.description.empty? ? "Location - #{scenario.file_colon_line}" : scenario.description.strip
108
- end
102
+ # @param [Cucumber::Core::Test::Case] test_case
103
+ # @return [String]
104
+ def description(test_case)
105
+ scenario = scenario(test_case)
106
+ scenario.description.empty? ? "Location - #{scenario.file_colon_line}" : scenario.description.strip
107
+ end
109
108
 
110
- # @param [Cucumber::Core::Test::Step] test_step
111
- # @return [Allure::Attachment]
112
- def multiline_arg_attachment(test_step)
113
- arg = multiline_arg(test_step)
114
- return unless arg
109
+ # @param [Cucumber::Core::Test::Step] test_step
110
+ # @return [Allure::Attachment]
111
+ def multiline_arg_attachment(test_step)
112
+ arg = multiline_arg(test_step)
113
+ return unless arg
115
114
 
116
- arg.data_table? ? data_table_attachment(arg) : docstring_attachment(arg)
117
- end
115
+ arg.data_table? ? data_table_attachment(arg) : docstring_attachment(arg)
116
+ end
118
117
 
119
- # @param [Cucumber::Core::Ast::DataTable] multiline_arg
120
- # @return [Allure::Attachment]
121
- def data_table_attachment(multiline_arg)
122
- attachment = lifecycle.prepare_attachment("data-table", Allure::ContentType::CSV)
123
- csv = multiline_arg.raw.each_with_object([]) { |row, arr| arr.push(row.to_csv) }.join("")
124
- lifecycle.write_attachment(csv, attachment)
125
- attachment
126
- end
118
+ # @param [Cucumber::Core::Ast::DataTable] multiline_arg
119
+ # @return [Allure::Attachment]
120
+ def data_table_attachment(multiline_arg)
121
+ attachment = lifecycle.prepare_attachment("data-table", Allure::ContentType::CSV)
122
+ csv = multiline_arg.raw.each_with_object([]) { |row, arr| arr.push(row.to_csv) }.join("")
123
+ lifecycle.write_attachment(csv, attachment)
124
+ attachment
125
+ end
127
126
 
128
- # @param [String] multiline_arg
129
- # @return [String]
130
- def docstring_attachment(multiline_arg)
131
- attachment = lifecycle.prepare_attachment("docstring", Allure::ContentType::TXT)
132
- lifecycle.write_attachment(multiline_arg.content, attachment)
133
- attachment
134
- end
127
+ # @param [String] multiline_arg
128
+ # @return [String]
129
+ def docstring_attachment(multiline_arg)
130
+ attachment = lifecycle.prepare_attachment("docstring", Allure::ContentType::TXT)
131
+ lifecycle.write_attachment(multiline_arg.content, attachment)
132
+ attachment
135
133
  end
136
134
  end
137
135
  end
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "fileutils"
4
3
  require_relative "cucumber_model"
5
4
 
6
5
  module AllureCucumber
7
6
  # Main formatter class. Translates cucumber event to allure lifecycle
8
7
  class CucumberFormatter
8
+ include AllureCucumberModel
9
+
9
10
  # @return [Hash] hook handler methods
10
11
  HOOK_HANDLERS = {
11
12
  "Before hook" => :start_prepare_fixture,
@@ -22,20 +23,28 @@ module AllureCucumber
22
23
  def initialize(config)
23
24
  Allure.configure do |c|
24
25
  c.results_directory = config.out_stream if config.out_stream.is_a?(String)
25
- FileUtils.rm_f(Dir.glob("#{c.results_directory}/*")) if c.clean_results_directory
26
26
  end
27
+
28
+ config.on_event(:test_run_started, &method(:on_test_run_started))
27
29
  config.on_event(:test_case_started, &method(:on_test_case_started))
28
30
  config.on_event(:test_step_started, &method(:on_test_step_started))
29
31
  config.on_event(:test_step_finished, &method(:on_test_step_finished))
30
32
  config.on_event(:test_case_finished, &method(:on_test_case_finished))
31
33
  end
32
34
 
35
+ # Clean test result directory before starting run
36
+ # @param [Cucumber::Events::TestRunStarted<Type>] _event
37
+ # @return [void]
38
+ def on_test_run_started(_event)
39
+ lifecycle.clean_results_dir
40
+ end
41
+
33
42
  # Handle test case started event
34
43
  # @param [Cucumber::Core::Events::TestCaseStarted] event
35
44
  # @return [void]
36
45
  def on_test_case_started(event)
37
46
  lifecycle.start_test_container(Allure::TestResultContainer.new(name: event.test_case.name))
38
- lifecycle.start_test_case(AllureCucumberModel.test_result(event.test_case))
47
+ lifecycle.start_test_case(test_result(event.test_case))
39
48
  end
40
49
 
41
50
  # Handle test step started event
@@ -65,7 +74,7 @@ module AllureCucumber
65
74
  # @param [Cucumber::Core::Events::TestCaseFinished] event
66
75
  # @return [void]
67
76
  def on_test_case_finished(event)
68
- failure_details = AllureCucumberModel.failure_details(event.result)
77
+ failure_details = failure_details(event.result)
69
78
  status = ALLURE_STATUS.fetch(event.result.to_sym, Allure::Status::BROKEN)
70
79
  lifecycle.update_test_case do |test_case|
71
80
  test_case.stage = Allure::Stage::FINISHED
@@ -80,12 +89,6 @@ module AllureCucumber
80
89
 
81
90
  private
82
91
 
83
- # Get thread specific lifecycle
84
- # @return [Allure::AllureLifecycle]
85
- def lifecycle
86
- Allure.lifecycle
87
- end
88
-
89
92
  # @param [Cucumber::Core::Test::Step] test_step <description>
90
93
  # @return [Boolean]
91
94
  def hook?(test_step)
@@ -101,7 +104,7 @@ module AllureCucumber
101
104
  # @param [Cucumber::Core::Test::Step] test_step
102
105
  # @return [void]
103
106
  def handle_step_started(test_step)
104
- lifecycle.start_test_step(AllureCucumberModel.step_result(test_step))
107
+ lifecycle.start_test_step(step_result(test_step))
105
108
  end
106
109
 
107
110
  # @param [Cucumber::Core::Test::Step] test_step
@@ -109,7 +112,7 @@ module AllureCucumber
109
112
  def handle_hook_started(test_step)
110
113
  return if prepare_world_hook?(test_step)
111
114
 
112
- lifecycle.public_send(HOOK_HANDLERS[test_step.text], AllureCucumberModel.fixture_result(test_step))
115
+ lifecycle.public_send(HOOK_HANDLERS[test_step.text], fixture_result(test_step))
113
116
  end
114
117
  end
115
118
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: allure-cucumber
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.0
4
+ version: 2.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrejs Cunskis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-08 00:00:00.000000000 Z
11
+ date: 2019-10-09 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.0
19
+ version: 2.13.1
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.0
26
+ version: 2.13.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: cucumber
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -54,7 +54,12 @@ files:
54
54
  homepage: https://github.com/allure-framework/allure-ruby
55
55
  licenses:
56
56
  - Apache-2.0
57
- metadata: {}
57
+ metadata:
58
+ bug_tracker_uri: https://github.com/allure-framework/allure-ruby/issues
59
+ changelog_uri: https://github.com/allure-framework/allure-ruby/releases
60
+ documentation_uri: https://github.com/allure-framework/allure-ruby/blob/master/allure-cucumber/README.md
61
+ source_code_uri: https://github.com/allure-framework/allure-ruby/tree/master/allure-cucumber
62
+ wiki_uri: https://github.com/allure-framework/allure-ruby/wiki
58
63
  post_install_message:
59
64
  rdoc_options: []
60
65
  require_paths: