gherkin_checker 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4711b2c3890a6a9afec7106533d5aa5819b7ace4c99e449a00584a7573083ee1
4
+ data.tar.gz: 113c6415dd7d8b49ebc7549ad27c5eeb441872aa7b7d736f9a2bd015a73ca578
5
+ SHA512:
6
+ metadata.gz: 2bef2f8db640cea542bf432b387d005cb571c684a20692766a8ea616d0ca92c995cb61936c0226ba3055a319b0b776e1afd297e475930b3685e6bb5e1d9e83d4
7
+ data.tar.gz: 115dce1ae49277fca57e56b694dc96e5e1127d7e4918e021e71c7f8894dc4352b3502917e528c6c09fe305484e27947031a8334fd923cae156ecc7126d142adf
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # GherkinChecker
2
+
3
+ TODO: Delete this and the text below, and describe your gem
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.
6
+
7
+ ## Installation
8
+
9
+ 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.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ 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).
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the GherkinChecker project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/gherkin_checker/blob/main/CODE_OF_CONDUCT.md).
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "gherkin_checker"
5
+
6
+ # Initialize the checker with default config or custom path if provided
7
+ checker = GherkinChecker::Checker.new("gherkin_checker.yml")
8
+
9
+ # Run the check and print the results
10
+ errors = checker.check_feature_files
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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GherkinChecker
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "find"
4
+ require "yaml"
5
+
6
+ require_relative "gherkin_checker/version"
7
+
8
+ module GherkinChecker
9
+ # Checker class
10
+ class Checker
11
+ def initialize(config_file = "gherkin_checker.yml")
12
+ puts config_file.inspect
13
+ system("ls -l")
14
+ system("cat #{config_file}")
15
+
16
+ unless File.exist?(config_file)
17
+ puts "Error: Configuration file #{config_file} not found."
18
+ exit(1) # Exit with a status of 1 to indicate an error
19
+ end
20
+
21
+ @config = YAML.load_file(config_file)
22
+ @feature_files_path = @config["feature_files_path"] || "./features"
23
+ @one_of_tag_groups = @config.dig("mandatory_tags", "one_of")
24
+ @must_be_tags = @config.dig("mandatory_tags", "must_be")
25
+
26
+ puts @one_of_tag_groups.inspect
27
+ puts @must_be_tags.inspect
28
+ end
29
+
30
+ def check_feature_files
31
+ errors = []
32
+ Find.find(@feature_files_path) do |file|
33
+ next unless File.extname(file) == ".feature"
34
+
35
+ lines = File.readlines(file)
36
+ lines.each_with_index do |line, index|
37
+ next unless line.strip.start_with?("Scenario", "Scenario Outline")
38
+
39
+ puts scenario_valid?(lines, index)
40
+
41
+ next if scenario_valid?(lines, index)
42
+
43
+ errors << {
44
+ file: file,
45
+ line: index + 1,
46
+ scenario: line.strip
47
+ }
48
+ end
49
+ end
50
+ errors
51
+ end
52
+
53
+ private
54
+
55
+ def scenario_valid?(lines, index)
56
+ one_of_tags?(lines, index) && must_be_tags?(lines, index)
57
+ end
58
+
59
+ def one_of_tags?(lines, start_line)
60
+ return false if @one_of_tag_groups.nil?
61
+
62
+ @one_of_tag_groups.all? do |tag_group|
63
+ tag_group.any? { |tag| lines[0...start_line].reverse.any? { |line| line.include?(tag) } }
64
+ end
65
+ end
66
+
67
+ def must_be_tags?(lines, start_line)
68
+ return false if @must_be_tags.nil?
69
+
70
+ @must_be_tags.all? { |tag| lines[0...start_line].reverse.any? { |line| line.include?(tag) } }
71
+ end
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gherkin_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Dikakoko
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-11-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Checking .feature files
14
+ email:
15
+ - dikakoko@icloud.com
16
+ executables:
17
+ - gherkin_checker
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - README.md
22
+ - exe/gherkin_checker
23
+ - lib/gherkin_checker.rb
24
+ - lib/gherkin_checker/version.rb
25
+ homepage: https://github.com/yourusername/feature_tag_checker
26
+ licenses:
27
+ - MIT
28
+ metadata:
29
+ rubygems_mfa_required: 'true'
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '3.0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubygems_version: 3.2.32
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: A gem to validate mandatory tags in .feature files
49
+ test_files: []