gherkin_lint 0.0.3 → 0.0.4

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gherkin_lint.rb +86 -13
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3daa67e7b175ac10bdcc6698e7d49f45a294c4e
4
- data.tar.gz: 5c7c0835a63af9a94fe99056f0a89f3d798dadbe
3
+ metadata.gz: 1d0d99d8c45ff4c504466326ac7f7dea6be3bcab
4
+ data.tar.gz: 680a25d303d1502e64218883dfaf01bbf8dd0eba
5
5
  SHA512:
6
- metadata.gz: 5538c69efcd96aeabc32aa6bbb4746edddc89e71f8823c00ecdc3e6862529b406dd738a8748a8a3ed530a233eb7aff669b92aaf83494008a9efebdbf3a98cfd5
7
- data.tar.gz: a867fa1ea399b7f5f564a0be95c411df25582cc8a0d06278b29f18ddc03e4dbecdb98c3c429e64ad43fcad59511172053085410936ef38d85342b98b8f15729f
6
+ metadata.gz: 3690cf08438bb34015d64a2e9218c60061ba4bfcb706346fe13a23ebaffe2a746f13b8bd4beb339238c6ab6340ec65ecc330f498a682f85e69c4a2979364e842
7
+ data.tar.gz: 63bf4c8d24cd0222a38efe34a0c30cc5eaa3b83574c9b8e6391df1034e4ce208ef267021509c9b9283e45263ff899096da9890d6e28a34eb5a457e1a94025f9e
@@ -128,6 +128,22 @@ class GherkinLint
128
128
  def add_issue(references, description = nil)
129
129
  @issues.push Issue.new(name, references, description)
130
130
  end
131
+
132
+ def gather_tags(element)
133
+ return [] unless element.include? 'tags'
134
+ element['tags'].map { |tag| tag['name'][1..-1] }
135
+ end
136
+
137
+ def render_step(step)
138
+ value = "#{step['keyword']}#{step['name']}"
139
+ value += "\n#{step['doc_string']['value']}" if step.include? 'doc_string'
140
+ if step.include? 'rows'
141
+ value += step['rows'].map do |row|
142
+ row['cells'].join '|'
143
+ end.join "|\n"
144
+ end
145
+ value
146
+ end
131
147
  end
132
148
 
133
149
  # service class to lint for unique scenario names
@@ -159,6 +175,53 @@ class GherkinLint
159
175
  end
160
176
  end
161
177
 
178
+ # service class to lint for too many tags
179
+ class TooManyTags < Linter
180
+ def lint
181
+ scenarios do |file, feature, scenario|
182
+ tags = gather_tags(feature) + gather_tags(scenario)
183
+ next unless tags.length >= 3
184
+ references = [reference(file, feature, scenario)]
185
+ add_issue(references, "Used #{tags.length} Tags")
186
+ end
187
+ end
188
+ end
189
+
190
+ # service class to lint for too many different tags
191
+ class TooManyDifferentTags < Linter
192
+ def lint
193
+ overall_tags = []
194
+ overall_references = []
195
+ features do |file, feature|
196
+ tags = tags_for_feature(feature)
197
+ overall_tags += tags
198
+ references = [reference(file, feature)]
199
+ overall_references += references unless tags.empty?
200
+ warn_single_feature(references, tags)
201
+ end
202
+ warn_across_all_features(overall_references, overall_tags)
203
+ end
204
+
205
+ def warn_single_feature(references, tags)
206
+ tags.uniq!
207
+ references.uniq!
208
+ return false unless tags.length >= 3
209
+ add_issue(references, "Used #{tags.length} Tags within single Feature")
210
+ end
211
+
212
+ def warn_across_all_features(references, tags)
213
+ tags.uniq!
214
+ references.uniq!
215
+ return false unless tags.length >= 10
216
+ add_issue(references, "Used #{tags.length} Tags across all Features")
217
+ end
218
+
219
+ def tags_for_feature(feature)
220
+ return [] unless feature.include? 'elements'
221
+ gather_tags(feature) + feature['elements'].map { |scenario| gather_tags(scenario) }.flatten
222
+ end
223
+ end
224
+
162
225
  # service class to lint for too long steps
163
226
  class TooLongStep < Linter
164
227
  def lint
@@ -221,6 +284,24 @@ class GherkinLint
221
284
  end
222
285
  end
223
286
 
287
+ # service class to lint for file name differs feature name
288
+ class FileNameDiffersFeatureName < Linter
289
+ def lint
290
+ features do |file, feature|
291
+ next unless feature.include? 'name'
292
+ expected_feature_name = title_case file
293
+ next unless feature['name'] != expected_feature_name
294
+ references = [reference(file, feature)]
295
+ add_issue(references, "Feature name should be '#{expected_feature_name}'")
296
+ end
297
+ end
298
+
299
+ def title_case(value)
300
+ value = File.basename(value, '.feature')
301
+ value.split('_').collect(&:capitalize).join(' ')
302
+ end
303
+ end
304
+
224
305
  # service class to lint for missing feature descriptions
225
306
  class MissingFeatureDescription < Linter
226
307
  def lint
@@ -459,7 +540,7 @@ class GherkinLint
459
540
  next if scenario['keyword'] == 'Background'
460
541
  next unless scenario.include? 'steps'
461
542
  return [] unless scenario['steps'].first['keyword'] == 'Given '
462
- result.push scenario['steps'].first['name']
543
+ result.push render_step scenario['steps'].first
463
544
  end
464
545
  result
465
546
  end
@@ -503,20 +584,9 @@ class GherkinLint
503
584
  def generate_reference(file, feature, scenario)
504
585
  reference = {}
505
586
  reference[:reference] = reference(file, feature, scenario)
506
- reference[:text] = scenario['steps'].map { |step| render(step) }.join ' '
587
+ reference[:text] = scenario['steps'].map { |step| render_step(step) }.join ' '
507
588
  reference
508
589
  end
509
-
510
- def render(step)
511
- value = "#{step['keyword']}#{step['name']}"
512
- value += "\n#{step['doc_string']['value']}" if step.include? 'doc_string'
513
- if step.include? 'rows'
514
- value += step['rows'].map do |row|
515
- row['cells'].join '|'
516
- end.join "|\n"
517
- end
518
- value
519
- end
520
590
  end
521
591
 
522
592
  LINTER = [
@@ -524,6 +594,7 @@ class GherkinLint
524
594
  BackgroundDoesMoreThanSetup,
525
595
  BackgroundRequiresMultipleScenarios,
526
596
  BadScenarioName,
597
+ FileNameDiffersFeatureName,
527
598
  MissingExampleName,
528
599
  MissingFeatureDescription,
529
600
  MissingFeatureName,
@@ -533,7 +604,9 @@ class GherkinLint
533
604
  InvalidFileName,
534
605
  InvalidStepFlow,
535
606
  TooClumsy,
607
+ TooManyDifferentTags,
536
608
  TooManySteps,
609
+ TooManyTags,
537
610
  TooLongStep,
538
611
  UniqueScenarioNames,
539
612
  UnknownVariable,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gherkin_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Rohe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-05 00:00:00.000000000 Z
11
+ date: 2015-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gherkin