Skip to content

Commit bd714ea

Browse files
andrcunsbaev
authored andcommitted
proper module split (via #14)
1 parent 5511f87 commit bd714ea

31 files changed

+103
-54
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ pkg
1414
.yardoc
1515
reports
1616
.allure
17+
doc

.yardopts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
allure-ruby-commons/lib/**/*.rb
2+
allure-cucumber/lib/**/*.rb

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Allure ruby
22

3-
Ruby testing framework adaptors for generating allure compatible test reports
3+
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/github/allure-framework/allure-ruby/master)\
4+
Ruby testing framework adaptors for generating allure compatible test reports.
45

56
## allure-ruby-commons
67

allure-cucumber/README.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,61 +9,68 @@ Add this line to your application's Gemfile:
99
```ruby
1010
gem 'allure-cucumber'
1111
```
12+
1213
And then execute:
14+
1315
```bash
14-
$ bundle
16+
$ bundle
1517
```
1618

1719
Or install it yourself as:
20+
1821
```bash
19-
$ gem install allure-cucumber
22+
$ gem install allure-cucumber
2023
```
2124

2225
## Configuration
2326

24-
By default, Allure json files are stored in `reports/allure-results`. To change this add the following in `features/support/env.rb` file:
27+
Common allure configuration is set via `Allure.configure` method. To change id, add the following in `features/support/env.rb` file:
2528

2629
```ruby
2730
Allure.configure do |c|
28-
c.results_directory = "/output/dir"
31+
c.results_directory = "/whatever/you/like"
32+
c.logging_level = Logger::INFO
33+
# these are used for creating links to bugs or test cases where {} is replaced with keys of relevant items
34+
c.link_tms_pattern = "http://www.jira.com/browse/{}"
35+
c.link_issue_pattern = "http://www.jira.com/browse/{}"
2936
end
3037
```
3138

3239
By default, allure-cucumber will analyze your cucumber tags looking for Test Management, Issue Management, and Severity hooks. Links to TMS and ISSUE and test severity will be displayed in the report. By default these prefixes are used:
3340

34-
```ruby
41+
```ruby
3542
DEFAULT_TMS_PREFIX = 'TMS:'
3643
DEFAULT_ISSUE_PREFIX = 'ISSUE:'
3744
DEFAULT_SEVERITY_PREFIX = 'SEVERITY:'
3845
```
3946

40-
Example:
47+
Example:
48+
4149
```gherkin
4250
@SEVERITY:trivial @ISSUE:YZZ-100 @TMS:9901
4351
Scenario: Leave First Name Blank
4452
When I register an account without a first name
4553
Then exactly (1) [validation_error] should be visible
46-
```
54+
```
4755

4856
You can configure these prefixes as well as tms and issue tracker urls like this:
4957

5058
```ruby
51-
Allure.configure do |c|
52-
c.link_tms_pattern = "http://www.hiptest.com/tms/{}"
53-
c.link_issue_pattern = "http://www.jira.com/browse/{}"
59+
AllureCucumber.configure do |c|
5460
c.tms_prefix = 'HIPTEST--'
5561
c.issue_prefix = 'JIRA++'
5662
c.severity_prefix = 'URGENCY:'
5763
end
5864
```
5965

60-
Example:
66+
Example:
67+
6168
```gherkin
6269
@URGENCY:critical @JIRA++YZZ-100 @HIPTEST--9901
6370
Scenario: Leave First Name Blank
6471
When I register an account without a first name
6572
Then exactly (1) [validation_error] should be visible
66-
```
73+
```
6774

6875
Additional special tags exists for setting status detail of test scenarios, allure will pick up following tags: `@flaky`, `@known` and `@muted`
6976

@@ -75,7 +82,7 @@ Put the following in your `features/support/env.rb` file:
7582
require 'allure-cucumber'
7683
```
7784

