|
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 |
0 commit comments