cuke_linter 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.simplecov +8 -0
  3. data/.travis.yml +16 -14
  4. data/CHANGELOG.md +11 -2
  5. data/Gemfile +6 -6
  6. data/README.md +160 -148
  7. data/Rakefile +48 -23
  8. data/cuke_linter.gemspec +3 -0
  9. data/environments/cucumber_env.rb +10 -0
  10. data/environments/rspec_env.rb +3 -0
  11. data/lib/cuke_linter/formatters/pretty_formatter.rb +4 -0
  12. data/lib/cuke_linter/linters/example_without_name_linter.rb +24 -0
  13. data/lib/cuke_linter/linters/feature_without_scenarios_linter.rb +6 -4
  14. data/lib/cuke_linter/linters/outline_with_single_example_row_linter.rb +27 -0
  15. data/lib/cuke_linter/linters/test_with_too_many_steps_linter.rb +26 -0
  16. data/lib/cuke_linter/version.rb +4 -3
  17. data/lib/cuke_linter.rb +14 -1
  18. data/testing/cucumber/features/linters/default_linters.feature +8 -1
  19. data/testing/cucumber/features/linters/example_without_name.feature +27 -0
  20. data/testing/cucumber/features/linters/feature_without_scenarios.feature +7 -2
  21. data/testing/cucumber/features/linters/outline_with_single_example_row.feature +23 -0
  22. data/testing/cucumber/features/linters/test_with_too_many_steps.feature +33 -0
  23. data/testing/cucumber/step_definitions/action_steps.rb +5 -1
  24. data/testing/cucumber/step_definitions/setup_steps.rb +12 -0
  25. data/testing/cucumber/step_definitions/verification_steps.rb +3 -2
  26. data/testing/model_factory.rb +36 -0
  27. data/testing/rspec/spec/integration/cuke_linter_integration_spec.rb +6 -0
  28. data/testing/rspec/spec/integration/linters/example_without_name_linter_integration_spec.rb +8 -0
  29. data/testing/rspec/spec/integration/linters/outline_with_single_example_row_linter_integration_spec.rb +8 -0
  30. data/testing/rspec/spec/integration/linters/test_with_too_many_steps_linter_integration_spec.rb +8 -0
  31. data/testing/rspec/spec/unit/formatters/pretty_formatter_unit_spec.rb +5 -1
  32. data/testing/rspec/spec/unit/linters/example_without_name_linter_unit_spec.rb +83 -0
  33. data/testing/rspec/spec/unit/linters/feature_without_scenarios_linter_unit_spec.rb +52 -2
  34. data/testing/rspec/spec/unit/linters/outline_with_single_example_row_linter_unit_spec.rb +231 -0
  35. data/testing/rspec/spec/unit/linters/test_with_too_many_steps_linter_unit_spec.rb +156 -0
  36. metadata +57 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa45813f720250fdd2aaceab4b69148a6029074418331a2467c65fa544733067
4
- data.tar.gz: 89abfd15ecc91f630bc8ab247346d26f8a20ec1f14ce11af197db65725e1fbb6
3
+ metadata.gz: 499570d540f5b32c4774f299e4733b932c32c2b14f3b52d47f4bec6e99854edd
4
+ data.tar.gz: 8e4361c1f2cd7c7f11f503dbc1ba9deaa073f89a220fbcf8cd1ef1cc63ff1265
5
5
  SHA512:
