chutney 2.0.3.1 → 3.0.0.beta.2

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +7 -1
  3. data/.rufo +1 -0
  4. data/Gemfile +2 -0
  5. data/README.md +6 -1
  6. data/Rakefile +2 -0
  7. data/chutney.gemspec +14 -6
  8. data/config/chutney.yml +4 -0
  9. data/config/cucumber.yml +1 -0
  10. data/docs/usage/rules.md +7 -1
  11. data/exe/chutney +20 -0
  12. data/lib/chutney.rb +20 -20
  13. data/lib/chutney/configuration.rb +7 -1
  14. data/lib/chutney/formatter.rb +2 -0
  15. data/lib/chutney/formatter/json_formatter.rb +2 -0
  16. data/lib/chutney/formatter/pie_formatter.rb +2 -0
  17. data/lib/chutney/formatter/rainbow_formatter.rb +6 -3
  18. data/lib/chutney/issue.rb +2 -0
  19. data/lib/chutney/linter.rb +65 -61
  20. data/lib/chutney/linter/avoid_full_stop.rb +3 -1
  21. data/lib/chutney/linter/avoid_outline_for_single_example.rb +8 -6
  22. data/lib/chutney/linter/avoid_scripting.rb +6 -4
  23. data/lib/chutney/linter/avoid_typographers_quotes.rb +39 -0
  24. data/lib/chutney/linter/background_does_more_than_setup.rb +8 -6
  25. data/lib/chutney/linter/background_requires_multiple_scenarios.rb +6 -3
  26. data/lib/chutney/linter/bad_scenario_name.rb +4 -2
  27. data/lib/chutney/linter/empty_feature_file.rb +10 -0
  28. data/lib/chutney/linter/file_name_differs_feature_name.rb +4 -2
  29. data/lib/chutney/linter/givens_after_background.rb +5 -6
  30. data/lib/chutney/linter/invalid_file_name.rb +2 -0
  31. data/lib/chutney/linter/invalid_step_flow.rb +7 -7
  32. data/lib/chutney/linter/missing_example_name.rb +7 -5
  33. data/lib/chutney/linter/missing_feature_description.rb +6 -3
  34. data/lib/chutney/linter/missing_feature_name.rb +5 -2
  35. data/lib/chutney/linter/missing_scenario_name.rb +3 -4
  36. data/lib/chutney/linter/missing_test_action.rb +3 -1
  37. data/lib/chutney/linter/missing_verification.rb +3 -1
  38. data/lib/chutney/linter/required_tags_starts_with.rb +2 -0
  39. data/lib/chutney/linter/same_tag_for_all_scenarios.rb +11 -10
  40. data/lib/chutney/linter/scenario_names_match.rb +4 -3
  41. data/lib/chutney/linter/tag_used_multiple_times.rb +2 -0
  42. data/lib/chutney/linter/too_clumsy.rb +3 -1
  43. data/lib/chutney/linter/too_long_step.rb +4 -2
  44. data/lib/chutney/linter/too_many_different_tags.rb +4 -2
  45. data/lib/chutney/linter/too_many_steps.rb +4 -2
  46. data/lib/chutney/linter/too_many_tags.rb +2 -0
  47. data/lib/chutney/linter/unique_scenario_names.rb +3 -3
  48. data/lib/chutney/linter/unknown_variable.rb +13 -13
  49. data/lib/chutney/linter/unused_variable.rb +13 -13
  50. data/lib/chutney/linter/use_background.rb +17 -16
  51. data/lib/chutney/linter/use_outline.rb +8 -7
  52. data/lib/chutney/version.rb +3 -1
  53. data/lib/config/locales/en.yml +6 -0
  54. data/spec/chutney_spec.rb +2 -0
  55. data/spec/spec_helper.rb +2 -0
  56. metadata +37 -17
@@ -1,15 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'chutney/linter'
2
4
 
3
5
  module Chutney
4
6
  # service class to lint for tags used multiple times
5
7
  class ScenarioNamesMatch < Linter
6
- MESSAGE = 'Scenario Name does not match pattern'.freeze
8
+ MESSAGE = 'Scenario Name does not match pattern'
7
9
 
8
10
 
9
11
  def lint
10
12
  scenarios do |feature, scenario|
