Skip to content

Commit

Permalink
proper handling of snake_case feature files
Browse files Browse the repository at this point in the history
  • Loading branch information
lindt committed Aug 31, 2016
1 parent a06a439 commit a610aeb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end

desc 'Publishes the Gem'
task :push do
sh 'gem push gherkin_lint-0.4.4.gem'
sh 'gem push gherkin_lint-0.5.0.gem'
end

desc 'Checks ruby style'
Expand Down
28 changes: 28 additions & 0 deletions features/file_name_differs_feature_name.feature
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,31 @@ Feature: File Name Differs Feature Name
| lint |
| Lint |
| LINT |

Scenario Outline: Valid Example for Snake Case
Given a file named "lint.rb" with:
"""
$LOAD_PATH << '../../lib'
require 'gherkin_lint'
linter = GherkinLint::GherkinLint.new
linter.enable %w(FileNameDiffersFeatureName)
linter.analyze 'lint_test.feature'
exit linter.report
"""
Given a file named "lint_test.feature" with:
"""
Feature: <name>
"""
When I run `ruby lint.rb lint_test.feature`
Then it should pass with exactly:
"""
"""

Examples: Valid Names
| name |
| lint_test |
| lint-test |
| lint test |
4 changes: 2 additions & 2 deletions gherkin_lint.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'gherkin_lint'
s.version = '0.4.4'
s.date = '2016-08-30'
s.version = '0.5.0'
s.date = '2016-08-31'
s.summary = 'Gherkin Lint'
s.description = 'Lint Gherkin Files'
s.authors = ['Stefan Rohe']
Expand Down
6 changes: 5 additions & 1 deletion lib/gherkin_lint/linter/file_name_differs_feature_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def lint
features do |file, feature|
next unless feature.include? :name
expected_feature_name = title_case file
next if feature[:name].casecmp(expected_feature_name) == 0
next if ignore_whitespaces(feature[:name]).casecmp(ignore_whitespaces(expected_feature_name)) == 0
references = [reference(file, feature)]
add_error(references, "Feature name should be '#{expected_feature_name}'")
end
Expand All @@ -17,5 +17,9 @@ def title_case(value)
value = File.basename(value, '.feature')
value.split('_').collect(&:capitalize).join(' ')
end

def ignore_whitespaces(value)
value.delete('-').delete('_').delete(' ')
end
end
end

0 comments on commit a610aeb

Please sign in to comment.