6
- metadata.gz: 2e986813b8bdb0e86b358058ceac6c62939fce89bf1049599e18e51d5d88d5cbc244c1d172333ed93091e71353a9a859e60caad47aaa08b81e1ca716a9ee72e8
7
- data.tar.gz: 3e354fcea0ac508b7bbeb25eeea8ff40bf17e21c2897213dedca3ab76d2c0e9f0c53e2fa030daf0de097b7e3c88a9337647336b17c0e2c0facee0852d8c0c354
6
+ metadata.gz: 37d73b22eb4be9d13b98339b14605c6d5b99c4c3584bc03f8baada3f88035787d4427980b0308855277ceccd5aa846468cecb34e03ad6e5c20b936426dfc62ab
7
+ data.tar.gz: e678c2ee1ac758234b4fd461c4c46acc555e5752d886203189b155a451a294b74d40b971b5aa8415af3239fa402ead4f9352bc6188a245d9dede6b720e1d5a1c
data/.simplecov ADDED
@@ -0,0 +1,8 @@
1
+ SimpleCov.start do
2
+ root __dir__
3
+
4
+ add_filter '/testing/'
5
+ add_filter '/environments/'
6
+
7
+ merge_timeout 300
8
+ end
data/.travis.yml CHANGED
@@ -1,14 +1,16 @@
1
- os:
2
- - linux
3
- - osx
4
- sudo: false
5
-
6
- language: ruby
7
- rvm:
8
- - 2.3.3
9
- - 2.4.0
10
- - 2.5.1
11
-
12
- before_install: gem install bundler -v 1.16.2
13
-
14
- script: bundle exec rake cuke_linter:ci_build
1
+ os:
2
+ - linux
3
+ - osx
4
+ sudo: false
5
+
6
+ language: ruby
7
+ rvm:
8
+ - 2.3.3
9
+ - 2.4.0
10
+ - 2.5.1
11
+ - 2.6.0
12
+ - jruby-9.1.7.0
13
+
14
+ before_install: gem install bundler -v 1.16.2
15
+
16
+ script: bundle exec rake cuke_linter:ci_build
data/CHANGELOG.md CHANGED
@@ -8,6 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
 
9
9
  Nothing yet...
10
10
 
11
+ ## [0.2.0] - 2019-03-19
12
+
13
+ ### Added
14
+ - New linters
15
+ - ExampleWithoutNameLinter
16
+ - OutlineWithSingleExampleRowLinter
17
+ - TestWithTooManyStepsLinter
18
+
11
19
 
12
20
  ## [0.1.0] - 2019-02-10
13
21
 
@@ -15,5 +23,6 @@ Nothing yet...
15
23
  - Custom linters, formatters, and command line usability
16
24
 
17
25
 