78-
Use `--format Allure::CucumberFormatter --out where/you-want-results` while running cucumber or add it to `cucumber.yml`
85+
Use `--format AllureCucumber::CucumberFormatter --out where/you-want-results` while running cucumber or add it to `cucumber.yml`
7986

8087
You can also manually attach screenshots and links to test steps and test cases by interacting with allure lifecycle directly. For more info check out `allure-ruby-commons`
8188

@@ -89,4 +96,5 @@ Allure.add_link("Custom Url", "http://www.github.com")
8996
```
9097

9198
## How to generate report
99+
92100
This adaptor only generates json files containing information about tests. See [wiki section](https://docs.qameta.io/allure/#_reporting) on how to generate report.

allure-cucumber/lib/allure-cucumber.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
require "allure_cucumber/formatter"
77
require "allure_cucumber/config"
88

9-
module Allure
9+
# Main allure-cucumber module providing configuration methods
10+
module AllureCucumber
1011
class << self
1112
# Get allure cucumber configuration
1213
# @return [Allure::CucumberConfig]

allure-cucumber/lib/allure_cucumber/ast_transformer.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# frozen_string_literal: true
22

3-
# Cucumber::Core::Ast is removed in cucumber-core 4.0 version.
4-
# This will have to be updated accordingly, once stable version rolls out
5-
6-
module Allure
3+
module AllureCucumber
4+
# Cucumber::Core::Ast is removed in cucumber-core 4.0 version.
5+
# This will have to be updated accordingly, once stable version rolls out
76
module AstTransformer
87
# Get scenario object
98
# @param [Cucumber::Core::Test::Case] test_case
@@ -15,7 +14,7 @@ def scenario(test_case)
1514
end
1615

1716
# Get step object
18-
# @param [Cucumber::Core::Test::Step] test_case
17+
# @param [Cucumber::Core::Test::Step] test_step
1918
# @return [Cucumber::Core::Ast::Step]
2019
def step(test_step)
2120
test_step.source.detect { |it| it.is_a?(Cucumber::Core::Ast::Step) }

allure-cucumber/lib/allure_cucumber/config.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# frozen_string_literal: true
22

3-
module Allure
4-
class CucumberConfig < Config
3+
module AllureCucumber
4+
# Allure cucumber configuration
5+
class CucumberConfig
56
class << self
7+
# @return [String] default tms tag prefix
68
DEFAULT_TMS_PREFIX = "TMS:"
9+
# @return [String] default issue tag prefix
710
DEFAULT_ISSUE_PREFIX = "ISSUE:"
11+
# @return [String] default severity tag prefix
812
DEFAULT_SEVERITY_PREFIX = "SEVERITY:"
913

1014
attr_writer :tms_prefix, :issue_prefix, :severity_prefix

allure-cucumber/lib/allure_cucumber/cucumber_model.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
require_relative "ast_transformer"
99
require_relative "tag_parser"
1010

11-
module Allure
11+
module AllureCucumber
1212
# Support class for transforming cucumber test entities in to allure model entities
1313
class AllureCucumberModel
1414
extend AstTransformer
@@ -19,7 +19,7 @@ class << self
1919
# @param [Cucumber::Core::Test::Case] test_case
2020
# @return [TestResult]
2121
def test_result(test_case)
22-
TestResult.new(
22+
Allure::TestResult.new(
2323
name: test_case.name,
2424
description: description(test_case),
2525
description_html: description(test_case),
@@ -36,7 +36,7 @@ def test_result(test_case)
3636
# @param [Cucumber::Core::Test::Step] test_step
3737
# @return [StepResult]
3838
def step_result(test_step)
39-
StepResult.new(
39+
Allure::StepResult.new(
4040
name: "#{step(test_step).keyword}#{test_step.text}",
4141
attachments: [multiline_arg_attachment(test_step)].compact,
4242
)
@@ -47,7 +47,7 @@ def step_result(test_step)
4747
# @return [StepResult]
4848
def fixture_result(test_step)
4949
location = test_step.location.to_s.split("/").last
50-
FixtureResult.new(name: location)
50+
Allure::FixtureResult.new(name: location)
5151
end
5252

5353
# Get failure details
@@ -72,12 +72,12 @@ def lifecycle
7272
# @return [Array<Allure::Label>]
7373
def labels(test_case)
7474
labels = []
75-
labels << ResultUtils.framework_label("cucumber")
76-
labels << ResultUtils.feature_label(test_case.feature.name)
77-
labels << ResultUtils.package_label(test_case.feature.name)
78-
labels << ResultUtils.suite_label(test_case.feature.name)
79-
labels << ResultUtils.story_label(test_case.name)
80-
labels << ResultUtils.test_class_label(test_case.name)
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)
8181
unless test_case.tags.empty?
8282
labels.push(*tag_labels(test_case.tags))
8383
labels << severity(test_case.tags)
@@ -97,7 +97,7 @@ def links(test_case)
9797
# @param [Cucumber::Core::Test::Case] test_case
9898
# @return [Array<Allure::Parameter>]
9999
def parameters(test_case)
100-
example_row(test_case)&.values&.map { |value| Parameter.new("argument", value) }
100+
example_row(test_case)&.values&.map { |value| Allure::Parameter.new("argument", value) }
101101
end
102102

103103
# @param [Cucumber::Core::Test::Case] test_case
@@ -119,7 +119,7 @@ def multiline_arg_attachment(test_step)
119119
# @param [Cucumber::Core::Ast::DataTable] multiline_arg
120120
# @return [Allure::Attachment]
121121
def data_table_attachment(multiline_arg)
122-
attachment = lifecycle.prepare_attachment("data-table", ContentType::CSV)
122+
attachment = lifecycle.prepare_attachment("data-table", Allure::ContentType::CSV)
123123
csv = multiline_arg.raw.each_with_object([]) { |row, arr| arr.push(row.to_csv) }.join("")
124124
lifecycle.write_attachment(csv, attachment)
125125
attachment
@@ -128,7 +128,7 @@ def data_table_attachment(multiline_arg)
128128
# @param [String] multiline_arg
129129
# @return [String]
130130
def docstring_attachment(multiline_arg)
131-
attachment = lifecycle.prepare_attachment("docstring", ContentType::TXT)
131+
attachment = lifecycle.prepare_attachment("docstring", Allure::ContentType::TXT)
132132
lifecycle.write_attachment(multiline_arg.content, attachment)
133133
attachment
134134
end

allure-cucumber/lib/allure_cucumber/formatter.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
require_relative "cucumber_model"
44

5-
module Allure
5+
module AllureCucumber
66
# Main formatter class. Translates cucumber event to allure lifecycle
77
class CucumberFormatter
8+
# @return [Hash] hook handler methods
89
HOOK_HANDLERS = {
910
"Before hook" => :start_prepare_fixture,
1011
"After hook" => :start_tear_down_fixture,
1112
}.freeze
13+
# @return [Hash] allure statuses mapping
1214
ALLURE_STATUS = {
13-
failed: Status::FAILED,
14-
skipped: Status::SKIPPED,
15-
passed: Status::PASSED,
15+
failed: Allure::Status::FAILED,
16+
skipped: Allure::Status::SKIPPED,
17+
passed: Allure::Status::PASSED,
1618
}.freeze
1719

1820
# @param [Cucumber::Configuration] config
@@ -28,7 +30,7 @@ def initialize(config)
2830
# @param [Cucumber::Core::Events::TestCaseStarted] event
2931
# @return [void]
3032
def on_test_case_started(event)
31-
lifecycle.start_test_container(TestResultContainer.new(name: event.test_case.name))
33+
lifecycle.start_test_container(Allure::TestResultContainer.new(name: event.test_case.name))
3234
lifecycle.start_test_case(AllureCucumberModel.test_result(event.test_case))
3335
end
3436

@@ -46,8 +48,8 @@ def on_test_step_finished(event)
4648
return if prepare_world_hook?(event.test_step)
4749

4850
update_block = proc do |step|
49-
step.stage = Stage::FINISHED
50-
step.status = ALLURE_STATUS.fetch(event.result.to_sym, Status::BROKEN)
51+
step.stage = Allure::Stage::FINISHED
52+
step.status = ALLURE_STATUS.fetch(event.result.to_sym, Allure::Status::BROKEN)
5153
end
5254
step_type = hook?(event.test_step) ? "fixture" : "test_step"
5355

@@ -60,9 +62,9 @@ def on_test_step_finished(event)
6062
# @return [void]
6163
def on_test_case_finished(event)
6264
failure_details = AllureCucumberModel.failure_details(event.result)
63-
status = ALLURE_STATUS.fetch(event.result.to_sym, Status::BROKEN)
65+
status = ALLURE_STATUS.fetch(event.result.to_sym, Allure::Status::BROKEN)
6466
lifecycle.update_test_case do |test_case|
65-
test_case.stage = Stage::FINISHED
67+
test_case.stage = Allure::Stage::FINISHED
6668
test_case.status = event.result.failed? ? Allure::ResultUtils.status(event.result&.exception) : status
6769
test_case.status_details.flaky = event.result.flaky?
6870
test_case.status_details.message = failure_details[:message]

allure-cucumber/lib/allure_cucumber/tag_parser.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,37 @@
22

33
require_relative "config"
44

5-
module Allure
5+
module AllureCucumber
6+
# Cucumber tag parser helper methods
67
module TagParser
78
# @param [Cucumber::Core::Ast::Tag] tags
89
# @return [Array<Allure::Label>]
910
def tag_labels(tags)
1011
tags
1112
.reject { |tag| reserved?(tag.name) }
12-
.map { |tag| ResultUtils.tag_label(tag.name.delete_prefix("@")) }
13+
.map { |tag| Allure::ResultUtils.tag_label(tag.name.delete_prefix("@")) }
1314
end
1415

1516
# @param [Cucumber::Core::Ast::Tag] tags
1617
# @return [Array<Allure::Link>]
1718
def tms_links(tags)
18-
return [] unless CucumberConfig.link_tms_pattern
19+
return [] unless Allure::Config.link_tms_pattern
1920

2021
tms_pattern = reserved_patterns[:tms]
2122
tags
2223
.select { |tag| tag.name.match?(tms_pattern) }
23-
.map { |tag| tag.name.match(tms_pattern) { |match| ResultUtils.tms_link(match[:tms]) } }
24+
.map { |tag| tag.name.match(tms_pattern) { |match| Allure::ResultUtils.tms_link(match[:tms]) } }
2425
end
2526

2627
# @param [Cucumber::Core::Ast::Tag] tags
2728
# @return [Array<Allure::Link>]
2829
def issue_links(tags)
29-
return [] unless CucumberConfig.link_issue_pattern
30+
return [] unless Allure::Config.link_issue_pattern
3031

3132
issue_pattern = reserved_patterns[:issue]
3233
tags
3334
.select { |tag| tag.name.match?(issue_pattern) }
34-
.map { |tag| tag.name.match(issue_pattern) { |match| ResultUtils.issue_link(match[:issue]) } }
35+
.map { |tag| tag.name.match(issue_pattern) { |match| Allure::ResultUtils.issue_link(match[:issue]) } }
3536
end
3637

3738
# @param [Cucumber::Core::Ast::Tag] tags
@@ -42,7 +43,7 @@ def severity(tags)
4243
.detect { |tag| tag.name.match?(severity_pattern) }&.name
4344
&.match(severity_pattern)&.[](:severity) || "normal"
4445

45-
ResultUtils.severity_label(severity)
46+
Allure::ResultUtils.severity_label(severity)
4647
end
4748

4849
# @param [Cucumber::Core::Ast::Tag] tags

0 commit comments

Comments
 (0)