gherkin_lint 0.0.1 → 0.0.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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gherkin_lint.rb +63 -9
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ada6bfa04c433aad9b3d227c5ae836b79d0dc7c
4
- data.tar.gz: 22345665cd0d4f7985f22ba857ae8a6d61cd3713
3
+ metadata.gz: 0115886cf68f342c7e96db6fed9b810821d39586
4
+ data.tar.gz: bc8c412c92394916145f3b4998e1455a942f1ef0
5
5
  SHA512:
6
- metadata.gz: dce80fc451a1cecbd88da1a7efdc27d8e1d35fd3674a10865082f1d42b6156ecea8827132dd8772d0afba59237e969e5974ebb4e19c89639d9731370e0483739
7
- data.tar.gz: 7814679c1fbefbfdf15870578adeffd530a849fb62c01c94ebb36dea68a26c395a91eea505cbf1aef86f44f9301324bfb38e616eb50f2e3d71609c7e624da5cc
6
+ metadata.gz: 5b1fb9da007d9908a43ea4ae5d7b9c4cad6604b9030306e9a254cab5cc0680011b2de551bf16a2556951620cfc82279b2521f11e8ee53e8b4cc5088c6b5fa0df
7
+ data.tar.gz: 1f5c003ef09b1bb24bf732816a43982ca7605ce541a60af1971094f694e3b30d03551e3de2fe87ef4fe1b2b97ef6234ec112d277c1bda2e2369d130aa0db3219
data/lib/gherkin_lint.rb CHANGED
@@ -146,7 +146,7 @@ class GherkinLint
146
146
  end
147
147
  end
148
148
 
149
- # service class to lint for backgrond that does more than setup
149
+ # service class to lint for background that does more than setup
150
150
  class BackgroundDoesMoreThanSetup < Linter
151
151
  def lint
152
152
  backgrounds do |file, feature, background|
@@ -159,6 +159,19 @@ class GherkinLint
159
159
  end
160
160
  end
161
161
 
162
+ # service class to lint for background requires multiple scenario
163
+ class BackgroundRequiresMultipleScenarios < Linter
164
+ def lint
165
+ backgrounds do |file, feature, background|
166
+ scenarios = feature['elements'].select { |element| element['keyword'] != 'Background' }
167
+ next if scenarios.length >= 2
168
+
169
+ references = [reference(file, feature, background)]
170
+ add_issue(references, "There are just #{scenarios.length} scenarios")
171
+ end
172
+ end
173
+ end
174
+
162
175
  # service class to lint for missing feature names
163
176
  class MissingFeatureName < Linter
164
177
  def lint
@@ -241,14 +254,14 @@ class GherkinLint
241
254
  steps.each do |step|
242
255
  break if step['keyword'] == 'When '
243
256
  references = [reference(file, feature, scenario, step)]
244
- description = 'Verification before action'
257
+ description = 'Missing Action'
245
258
  add_issue(references, description) if step['keyword'] == 'Then '
246
259
  end
247
260
  end
248
261
  end
249
262
 
250
- # service class to lint for invalid scenario names
251
- class InvalidScenarioName < Linter
263
+ # service class to lint for bad scenario names
264
+ class BadScenarioName < Linter
252
265
  def lint
253
266
  scenarios do |file, feature, scenario|
254
267
  next if scenario['name'].empty?
@@ -267,13 +280,52 @@ class GherkinLint
267
280
  def lint
268
281
  files do |file|
269
282
  base = File.basename file
270
- next if base == base.downcase
283
+ next unless base != base.downcase || base =~ /[ -]/
271
284
  references = [reference(file)]
272
285
  add_issue(references, 'Feature files should be snake_cased')
273
286
  end
274
287
  end
275
288
  end
276
289
 
290
+ # service class to lint for unknown variables
291
+ class UnknownVariable < Linter
292
+ def lint
293
+ scenarios do |file, feature, scenario|
294
+ known_vars = known_variables scenario
295
+ scenario['steps'].each do |step|
296
+ step_vars(step).each do |used_var|
297
+ next if known_vars.include? used_var
298
+ references = [reference(file, feature, scenario)]
299
+ add_issue(references, "'<#{used_var}>' is unknown")
300
+ end
301
+ end
302
+ end
303
+ end
304
+
305
+ def step_vars(step)
306
+ vars = gather_vars step['name']
307
+ vars += gather_vars step['doc_string']['value'] if step.key? 'doc_string'
308
+ if step.key? 'rows'
309
+ vars += step['rows'].map do |row|
310
+ row['cells'].map { |value| gather_vars value }.flatten
311
+ end.flatten
312
+ end
313
+ vars
314
+ end
315
+
316
+ def gather_vars(string)
317
+ string.scan(/<.+>/).map { |val| val[1..-2] }
318
+ end
319
+
320
+ def known_variables(scenario)
321
+ return Set.new unless scenario.key? 'examples'
322
+ Set.new(scenario['examples'].map do |example|
323
+ next unless example.key? 'rows'
324
+ example['rows'].first['cells'].map(&:strip)
325
+ end.flatten)
326
+ end
327
+ end
328
+
277
329
  # service class to lint for unused variables
278
330
  class UnusedVariable < Linter
279
331
  def lint
@@ -313,8 +365,8 @@ class GherkinLint
313
365
  end
314
366
  end
315
367
 
316
- # service class to lint for avoiding colons
317
- class AvoidColon < Linter
368
+ # service class to lint for avoiding periods
369
+ class AvoidPeriod < Linter
318
370
  def lint
319
371
  scenarios do |file, feature, scenario|
320
372
  next unless scenario.key? 'steps'
@@ -328,8 +380,10 @@ class GherkinLint
328
380
  end
329
381
 
330
382
  LINTER = [
331
- AvoidColon,
383
+ AvoidPeriod,
332
384
  BackgroundDoesMoreThanSetup,
385
+ BackgroundRequiresMultipleScenarios,
386
+ BadScenarioName,
333
387
  MissingExampleName,
334
388
  MissingFeatureDescription,
335
389
  MissingFeatureName,
@@ -337,9 +391,9 @@ class GherkinLint
337
391
  MissingTestAction,
338
392
  MissingVerification,
339
393
  InvalidFileName,
340
- InvalidScenarioName,
341
394
  InvalidStepFlow,
342
395
  UniqueScenarioNames,
396
+ UnknownVariable,
343
397
  UnusedVariable
344
398
  ]
345
399
 
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.1
4
+ version: 0.0.2
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-02 00:00:00.000000000 Z
11
+ date: 2015-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gherkin