gherkin_checker 1.1.6 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a891fdd78e890d05a3cc2efb4d75c7d609cf59856219bc37f13b01cbb98c79fd
4
- data.tar.gz: f9da8527b261c56565ed5909427da2851a94702fe45737b9ab4091ff742acdec
3
+ metadata.gz: 187d4e241a76c4044dc0f41c640c4b3b5022508614482d6c6369dd72b4c9888a
4
+ data.tar.gz: 3e679ba099d82061788ae12270bb0d73f15673289e089ca35436a2d0418934d3
5
5
  SHA512:
6
- metadata.gz: 7f5567eb5950a2ce540ea4fd56a3a35c651d75f6ba1acfdcaaa922449d9ae0559881b6b86e079db3ae129074f46f3b8f5ccc2549caba9bef60fc5597fd651f08
7
- data.tar.gz: 7b6456730fea4048d557ced5bf229aaf8555d03393736ba770b534a373d10c99622cd3a334bceda09c91c191a06cb348611ee3597dc225200c528fbe16813a07
6
+ metadata.gz: 9184c1441b70cd8f8f8f6db7a1499b3f6cf476556e762a5f3b1318235e9a0ed1bf3dfbc7417aa6b1ff42f78ec4d1ca9ee278bd4edaec7bbfd57821063cea99fe
7
+ data.tar.gz: 3ba183a3a7af38e70823945f7228ac21311f3462b7d4f5be8c18047263b0f8f8e6d977ae560b61113c02148f0acb7a9dbc29b7b0b84cc87d22c6bc49b1846d25
data/README.md CHANGED
@@ -1,22 +1,44 @@
1
- # GherkinChecker
1
+ # gherkin_checker
2
2
 
3
- .feature file checker
3
+ **GherkinChecker** is a tool for validating and enforcing rules on Gherkin `.feature` files. It allows users to set custom tag and structure requirements for feature files to maintain consistency and quality in test scenarios.
4
4
 
5
5
  ## Installation
6
6
 
7
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
7
+ Install the gem and add it to your application's Gemfile by running:
8
8
 
9
- Install the gem and add to the application's Gemfile by executing:
9
+ ```sh
10
+ gem install gherkin_checker
11
+ ````
10
12
 
11
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
13
+ ## Usage
12
14
 
13
- If bundler is not being used to manage dependencies, install the gem by executing:
15
+ After successful installation, navigate to your project repository and create a configuration file named gherkin_checker.yml. Define your custom rules for Gherkin checking within this file. Below is a sample configuration format:
14
16
 
15
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
17
+ ```yaml
18
+ feature_files_path: '{to/your/path}'
19
+ mandatory_tags:
20
+ must_be:
21
+ - "Text1"
22
+ one_of:
23
+ - "Text2"
24
+ - "Text3"
25
+ - "Text4"
26
+ ```
16
27
 
17
- ## Usage
28
+ **Configuration Parameters**
29
+
30
+ - **feature_files_path**: Specifies the path to the directory containing Gherkin feature files.
31
+ - **mandatory_tags**:
32
+ - **must_be**: Tags that must be present in every feature file.
33
+ - **one_of**: Tags where at least one must be present in each feature file.
34
+
35
+ To run Gherkin Checker on your project, execute the following command in the terminal:
36
+
37
+ ```sh
38
+ gherkin_checker
39
+ ````
18
40
 
19
- TODO: Write usage instructions here
41
+ This command will check your feature files according to the rules defined in gherkin_checker.yml and provide feedback based on any discrepancies found.
20
42
 
21
43
  ## Development
22
44
 
@@ -26,7 +48,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
26
48
 
27
49
  ## Contributing
28
50
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gherkin_checker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/gherkin_checker/blob/main/CODE_OF_CONDUCT.md).
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dikako/gherkin_checker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/gherkin_checker/blob/main/CODE_OF_CONDUCT.md).
30
52
 
31
53
  ## License
32
54
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GherkinChecker
4
- VERSION = "1.1.6"
4
+ VERSION = "1.2.0"
5
5
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "find"
4
4
  require "yaml"
5
- require "set"
5
+ require "gherkin/parser"
6
6
 
7
7
  require_relative "gherkin_checker/version"
8
8
 
@@ -50,18 +50,20 @@ module GherkinChecker
50
50
  return log_one_of_tags_warning if @one_of_tags.nil?
51
51
 
52
52
  errors = []
53
- extract_scenarios_with_tags(file).each do |data|
54
- is_tags_nil = data[:tags].nil?
55
- tags = data[:tags]
53
+ extract_scenario_data(file).each do |data|
54
+ is_tags_nil = data[:scenario_tags].nil?
55
+ tags = data[:scenario_tags]
56
56
  file_line = data[:file_line]
57
- scenario = data[:scenario]
57
+ scenario = data[:scenario_name]
58
+ error = data[:error]
58
59
 
59
60
  if is_tags_nil
60
61
  errors << {
61
62
  check: :one_of_tags,
62
63
  file_line: file_line,
63
- scenario: scenario,
64
- tags: tags
64
+ scenario_name: scenario,
65
+ scenario_tags: tags,
66
+ error: error
65
67
  }
66
68
  end
67
69
 
@@ -72,8 +74,9 @@ module GherkinChecker
72
74
  errors << {
73
75
  check: :one_of_tags,
74
76
  file_line: file_line,
75
- scenario: scenario,
76
- tags: tags
77
+ scenario_name: scenario,
78
+ scenario_tags: tags,
79
+ error: error
77
80
  }
