gherkin_checker 1.0.0 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -3
- data/exe/gherkin_checker +1 -9
- data/lib/gherkin_checker/version.rb +1 -1
- data/lib/gherkin_checker.rb +162 -28
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 111267457a212006c30253734d11960637a14ea50b00ebb3ecf483a7649a65e7
|
4
|
+
data.tar.gz: 411a3c65e46496b5877944f03476d55be29eb0a80008edd92365f1d9cc85dc9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af750131d5843011ff26f3c2a40f639c7fda9d3711ac1b9d0deb1a7160bab6b3f0799a6e7ac270fbc729712ed9854d6fad6844b4a92c48282d8ca17cf5aa6436
|
7
|
+
data.tar.gz: aea323eed503046793b4eef9638c913246f326782a9e3a6f1a9a975a32c690c43662bd2fd2f75a5679510931c05bf949896f738b8f3ceef646fa3ae2bf116e0e
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# GherkinChecker
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gherkin_checker`. To experiment with that code, run `bin/console` for an interactive prompt.
|
3
|
+
.feature file checker
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
data/exe/gherkin_checker
CHANGED
@@ -7,13 +7,5 @@ require "gherkin_checker"
|
|
7
7
|
checker = GherkinChecker::Checker.new("gherkin_checker.yml")
|
8
8
|
|
9
9
|
# Run the check and print the results
|
10
|
-
|
10
|
+
checker.check_feature_files
|
11
11
|
|
12
|
-
if errors.empty?
|
13
|
-
puts "All scenarios have the required tags."
|
14
|
-
else
|
15
|
-
puts "The following scenarios have the required tags:"
|
16
|
-
errors.each do |error|
|
17
|
-
puts "#{error[:file]}: Line #{error[:line]} - #{error[:character]}"
|
18
|
-
end
|
19
|
-
end
|
data/lib/gherkin_checker.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require "find"
|
4
4
|
require "yaml"
|
5
|
+
require "set"
|
5
6
|
|
6
7
|
require_relative "gherkin_checker/version"
|
7
8
|
|
@@ -9,22 +10,26 @@ module GherkinChecker
|
|
9
10
|
# Checker class
|
10
11
|
class Checker
|
11
12
|
def initialize(config_file = "gherkin_checker.yml")
|
12
|
-
puts config_file.inspect
|
13
|
-
system("ls -l")
|
14
|
-
system("cat #{config_file}")
|
15
|
-
|
16
13
|
unless File.exist?(config_file)
|
17
|
-
|
14
|
+
log_message("Error: Configuration file #{config_file} not found.", level: :error)
|
18
15
|
exit(1) # Exit with a status of 1 to indicate an error
|
19
16
|
end
|
20
17
|
|
21
18
|
@config = YAML.load_file(config_file)
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
if @config
|
20
|
+
@skip_check = false
|
21
|
+
else
|
22
|
+
log_message("Warning: The gherkin_checker.yml not define", level: :warn)
|
23
|
+
@skip_check = true
|
24
|
+
end
|
25
|
+
|
26
|
+
@feature_files_path = @config&.key?("feature_files_path") ? @config.fetch("feature_files_path") : "./features"
|
27
|
+
@one_of_tags = @config.dig("mandatory_tags", "one_of") if @config
|
28
|
+
@must_be_tags = @config.dig("mandatory_tags", "must_be") if @config
|
25
29
|
|
26
|
-
|
27
|
-
|
30
|
+
# Flags to ensure warnings are only printed once
|
31
|
+
@one_of_tags_warning_shown = false
|
32
|
+
@must_be_tags_warning_shown = false
|
28
33
|
end
|
29
34
|
|
30
35
|
def check_feature_files
|
@@ -32,42 +37,171 @@ module GherkinChecker
|
|
32
37
|
Find.find(@feature_files_path) do |file|
|
33
38
|
next unless File.extname(file) == ".feature"
|
34
39
|
|
35
|
-
|
36
|
-
|
37
|
-
|
40
|
+
errors += check_one_of_tags(file)
|
41
|
+
errors += check_must_be_tags(file)
|
42
|
+
end
|
43
|
+
|
44
|
+
report_errors(errors)
|
45
|
+
end
|
38
46
|
|
39
|
-
|
47
|
+
private
|
40
48
|
|
41
|
-
|
49
|
+
def check_one_of_tags(file)
|
50
|
+
return log_one_of_tags_warning if @one_of_tags.nil?
|
42
51
|
|
52
|
+
errors = []
|
53
|
+
extract_scenarios_with_tags(file).each do |data|
|
54
|
+
is_tags_nil = data[:tags].nil?
|
55
|
+
tags = data[:tags]
|
56
|
+
file_line = data[:file_line]
|
57
|
+
scenario = data[:scenario]
|
58
|
+
|
59
|
+
if is_tags_nil
|
43
60
|
errors << {
|
44
|
-
|
45
|
-
|
46
|
-
scenario:
|
61
|
+
check: :one_of_tags,
|
62
|
+
file_line: file_line,
|
63
|
+
scenario: scenario,
|
64
|
+
tags: tags
|
47
65
|
}
|
48
66
|
end
|
67
|
+
|
68
|
+
next if is_tags_nil
|
69
|
+
|
70
|
+
next if @one_of_tags.any? { |tag| tags.include?(tag) }
|
71
|
+
|
72
|
+
errors << {
|
73
|
+
check: :one_of_tags,
|
74
|
+
file_line: file_line,
|
75
|
+
scenario: scenario,
|
76
|
+
tags: tags
|
77
|
+
}
|
49
78
|
end
|
79
|
+
|
50
80
|
errors
|
51
81
|
end
|
52
82
|
|
53
|
-
|
83
|
+
def check_must_be_tags(file)
|
84
|
+
return log_must_be_tags_warning if @must_be_tags.nil?
|
54
85
|
|
55
|
-
|
56
|
-
|
86
|
+
errors = []
|
87
|
+
extract_scenarios_with_tags(file).each do |data|
|
88
|
+
is_tags_nil = data[:tags].nil?
|
89
|
+
tags = data[:tags]
|
90
|
+
file_line = data[:file_line]
|
91
|
+
scenario = data[:scenario]
|
92
|
+
|
93
|
+
if is_tags_nil
|
94
|
+
errors << {
|
95
|
+
check: :must_be_tags,
|
96
|
+
file_line: file_line,
|
97
|
+
scenario: scenario,
|
98
|
+
tags: tags
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
102
|
+
next if is_tags_nil
|
103
|
+
|
104
|
+
next if @must_be_tags.all? { |item| tags.include?(item) }
|
105
|
+
|
106
|
+
errors << {
|
107
|
+
check: :must_be_tags,
|
108
|
+
file_line: file_line,
|
109
|
+
scenario: scenario,
|
110
|
+
tags: tags
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
errors
|
115
|
+
end
|
116
|
+
|
117
|
+
def log_one_of_tags_warning
|
118
|
+
return [] if @one_of_tags_warning_shown
|
119
|
+
|
120
|
+
log_message("Warning: Optional tags not set in 'gherkin_checker.yml'.", level: :warn) unless @skip_check
|
121
|
+
@one_of_tags_warning_shown = true
|
122
|
+
[] # Return an empty array to maintain consistency
|
57
123
|
end
|
58
124
|
|
59
|
-
def
|
60
|
-
return
|
125
|
+
def log_must_be_tags_warning
|
126
|
+
return [] if @must_be_tags_warning_shown
|
61
127
|
|
62
|
-
|
63
|
-
|
128
|
+
log_message("Warning: Mandatory tags not set in 'gherkin_checker.yml'.", level: :warn) unless @skip_check
|
129
|
+
@must_be_tags_warning_shown = true
|
130
|
+
[] # Return an empty array to maintain consistency
|
131
|
+
end
|
132
|
+
|
133
|
+
def report_errors(errors)
|
134
|
+
if errors.empty?
|
135
|
+
if @skip_check
|
136
|
+
log_message("Skip gherkin checking", level: :warn)
|
137
|
+
else
|
138
|
+
log_message("All scenarios have the required tags.")
|
139
|
+
end
|
140
|
+
else
|
141
|
+
log_message("Gherkin Checker found Error:", level: :error)
|
142
|
+
errors.each do |error|
|
143
|
+
tags = error[:tags]
|
144
|
+
tags = error[:tags].nil? ? "Tagging not set" : "Just found '#{tags}'"
|
145
|
+
|
146
|
+
message = case error[:check]
|
147
|
+
when :one_of_tags
|
148
|
+
"one_of_tags '#{@one_of_tags}' not found!, #{tags}"
|
149
|
+
when :must_be_tags
|
150
|
+
"must_be_tags '#{@must_be_tags}' not found!, #{tags}"
|
151
|
+
else
|
152
|
+
"error undefined"
|
153
|
+
end
|
154
|
+
|
155
|
+
# Log error to console
|
156
|
+
log_message("#{error[:file_line]}: #{error[:scenario]} - #{message}", level: :error)
|
157
|
+
end
|
64
158
|
end
|
65
159
|
end
|
66
160
|
|
67
|
-
|
68
|
-
|
161
|
+
# Define a method to log messages with different levels
|
162
|
+
def log_message(message, level: :info)
|
163
|
+
# Define color codes
|
164
|
+
colors = {
|
165
|
+
debug: "\e[36m", # Cyan
|
166
|
+
info: "\e[32m", # Green
|
167
|
+
warn: "\e[33m", # Yellow
|
168
|
+
error: "\e[31m", # Red
|
169
|
+
fatal: "\e[35m", # Magenta
|
170
|
+
reset: "\e[0m" # Reset to default color
|
171
|
+
}
|
172
|
+
|
173
|
+
color = colors[level] || colors[:reset]
|
174
|
+
|
175
|
+
puts "#{color}#{message}#{colors[:reset]}"
|
176
|
+
end
|
177
|
+
|
178
|
+
def extract_scenarios_with_tags(file)
|
179
|
+
scenarios = []
|
180
|
+
current_tags = []
|
181
|
+
|
182
|
+
lines = File.readlines(file)
|
183
|
+
|
184
|
+
lines.each_with_index do |line, index|
|
185
|
+
# Remove leading/trailing whitespace
|
186
|
+
line.strip!
|
187
|
+
|
188
|
+
if line.start_with?("@")
|
189
|
+
# Capture tags if line contains tags
|
190
|
+
current_tags = line.scan(/@(\w+)/).flatten
|
191
|
+
elsif line.start_with?("Scenario:", "Scenario Outline:")
|
192
|
+
# Capture scenario names
|
193
|
+
scenario_name = line.sub(/^Scenario(?: Outline)?:\s*/, "").strip
|
194
|
+
# Store scenario with current tags (nil if no tags), then reset tags for next scenario
|
195
|
+
scenarios << {
|
196
|
+
file_line: "#{file}:#{index + 1}",
|
197
|
+
scenario: scenario_name,
|
198
|
+
tags: current_tags.empty? ? nil : current_tags.dup
|
199
|
+
}
|
200
|
+
current_tags = [] # Reset tags for next scenario
|
201
|
+
end
|
202
|
+
end
|
69
203
|
|
70
|
-
|
204
|
+
scenarios
|
71
205
|
end
|
72
206
|
end
|
73
207
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gherkin_checker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dikakoko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Checking .feature files
|
14
14
|
email:
|
@@ -22,7 +22,7 @@ files:
|
|
22
22
|
- exe/gherkin_checker
|
23
23
|
- lib/gherkin_checker.rb
|
24
24
|
- lib/gherkin_checker/version.rb
|
25
|
-
homepage: https://github.com/
|
25
|
+
homepage: https://github.com/dikako/gherkin_checker
|
26
26
|
licenses:
|
27
27
|
- MIT
|
28
28
|
metadata:
|
@@ -45,5 +45,5 @@ requirements: []
|
|
45
45
|
rubygems_version: 3.2.32
|
46
46
|
signing_key:
|
47
47
|
specification_version: 4
|
48
|
-
summary:
|
48
|
+
summary: ".feature files checkers"
|
49
49
|
test_files: []
|