18
- [Unreleased]: https://github.com/enkessler/cuke_linter/compare/v0.1.0...HEAD
19
- [0.1.0]: https://github.com/enkessler/cuke_linter/compare/2bbd3f29f4eb45b6e9ea7d47c5bb47182bf4fde7...HEAD
26
+ [Unreleased]: https://github.com/enkessler/cuke_linter/compare/v0.2.0...HEAD
27
+ [0.2.0]: https://github.com/enkessler/cuke_linter/compare/v0.1.0...v0.2.0
28
+ [0.1.0]: https://github.com/enkessler/cuke_linter/compare/2bbd3f29f4eb45b6e9ea7d47c5bb47182bf4fde7...v0.1.0
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in cuke_linter.gemspec
6
- gemspec
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in cuke_linter.gemspec
6
+ gemspec
data/README.md CHANGED
@@ -1,148 +1,160 @@
1
- [![Gem Version](https://badge.fury.io/rb/cuke_linter.svg)](https://rubygems.org/gems/cuke_linter)
2
- [![Build Status](https://travis-ci.org/enkessler/cuke_linter.svg?branch=master)](https://travis-ci.org/enkessler/cuke_linter)
3
- [![Build Status](https://ci.appveyor.com/api/projects/status/g5o70u747x073evy?svg=true)](https://ci.appveyor.com/project/enkessler/cuke-linter)
4
- [![Project License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/mit-license.php)
5
-
6
-
7
- # CukeLinter
8
-
9
- So you have started to use Cucumber to describe your system in the abstract, natural language style of Gherkin. But wait! All of your feature files are themselves code and that means that they may need the same protection from anti-patterns as the lower level source code of your system. Enter `cuke_linter`.
10
-
11
- This gem provides linting functionality for `.feature` files by building upon the modeling capabilities of the `cuke_modeler` gem. By passing models through a set of linters, reports can be generated that will inform you of potential bugs, style violations, or anything else that you can define as a problem via custom linters!
12
-
13
- ## Installation
14
-
15
- Add this line to your application's Gemfile:
16
-
17
- ```ruby
18
- gem 'cuke_linter'
19
- ```
20
-
21
- And then execute:
22
-
23
- $ bundle
24
-
25
- Or install it yourself as:
26
-
27
- $ gem install cuke_linter
28
-
29
- ## Usage
30
-
31
- The easiest way to use the gem is to use all of the defaults by invoking it from the command line directly.
32
-
33
- ```
34
- $ cuke_linter
35
- ```
36
-
37
- The linter can also be used inside of a Ruby script, like so:
38
-
39
- ```
40
- require 'cuke_linter'
41
-
42
- CukeLinter.lint
43
- ```
44
-
45
- The linting will happen against a tree of `CukeModeler` models that is generated based on the current directory. You can generate your own model tree and use that instead, if desired.
46
-
47
- Custom linters can be any object that responds to `#lint` and returns a collection of detected issues in the format of
48
-
49
- ```
50
- [
51
- { problem: 'some linting issue',
52
- location: 'path/to/file:line_number' },
53
- { problem: 'some linting issue',
54
- location: 'path/to/file:line_number' },
55
- # etc.
56
- ]
57
- ```
58
-
59
- Note that a linter will receive, in turn, *every model* in the model tree in order for it to have the chance to detect problems with it. Checking the model's class before attempting to lint it is recommended.
60
-
61
- Custom formatters can be any object that responds to `#format` and takes input data in the following format:
62
-
63
- ```
64
- [
65
- { linter: 'some linter name',
66
- problem: 'some linting issue',
67
- location: 'path/to/file:line_number' },
68
- { linter: 'some linter name',
69
- problem: 'some linting issue',
70
- location: 'path/to/file:line_number' },
71
- # etc.
72
- ]
73
- ```
74
-
75
- All formatted data will be output to STDOUT unless a file location is provided as an alternative.
76
-
77
- Below is an example of using non-default linting options.
78
-
79
- ```
80
- require 'cuke_linter'
81
-
82
- class MyCustomLinter
83
-
84
- def name
85
- 'MyCustomLinter'
86
- end
87
-
88
- def lint(model)
89
- return [] unless model.is_a?(CukeModeler::Scenario)
90
-
91
- if model.name.empty?
92
- [{ problem: 'Scenario has no name', location: "#{model.get_ancestor(:feature_file).path}:#{model.source_line}" }]
93
- else
94
- []
95
- end
96
- end
97
-
98
- end
99
-
100
- class MyCustomFormatter
101
-
102
- def format(linting_data)
103
- formatted_data = ''
104
-
105
- linting_data.each do |lint_item|
106
- formatted_data << "#{lint_item[:linter]}\n"
107
- formatted_data << " #{lint_item[:problem]}\n"
108
- formatted_data << " #{lint_item[:location]}\n"
109
- end
110
-
111
- formatted_data
112
- end
113
-
114
- end
115
-
116
- linter = MyCustomLinter.new
117
- formatter = MyCustomFormatter.new
118
- output_path = "#{__dir__}/my_report.txt"
119
- model_tree_root = CukeModeler::Directory.new(Dir.pwd)
120
-
121
- # Providing the formatter twice so that it also is printed to the console
122
- CukeLinter.lint(linters: [linter], formatters: [[formatter], [formatter, output_path]], model_tree: model_tree_root)
123
- ```
124
-
125
-
126
- For more information, see the documentation [here](https://app.cucumber.pro/projects/cuke_linter/documents/branch/master/).
127
-
128
-
129
- ## Development
130
-
131
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake cuke_linter:test_everything` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
132
-
133
- ## Contributing
134
-
135
- Bug reports and pull requests are welcome on GitHub at https://github.com/enkessler/cuke_linter.
136
-
137
- 1. Fork it
138
- 2. Create your feature branch (off of the development branch)
139
- `git checkout -b my-new-feature`
140
- 3. Commit your changes
141
- `git commit -am 'Add some feature'`
142
- 4. Push to the branch
143
- `git push origin my-new-feature`
144
- 5. Create new Pull Request
145
-
146
- ## License
147
-
148
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
1
+ Basic stuff:
2
+ [![Gem Version](https://badge.fury.io/rb/cuke_linter.svg)](https://rubygems.org/gems/cuke_linter)
3
+ [![Project License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/mit-license.php)
4
+ [![Downloads](https://img.shields.io/gem/dt/cuke_linter.svg)](https://rubygems.org/gems/cuke_linter)
5
+
6
+ User stuff:
7
+ [![Cucumber Docs](http://img.shields.io/badge/Documentation-Features-green.svg)](https://app.cucumber.pro/projects/cuke_linter)
8
+ [![Yard Docs](http://img.shields.io/badge/Documentation-API-blue.svg)](https://www.rubydoc.info/gems/cuke_linter)
9
+
10
+ Developer stuff:
11
+ [![Build Status](https://travis-ci.org/enkessler/cuke_linter.svg?branch=dev)](https://travis-ci.org/enkessler/cuke_linter)
12
+ [![Build Status](https://ci.appveyor.com/api/projects/status/g5o70u747x073evy?svg=true)](https://ci.appveyor.com/project/enkessler/cuke-linter)
13
+ [![Coverage Status](https://coveralls.io/repos/github/enkessler/cuke_linter/badge.svg?branch=dev)](https://coveralls.io/github/enkessler/cuke_linter?branch=dev)
14
+ [![Maintainability](https://api.codeclimate.com/v1/badges/d1b86760e59a457c8e73/maintainability)](https://codeclimate.com/github/enkessler/cuke_linter/maintainability)
15
+ [![Inline docs](http://inch-ci.org/github/enkessler/cuke_linter.svg?branch=dev)](https://inch-ci.org/github/enkessler/cuke_linter?branch=dev)
16
+
17
+ ---
18
+
19
+ # CukeLinter
20
+
21
+ So you have started to use Cucumber to describe your system in the abstract, natural language style of Gherkin. But wait! All of your feature files are themselves code and that means that they may need the same protection from anti-patterns as the lower level source code of your system. Enter `cuke_linter`.
22
+
23
+ This gem provides linting functionality for `.feature` files by building upon the modeling capabilities of the [cuke_modeler](https://github.com/enkessler/cuke_modeler) gem. By passing models through a set of linters, reports can be generated that will inform you of potential bugs, style violations, or anything else that you can define as a problem via custom linters!
24
+
25
+ ## Installation
26
+
27
+ Add this line to your application's Gemfile:
28
+
29
+ ```ruby
30
+ gem 'cuke_linter'
31
+ ```
32
+
33
+ And then execute:
34
+
35
+ $ bundle
36
+
37
+ Or install it yourself as:
38
+
39
+ $ gem install cuke_linter
40
+
41
+ ## Usage
42
+
43
+ The easiest way to use the gem is to use all of the defaults by invoking it from the command line directly.
44
+
45
+ ```
46
+ $ cuke_linter
47
+ ```
48
+
49
+ The linter can also be used inside of a Ruby script, like so:
50
+
51
+ ```
52
+ require 'cuke_linter'
53
+
54
+ CukeLinter.lint
55
+ ```
56
+
57
+ The linting will happen against a tree of `CukeModeler` models that is generated based on the current directory. You can generate your own model tree and use that instead, if desired.
58
+
59
+ Custom linters can be any object that responds to `#lint` and returns a collection of detected issues in the format of
60
+
61
+ ```
62
+ [
63
+ { problem: 'some linting issue',
64
+ location: 'path/to/file:line_number' },
65
+ { problem: 'some linting issue',
66
+ location: 'path/to/file:line_number' },
67
+ # etc.
68
+ ]
69
+ ```
70
+
71
+ Note that a linter will receive, in turn, *every model* in the model tree in order for it to have the chance to detect problems with it. Checking the model's class before attempting to lint it is recommended.
72
+
73
+ Custom formatters can be any object that responds to `#format` and takes input data in the following format:
74
+
75
+ ```
76
+ [
77
+ { linter: 'some linter name',
78
+ problem: 'some linting issue',
79
+ location: 'path/to/file:line_number' },
80
+ { linter: 'some linter name',
81
+ problem: 'some linting issue',
82
+ location: 'path/to/file:line_number' },
83
+ # etc.
84
+ ]
85
+ ```
86
+
87
+ All formatted data will be output to STDOUT unless a file location is provided as an alternative.
88
+
89
+ Below is an example of using non-default linting options.
90
+
91
+ ```
92
+ require 'cuke_linter'
93
+
94
+ class MyCustomLinter
95
+
96
+ def name
97
+ 'MyCustomLinter'
98
+ end
99
+
100
+ def lint(model)
101
+ return [] unless model.is_a?(CukeModeler::Scenario)
102
+
103
+ if model.name.empty?
104
+ [{ problem: 'Scenario has no name', location: "#{model.get_ancestor(:feature_file).path}:#{model.source_line}" }]
105
+ else
106
+ []
107
+ end
108
+ end
109
+
110
+ end
111
+
112
+ class MyCustomFormatter
113
+
114
+ def format(linting_data)
115
+ formatted_data = ''
116
+
117
+ linting_data.each do |lint_item|
118
+ formatted_data << "#{lint_item[:linter]}\n"
119
+ formatted_data << " #{lint_item[:problem]}\n"
120
+ formatted_data << " #{lint_item[:location]}\n"
121
+ end
122
+
123
+ formatted_data
124
+ end
125
+
126
+ end
127
+
128
+ linter = MyCustomLinter.new
129
+ formatter = MyCustomFormatter.new
130
+ output_path = "#{__dir__}/my_report.txt"
131
+ model_tree_root = CukeModeler::Directory.new(Dir.pwd)
132
+
133
+ # Providing the formatter twice so that it also is printed to the console
134
+ CukeLinter.lint(linters: [linter], formatters: [[formatter], [formatter, output_path]], model_tree: model_tree_root)
135
+ ```
136
+
137
+
138
+ For more information, see the documentation [here](https://app.cucumber.pro/projects/cuke_linter).
139
+
140
+
141
+ ## Development
142
+
143
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake cuke_linter:test_everything` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
144
+
145
+ ## Contributing
146
+
147
+ Bug reports and pull requests are welcome on GitHub at https://github.com/enkessler/cuke_linter.
148
+
149
+ 1. Fork it
150
+ 2. Create your feature branch **(off of the development branch)**
151
+ `git checkout -b my-new-feature`
152
+ 3. Commit your changes
153
+ `git commit -am 'Add some feature'`
154
+ 4. Push to the branch
155
+ `git push origin my-new-feature`
156
+ 5. Create new Pull Request
157
+
158
+ ## License
159
+
160
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,23 +1,48 @@
1
- require 'rake'
2
- require 'racatt'
3
-
4
-
5
- namespace 'racatt' do
6
- Racatt.create_tasks
7
- end
8
-
9
- namespace 'cuke_linter' do
10
-
11
- desc 'Run all of the tests'
12
- task :test_everything do
13
- rspec_args = '--pattern testing/rspec/spec/**/*_spec.rb'
14
- cucumber_args = "testing/cucumber/features -r environments/cucumber_env.rb -f progress -t 'not @wip'"
15
-
16
- Rake::Task['racatt:test_everything'].invoke(rspec_args, cucumber_args)
17
- end
18
-
19
- task :ci_build => 'cuke_linter:test_everything'
20
- end
21
-
22
-
23
- task :default => 'cuke_linter:test_everything'
1
+ require 'rake'
2
+ require 'racatt'
3
+ require 'coveralls/rake/task'
4
+ require 'colorize'
5
+
6
+
7
+ namespace 'racatt' do
8
+ Racatt.create_tasks
9
+ end
10
+
11
+ namespace 'cuke_linter' do
12
+
13
+ desc 'Removes the current code coverage data'
14
+ task :clear_coverage do
15
+ code_coverage_directory = "#{__dir__}/coverage"
16
+
17
+ FileUtils.remove_dir(code_coverage_directory, true)
18
+ end
19
+
20
+ desc 'Check documentation with RDoc'
21
+ task :check_documentation do
22
+ output = `rdoc lib`
23
+ puts output
24
+
25
+ if output =~ /100.00% documented/
26
+ puts 'All code documented'.green
27
+ else
28
+ raise 'Parts of the gem are undocumented'.red
29
+ end
30
+ end
31
+
32
+ desc 'Run all of the tests'
33
+ task :test_everything => [:clear_coverage] do
34
+ rspec_args = '--pattern "testing/rspec/spec/**/*_spec.rb"'
35
+ cucumber_args = "testing/cucumber/features -r environments/cucumber_env.rb -f progress -t 'not @wip'"
36
+
37
+ Rake::Task['racatt:test_everything'].invoke(rspec_args, cucumber_args)
38
+ end
39
+
40
+ # creates coveralls:push task
41
+ Coveralls::RakeTask.new
42
+
43
+ desc 'The task that CI will run. Do not run locally.'
44
+ task :ci_build => ['cuke_linter:test_everything', 'coveralls:push']
45
+ end
46
+
47
+
48
+ task :default => 'cuke_linter:test_everything'
data/cuke_linter.gemspec CHANGED
@@ -31,4 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "rake", "~> 12.0"
32
32
  spec.add_development_dependency "require_all", "~> 2.0"
33
33
  spec.add_development_dependency "rspec", "~> 3.0"
34
+ spec.add_development_dependency 'simplecov', '< 1.0.0'
35
+ spec.add_development_dependency 'coveralls', '< 1.0.0'
36
+ spec.add_development_dependency 'colorize', '< 1.0.0'
34
37
  end
@@ -1,4 +1,14 @@
1
+ require 'simplecov'
2
+ SimpleCov.command_name('cucumber_tests')
3
+
1
4
  require_relative 'common_env'
2
5
  require 'cucumber'
3
6
 
4
7
  require_all 'testing/cucumber/step_definitions'
8
+
9
+
10
+ at_exit do
11
+ CukeLinter::FileHelper.created_directories.each do |dir_path|
12
+ FileUtils.remove_entry(dir_path, true)
13
+ end
14
+ end
@@ -1,3 +1,6 @@
1
+ require 'simplecov'
2
+ SimpleCov.command_name('rspec_tests')
3
+
1
4
  require_relative 'common_env'
2
5
  require 'rspec'
3
6
  require 'rubygems/mock_gem_ui'
@@ -1,6 +1,10 @@
1
1
  module CukeLinter
2
+
3
+ # Formats linting data into organized, user readable text
4
+
2
5
  class PrettyFormatter
3
6
 
7
+ # Formats the given linting data
4
8
  def format(data)
5
9
  categorized_problems = Hash.new { |linters, linter_name| linters[linter_name] = Hash.new { |problems, problem| problems[problem] = [] } }
6
10
 
@@ -0,0 +1,24 @@
1
+ module CukeLinter
2
+
3
+ # A linter that detects unnamed example groups
4
+
5
+ class ExampleWithoutNameLinter
6
+
7
+ # Returns the name of the linter
8
+ def name
9
+ 'ExampleWithoutNameLinter'
10
+ end
11
+
12
+ # Lints the given model and returns linting data about said model
13
+ def lint(model)
14
+ return [] unless model.is_a?(CukeModeler::Example)
15
+
16
+ if model.name.nil? || model.name.empty?
17
+ [{ problem: 'Example has no name', location: "#{model.get_ancestor(:feature_file).path}:#{model.source_line}" }]
18
+ else
19
+ []
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -1,17 +1,19 @@
1
1
  module CukeLinter
2
+
3
+ # A linter that detects empty features
4
+
2
5
  class FeatureWithoutScenariosLinter
3
- # # class FeatureWithoutScenariosLinter < BaseLinter
4
- #
5
- # # targets :features
6
6
 
7
+ # Returns the name of the linter
7
8
  def name
8
9
  'FeatureWithoutScenariosLinter'
9
10
  end
10
11
 
12
+ # Lints the given model and returns linting data about said model
11
13
  def lint(model)
12
14
  return [] unless model.is_a?(CukeModeler::Feature)
13
15
 
14
- if model.tests.empty?
16
+ if model.tests.nil? || model.tests.empty?
15
17
  [{ problem: 'Feature has no scenarios', location: "#{model.parent_model.path}:#{model.source_line}" }]
16
18
  else
17
19
  []
@@ -0,0 +1,27 @@
1
+ module CukeLinter
2
+
3
+ # A linter that detects outlines that don't have multiple example rows
4
+
5
+ class OutlineWithSingleExampleRowLinter
6
+
7
+ # Returns the name of the linter
8
+ def name
9
+ 'OutlineWithSingleExampleRowLinter'
10
+ end
11
+
12
+ # Lints the given model and returns linting data about said model
13
+ def lint(model)
14
+ return [] unless model.is_a?(CukeModeler::Outline)
15
+ return [] if model.examples.nil?
16
+
17
+ examples_rows = model.examples.collect(&:argument_rows).flatten
18
+
19
+ if examples_rows.count == 1
20
+ [{ problem: 'Outline has only one example row', location: "#{model.get_ancestor(:feature_file).path}:#{model.source_line}" }]
21
+ else
22
+ []
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ module CukeLinter
2
+
3
+ # A linter that detects scenarios and outlines that have too many steps
4
+
5
+ class TestWithTooManyStepsLinter
6
+
7
+ # Returns the name of the linter
8
+ def name
9
+ 'TestWithTooManyStepsLinter'
10
+ end
11
+
12
+ # Lints the given model and returns linting data about said model
13
+ def lint(model)
14
+ return [] unless model.is_a?(CukeModeler::Scenario) || model.is_a?(CukeModeler::Outline)
15
+
16
+ step_count = model.steps.nil? ? 0 : model.steps.count
17
+
18
+ if step_count > 10
19
+ [{ problem: "Test has too many steps. #{step_count} steps found (max 10)", location: "#{model.get_ancestor(:feature_file).path}:#{model.source_line}" }]
20
+ else
21
+ []
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -1,3 +1,4 @@
1
- module CukeLinter
2
- VERSION = "0.1.0"
3
- end
1
+ module CukeLinter
2
+ # The release version of this gem
3
+ VERSION = "0.2.0"
4
+ end