11
- name = scenario.key?(:name) ? scenario[:name].strip : ''
12
- next unless (name =~ /#{configuration['Matcher']}/).nil?
13
+ next unless (scenario.name =~ /#{configuration['Matcher']}/).nil?
13
14
 
14
15
  add_issue(
15
16
  I18n.t('linters.scenario_names_match',
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Chutney
2
4
  # service class to lint for tags used multiple times
3
5
  class TagUsedMultipleTimes < Linter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'chutney/linter'
2
4
 
3
5
  module Chutney
@@ -5,7 +7,7 @@ module Chutney
5
7
  class TooClumsy < Linter
6
8
  def lint
7
9
  filled_scenarios do |feature, scenario|
8
- characters = scenario[:steps].map { |step| step[:text].length }.inject(0, :+)
10
+ characters = scenario.steps.map { |step| step.text.length }.inject(0, :+)
9
11
  next if characters < 400
10
12
 
11
13
  add_issue(
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Chutney
2
4
  # service class to lint for too long steps
3
5
  class TooLongStep < Linter
4
6
  def lint
5
7
  steps do |feature, scenario, step|
6
- next if step[:text].length <= maxlength
8
+ next if step.text.length <= maxlength
7
9
 
8
10
  add_issue(
9
- I18n.t('linters.too_long_step', length: step[:text].length, max: maxlength),
11
+ I18n.t('linters.too_long_step', length: step.text.length, max: maxlength),
10
12
  feature, scenario
11
13
  )
12
14
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Chutney
2
4
  # service class to lint for too many different tags
3
5
  class TooManyDifferentTags < Linter
@@ -16,9 +18,9 @@ module Chutney
16
18
  end
17
19
 
18
20
  def all_tags
19
- return [] unless feature.include?(:children)
21
+ return [] unless feature&.scenarios
20
22
 
21
- tags_for(feature) + feature[:children].map { |scenario| tags_for(scenario) }.flatten
23
+ tags_for(feature) + feature.scenarios.map { |scenario| tags_for(scenario) }.flatten
22
24
  end
23
25
  end
24
26
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Chutney
2
4
  # service class to lint for too many steps
3
5
  class TooManySteps < Linter
4
6
  def lint
5
7
  filled_scenarios do |feature, scenario|
6
- next if scenario[:steps].length <= maxcount
8
+ next if scenario.steps.length <= maxcount
7
9
 
8
10
  add_issue(
9
- I18n.t('linters.too_many_steps', count: scenario[:steps].length, max: maxcount),
11
+ I18n.t('linters.too_many_steps', count: scenario.steps.length, max: maxcount),
10
12
  feature
11
13
  )
12
14
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Chutney
2
4
  # service class to lint for too many tags
3
5
  class TooManyTags < Linter
@@ -1,12 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Chutney
2
4
  # service class to lint for unique scenario names
3
5
  class UniqueScenarioNames < Linter
4
6
  def lint
5
7
  references_by_name = {}
6
8
  scenarios do |feature, scenario|
7
- next unless scenario.key? :name
8
-
9
- name = scenario[:name]
9
+ name = scenario.name
10
10
  if references_by_name[name]
11
11
  issue(name, references_by_name[name], scenario)
12
12
  else
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Chutney
2
4
  # service class to lint for unknown variables
3
5
  class UnknownVariable < Linter
4
6
  def lint
5
7
  filled_scenarios do |feature, scenario|
6
8
  known_vars = Set.new(known_variables(scenario))
7
- scenario[:steps].each do |step|
9
+ scenario.steps.each do |step|
8
10
  step_vars(step).each do |used_var|
9
11
  next if known_vars.include? used_var
10
12
 
@@ -17,17 +19,17 @@ module Chutney
17
19
  end
18
20
 
19
21
  def step_vars(step)
20
- vars = gather_vars step[:text]
21
- return vars unless step.include? :argument
22
+ vars = gather_vars step.text
23
+ return vars unless step.block
22
24
 
23
- vars + gather_vars_from_argument(step[:argument])
25
+ vars + gather_vars_from_argument(step.block)
24
26
  end
25
27
 
26
28
  def gather_vars_from_argument(argument)
27
- return gather_vars argument[:content] if argument[:type] == :DocString
28
-
29
- (argument[:rows] || []).map do |row|
30
- row[:cells].map { |value| gather_vars value[:value] }.flatten
29
+ return gather_vars argument.content if argument.is_a? CukeModeler::DocString
30
+
31
+ argument.rows.map do |row|
32
+ row.cells.map { |cell| gather_vars cell.value }.flatten
31
33
  end.flatten
32
34
  end
33
35
 
@@ -36,11 +38,9 @@ module Chutney
36
38
  end
37
39
 
38
40
  def known_variables(scenario)
39
- (scenario[:examples] || []).map do |example|
40
- next unless example.key? :tableHeader
41
-
42
- example[:tableHeader][:cells].map { |cell| cell[:value].strip }
43
- end.flatten
41
+ return [] unless scenario.is_a? CukeModeler::Outline
42
+
43
+ scenario.examples.map { |ex| ex.rows.first.cells.map(&:value) }.flatten
44
44
  end
45
45
  end
46
46
  end
@@ -1,14 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Chutney
2
4
  # service class to lint for unused variables
3
5
  class UnusedVariable < Linter
4
6
  def lint
5
7
  scenarios do |feature, scenario|
6
- next unless scenario.key?(:examples)
7
-
8
- scenario[:examples].each do |example|
9
- next unless example.key?(:tableHeader)
8
+ next unless scenario.is_a? CukeModeler::Outline
9
+
10
+ scenario.examples.each do |example|
10
11
 
11
- example[:tableHeader][:cells].map { |cell| cell[:value] }.each do |variable|
12
+ example.rows.first.cells.map(&:value).each do |variable|
12
13
  next if used?(variable, scenario)
13
14
 
14
15
  add_issue(I18n.t('linters.unused_variable', variable: variable), feature, scenario, example)
@@ -19,11 +20,10 @@ module Chutney
19
20
 
20
21
  def used?(variable, scenario)
21
22
  variable = "<#{variable}>"
22
- return false unless scenario.key? :steps
23
23
 
24
- scenario[:steps].each do |step|
25
- return true if step[:text].include? variable
26
- next unless step.include? :argument
24
+ scenario.steps.each do |step|
25
+ return true if step.text.include? variable
26
+ next unless step.block
27
27
  return true if used_in_docstring?(variable, step)
28
28
  return true if used_in_table?(variable, step)
29
29
  end
@@ -31,14 +31,14 @@ module Chutney
31
31
  end
32
32
 
33
33
  def used_in_docstring?(variable, step)
34
- step[:argument][:type] == :DocString && step[:argument][:content].include?(variable)
34
+ step.block.is_a?(CukeModeler::DocString) && step.block.content.include?(variable)
35
35
  end
36
36
 
37
37
  def used_in_table?(variable, step)
38
- return false unless step[:argument][:type] == :DataTable
38
+ return false unless step.block.is_a?(CukeModeler::Table)
39
39
 
40
- step[:argument][:rows].each do |row|
41
- row[:cells].each { |value| return true if value[:value].include?(variable) }
40
+ step.block.rows.each do |row|
41
+ row.cells.each { |cell| return true if cell.value.include?(variable) }
42
42
  end
43
43
  false
44
44
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Chutney
2
4
  # service class to lint for using background
3
5
  class UseBackground < Linter
@@ -13,14 +15,13 @@ module Chutney
13
15
  end
14
16
 
15
17
  def gather_givens
16
- return unless feature.include? :children
18
+ return unless feature.children
17
19
 
18
20
  has_non_given_step = false
19
- feature[:children].each do |scenario|
20
- next unless scenario.include? :steps
21
- next if scenario[:steps].empty?
21
+ scenarios do |_feature, scenario|
22
+ next unless scenario.steps
22
23
 
23
- has_non_given_step = true unless given_word?(scenario[:steps].first[:keyword])
24
+ has_non_given_step = true unless given_word?(scenario.steps.first.keyword)
24
25
  end
25
26
  return if has_non_given_step
26
27
 
@@ -29,15 +30,13 @@ module Chutney
29
30
  result
30
31
  end
31
32
 
32
- def expanded_steps
33
- feature[:children].each do |scenario|
34
- next unless scenario[:type] != :Background
35
- next unless scenario.include? :steps
36
- next if scenario[:steps].empty?
33
+ def expanded_steps(&block)
34
+ scenarios do |_feature, scenario|
35
+ next unless scenario.steps
37
36
 
38
- prototypes = [render_step(scenario[:steps].first)]
39
- prototypes = expand_examples(scenario[:examples], prototypes) if scenario.key? :examples
40
- prototypes.each { |prototype| yield prototype }
37
+ prototypes = [render_step(scenario.steps.first)]
38
+ prototypes = expand_examples(scenario.examples, prototypes) if scenario.is_a? CukeModeler::Outline
39
+ prototypes.each(&block)
41
40
  end
42
41
  end
43
42
 
@@ -50,10 +49,12 @@ module Chutney
50
49
 
51
50
  def expand_outlines(sentence, example)
52
51
  result = []
53
- headers = example[:tableHeader][:cells].map { |cell| cell[:value] }
54
- example[:tableBody].each do |row| # .slice(1, example[:tableBody].length).each do |row|
52
+ headers = example.rows.first.cells.map(&:value)
53
+ example.rows.each_with_index do |row, idx|
54
+ next if idx.zero? # skip the header
55
+
55
56
  modified_sentence = sentence.dup
56
- headers.zip(row[:cells].map { |cell| cell[:value] }).map do |key, value|
57
+ headers.zip(row.cells.map(&:value)).map do |key, value|
57
58
  modified_sentence.gsub!("<#{key}>", value)
58
59
  end
59
60
  result.push modified_sentence
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Chutney
2
4
  # service class to lint for using outline
3
5
  class UseOutline < Linter
@@ -36,12 +38,11 @@ module Chutney
36
38
 
37
39
  def gather_scenarios(feature)
38
40
  scenarios = []
39
- return scenarios unless feature.include? :children
41
+ return scenarios if feature.nil? || !feature.tests
40
42
 
41
- feature[:children].each do |scenario|
42
- next unless scenario[:type] == :Scenario
43
- next unless scenario.include? :steps
44
- next if scenario[:steps].empty?
43
+ scenarios do |_feature, scenario|
44
+ next unless scenario.steps
45
+ next if scenario.steps.empty?
45
46
 
46
47
  scenarios.push generate_reference(feature, scenario)
47
48
  end
@@ -51,8 +52,8 @@ module Chutney
51
52
  def generate_reference(feature, scenario)
52
53
  reference = {}
53
54
  reference[:reference] = location(feature, scenario, nil)
54
- reference[:name] = "#{scenario[:keyword]}: #{scenario[:name]}"
55
- reference[:text] = scenario[:steps].map { |step| render_step(step) }.join ' '
55
+ reference[:name] = "#{scenario.keyword}: #{scenario.name}"
56
+ reference[:text] = scenario.steps.map { |step| render_step(step) }.join ' '
56
57
  reference
57
58
  end
58
59
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Chutney
2
- VERSION = '2.0.3.1'.freeze
4
+ VERSION = '3.0.0.beta.2'
3
5
  end
@@ -11,12 +11,18 @@ en:
11
11
  avoid_scripting: >-
12
12
  You have %{count} When steps when you should only have one.
13
13
  Be careful not to add And steps following a When.
14
+ avoid_typographers_quotes: >-
15
+ You are using typographers quotation marks (curly quotes).
16
+ Make sure you intend to use this character and not a neutral quote
17
+ (straight quote) instead.
14
18
  background_does_more_than_setup: >-
15
19
  The Background does more than setup. It should only contain Given steps.
16
20
  background_requires_multiple_scenarios: >-
17
21
  Avoid using Background if you only have a single scenario.
18
22
  bad_scenario_name: >-
19
23
  You should avoid using words like '%{word}' in your scenario names.
24
+ empty_feature_file: >-
25
+ The feature file is empty
20
26
  file_name_differs_feature_name: >-
21
27
  The name of the feature should reflect the file name. Consider renaming this feature
22
28
  to '%{expected}'.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'chutney'
2
4
 
3
5
  describe Chutney::ChutneyLint do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'simplecov'
2
4
  require 'coveralls'
3
5
  # Coveralls.wear!
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chutney
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3.1
4
+ version: 3.0.0.beta.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nigel Brookes-Thomas
8
8
  - Stefan Rohe
9
9
  - Nishtha Argawal
10
10
  - John Gluck
11
- autorequire:
11
+ autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2020-04-28 00:00:00.000000000 Z
14
+ date: 2020-09-17 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: amatch
@@ -28,19 +28,19 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: 0.4.0
30
30
  - !ruby/object:Gem::Dependency
31
- name: gherkin
31
+ name: cuke_modeler
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
34
  - - "~>"
35
35
  - !ruby/object:Gem::Version
36
- version: 5.1.0
36
+ version: '3.3'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - "~>"
42
42
  - !ruby/object:Gem::Version
43
- version: 5.1.0
43
+ version: '3.3'
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: i18n
46
46
  requirement: !ruby/object:Gem::Requirement
@@ -99,6 +99,20 @@ dependencies:
99
99
  version: '0.8'
100
100
  - !ruby/object:Gem::Dependency
101
101
  name: cucumber
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
106
+ version: '5.1'
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '5.1'
114
+ - !ruby/object:Gem::Dependency
115
+ name: pry-byebug
102
116
  requirement: !ruby/object:Gem::Requirement
103
117
  requirements:
104
118
  - - "~>"
@@ -159,14 +173,14 @@ dependencies:
159
173
  requirements:
160
174
  - - "~>"
161
175
  - !ruby/object:Gem::Version
162
- version: 0.82.0
176
+ version: 0.89.0
163
177
  type: :development
164
178
  prerelease: false
165
179
  version_requirements: !ruby/object:Gem::Requirement
166
180
  requirements:
167
181
  - - "~>"
168
182
  - !ruby/object:Gem::Version
169
- version: 0.82.0
183
+ version: 0.89.0
170
184
  - !ruby/object:Gem::Dependency
171
185
  name: rspec
172
186
  requirement: !ruby/object:Gem::Requirement
@@ -181,8 +195,10 @@ dependencies:
181
195
  - - "~>"
182
196
  - !ruby/object:Gem::Version
183
197
  version: '3.8'
184
- description: A linter for your Cucumber features. It supports any spoken language
185
- Cucumber v3 supports.
198
+ description: A linter for your Cucumber features. Making sure you have nice, expressible
199
+ Gherkin is essential is making sure you have a readable test-base. Chutney is designed
200
+ to sniff out smells in your feature files. It supports any spoken language Cucumber
201
+ supports.
186
202
  email:
187
203
  - nigel@brookes-thomas.co.uk
188
204
  executables:
@@ -195,12 +211,14 @@ files:
195
211
  - ".gitignore"
196
212
  - ".rspec"
197
213
  - ".rubocop.yml"
214
+ - ".rufo"
198
215
  - Gemfile
199
216
  - LICENSE.txt
200
217
  - README.md
201
218
  - Rakefile
202
219
  - chutney.gemspec
203
220
  - config/chutney.yml
221
+ - config/cucumber.yml
204
222
  - docs/.keep
205
223
  - docs/_config.yml
206
224
  - docs/credits.md
@@ -228,9 +246,11 @@ files:
228
246
  - lib/chutney/linter/avoid_full_stop.rb
229
247
  - lib/chutney/linter/avoid_outline_for_single_example.rb
230
248
  - lib/chutney/linter/avoid_scripting.rb
249
+ - lib/chutney/linter/avoid_typographers_quotes.rb
231
250
  - lib/chutney/linter/background_does_more_than_setup.rb
232
251
  - lib/chutney/linter/background_requires_multiple_scenarios.rb
233
252
  - lib/chutney/linter/bad_scenario_name.rb
253
+ - lib/chutney/linter/empty_feature_file.rb
234
254
  - lib/chutney/linter/file_name_differs_feature_name.rb
235
255
  - lib/chutney/linter/givens_after_background.rb
236
256
  - lib/chutney/linter/invalid_file_name.rb
@@ -266,23 +286,23 @@ metadata:
266
286
  homepage_uri: https://billyruffian.github.io/chutney/
267
287
  source_code_uri: https://github.com/BillyRuffian/chutney
268
288
  changelog_uri: https://github.com/BillyRuffian/chutney/releases
269
- post_install_message:
289
+ post_install_message:
270
290
  rdoc_options: []
271
291
  require_paths:
272
292
  - lib
273
293
  required_ruby_version: !ruby/object:Gem::Requirement
274
294
  requirements:
275
- - - ">="
295
+ - - "~>"
276
296
  - !ruby/object:Gem::Version
277
- version: '0'
297
+ version: '2.6'
278
298
  required_rubygems_version: !ruby/object:Gem::Requirement
279
299
  requirements:
280
- - - ">="
300
+ - - ">"
281
301
  - !ruby/object:Gem::Version
282
- version: '0'
302
+ version: 1.3.1
283
303
  requirements: []
284
304
  rubygems_version: 3.1.2
285
- signing_key:
305
+ signing_key:
286
306
  specification_version: 4
287
- summary: A linter for English language Gherkin
307
+ summary: A linter for multi-lingual Gherkin
288
308
  test_files: []