-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from funkwerk/feature/tag_used_multiple_times
tags shouldn't be used mutliple times for a scenario
- Loading branch information
Showing
6 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
Feature: Tag Used Multiple Times | ||
As a Business Analyst | ||
I want to use tags just once | ||
so that redundancy is minimized. | ||
|
||
Background: Prepare Testee | ||
Given a file named "lint.rb" with: | ||
""" | ||
$LOAD_PATH << '../../lib' | ||
require 'gherkin_lint' | ||
linter = GherkinLint::GherkinLint.new | ||
linter.enable %w(TagUsedMultipleTimes) | ||
linter.analyze 'lint.feature' | ||
exit linter.report | ||
""" | ||
|
||
Scenario Outline: Tag used twice | ||
Given a file named "lint.feature" with: | ||
""" | ||
<feature tag> | ||
Feature: Test | ||
@tag <scenario tag> | ||
Scenario: A | ||
""" | ||
When I run `ruby lint.rb` | ||
Then it should fail with exactly: | ||
""" | ||
TagUsedMultipleTimes - Tag @tag used multiple times | ||
lint.feature (4): Test.A | ||
""" | ||
|
||
Examples: Invalid Tag Combinations | ||
| feature tag | scenario tag | | ||
| @tag | | | ||
| | @tag | | ||
|
||
Scenario: Just unique tags | ||
Given a file named "lint.feature" with: | ||
""" | ||
Feature: Test | ||
@tag_a @tag_b | ||
Scenario: A | ||
""" | ||
When I run `ruby lint.rb` | ||
Then it should pass with exactly: | ||
""" | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'gherkin_lint/linter' | ||
|
||
module GherkinLint | ||
# service class to lint for tags used multiple times | ||
class TagUsedMultipleTimes < Linter | ||
def lint | ||
scenarios do |file, feature, scenario| | ||
references = [reference(file, feature, scenario)] | ||
total_tags = tags(feature) + tags(scenario) | ||
double_used_tags = total_tags.find_all { |a| total_tags.count(a) > 1 }.uniq! | ||
next if double_used_tags.nil? | ||
add_error(references, "Tag #{double_used_tags.join(' and ')} used multiple times") | ||
end | ||
end | ||
|
||
def tags(element) | ||
return [] unless element.include? :tags | ||
element[:tags].map { |a| a[:name] } | ||
end | ||
end | ||
end |