78
81
  end
79
82
 
@@ -84,18 +87,20 @@ module GherkinChecker
84
87
  return log_must_be_tags_warning if @must_be_tags.nil?
85
88
 
86
89
  errors = []
87
- extract_scenarios_with_tags(file).each do |data|
88
- is_tags_nil = data[:tags].nil?
89
- tags = data[:tags]
90
+ extract_scenario_data(file).each do |data|
91
+ is_tags_nil = data[:scenario_tags].nil?
92
+ tags = data[:scenario_tags]
90
93
  file_line = data[:file_line]
91
- scenario = data[:scenario]
94
+ scenario = data[:scenario_name]
95
+ error = data[:error]
92
96
 
93
97
  if is_tags_nil
94
98
  errors << {
95
99
  check: :must_be_tags,
96
100
  file_line: file_line,
97
- scenario: scenario,
98
- tags: tags
101
+ scenario_name: scenario,
102
+ scenario_tags: tags,
103
+ error: error
99
104
  }
100
105
  end
101
106
 
@@ -106,8 +111,9 @@ module GherkinChecker
106
111
  errors << {
107
112
  check: :must_be_tags,
108
113
  file_line: file_line,
109
- scenario: scenario,
110
- tags: tags
114
+ scenario_name: scenario,
115
+ scenario_tags: tags,
116
+ error: error
111
117
  }
112
118
  end
113
119
 
@@ -140,20 +146,25 @@ module GherkinChecker
140
146
  else
141
147
  log_message("Gherkin Checker found Error:", level: :error)
142
148
  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)
149
+ error_message = error[:error]
150
+ if error_message.nil?
151
+ scenario_tags = error[:scenario_tags]
152
+ tags = scenario_tags
153
+ tags = scenario_tags.nil? ? "Tagging not set" : "Just found '#{tags}'"
154
+
155
+ message = case error[:check]
156
+ when :one_of_tags
157
+ "one_of_tags '#{@one_of_tags}' not found!, #{tags}"
158
+ when :must_be_tags
159
+ "must_be_tags '#{@must_be_tags}' not found!, #{tags}"
160
+ else
161
+ "error undefined"
162
+ end
163
+
164
+ log_message("#{error[:file_line]}: #{error[:scenario_name]} - #{message}", level: :error)
165
+ else
166
+ log_message("Error: #{error_message}", level: :error)
167
+ end
157
168
  end
158
169
  end
159
170
  end
@@ -175,33 +186,48 @@ module GherkinChecker
175
186
  puts "#{color}#{message}#{colors[:reset]}"
176
187
  end
177
188
 
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
189
+ def extract_scenario_data(file)
190
+ gherkin_parser = Gherkin::Parser.new
191
+ scenario_data = []
192
+
193
+ begin
194
+ content = File.read(file)
195
+ document = gherkin_parser.parse(content)
196
+ feature = document.feature
197
+ feature_name = feature.name
198
+ feature_tags = feature.tags.map(&:name)
199
+
200
+ feature.children.each do |child|
201
+ raise "Error: read scenario data" unless child.respond_to?(:scenario) && child.scenario
202
+
203
+ scenario = child.scenario
204
+ scenario_name = scenario.name
205
+ scenario_tags = scenario.tags.map(&:name)
206
+ scenario_tags = scenario_tags.map { |tag| tag.delete_prefix("@") }
207
+ location_line = scenario.location.line
208
+ location_column = scenario.location.column
209
+
210
+ scenario_data << {
211
+ feature_name: feature_name,
212
+ feature_tags: feature_tags,
213
+ file_line: "#{file}:#{location_line}:#{location_column}",
214
+ scenario_name: scenario_name,
215
+ scenario_tags: scenario_tags,
216
+ error: nil
199
217
  }
200
- current_tags = [] # Reset tags for next scenario
201
218
  end
219
+ rescue StandardError => e
220
+ scenario_data << {
221
+ feature_name: nil,
222
+ feature_tags: nil,
223
+ file_line: nil,
224
+ scenario_name: nil,
225
+ scenario_tags: nil,
226
+ error: e.message
227
+ }
202
228
  end
203
229
 
204
- scenarios
230
+ scenario_data
205
231
  end
206
232
  end
207
233
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gherkin_checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dikakoko
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-11-04 00:00:00.000000000 Z
10
+ date: 2025-07-25 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Checking .feature files
14
13
  email:
@@ -27,7 +26,7 @@ licenses:
27
26
  - MIT
28
27
  metadata:
29
28
  rubygems_mfa_required: 'true'
30
- post_install_message:
29
+ source_code_uri: https://github.com/dikako/gherkin_checker
31
30
  rdoc_options: []
32
31
  require_paths:
33
32
  - lib
@@ -35,15 +34,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
35
34
  requirements:
36
35
  - - ">="
37
36
  - !ruby/object:Gem::Version
38
- version: '3.0'
37
+ version: '3.4'
39
38
  required_rubygems_version: !ruby/object:Gem::Requirement
40
39
  requirements:
41
40
  - - ">="
42
41
  - !ruby/object:Gem::Version
43
42
  version: '0'
44
43
  requirements: []
45
- rubygems_version: 3.2.33
46
- signing_key:
44
+ rubygems_version: 3.6.2
47
45
  specification_version: 4
48
46
  summary: ".feature files checkers"
49
47
  test_files: []