cuke_linter 0.12.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 670cec37df02d865f45baf856baab441942d1dd54f8b39089b88fd4657afc098
|
4
|
+
data.tar.gz: 840623e9e37f4f38ac3d5f1f28332b77f759b77a8dd3aa12a9554ede015ccddb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96beaf4a96234000319d61976ee7b19de8fe0c4d5a83583d0cd3fa33579078cbfce40eac96e52302423c69266db8cc0d3582263a1b913674a741142ee044f0bc
|
7
|
+
data.tar.gz: b21f8016215c971dcff8565232c3e078c9e2f0f6a4421c554e2479cb0a5d42d1abeb6b08ef5f6851d28d50b13b3a8362772d8ecbecfbcc6a66efa34681deaeb5
|
data/.travis.yml
CHANGED
@@ -8,11 +8,21 @@ dist: trusty
|
|
8
8
|
|
9
9
|
language: ruby
|
10
10
|
rvm:
|
11
|
+
- 2.3.3
|
11
12
|
- 2.4.0
|
12
13
|
- 2.5.1
|
13
14
|
- 2.6.0
|
14
15
|
- jruby-9.1.7.0
|
15
16
|
|
17
|
+
matrix:
|
18
|
+
exclude:
|
19
|
+
# Ruby 2.3.x is currently broken on TravisCI and is no longer a supported Ruby version, anyway.
|
20
|
+
- rvm: 2.3.3
|
21
|
+
os: osx
|
22
|
+
|
23
|
+
gemfile:
|
24
|
+
- testing/gemfiles/cuke_modeler1.gemfile
|
25
|
+
- testing/gemfiles/cuke_modeler2.gemfile
|
16
26
|
|
17
27
|
gemfile:
|
18
28
|
- testing/gemfiles/cuke_modeler1.gemfile
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
8
8
|
|
9
9
|
Nothing yet...
|
10
10
|
|
11
|
+
|
12
|
+
## [0.12.1] - 2020-02-15
|
13
|
+
|
14
|
+
### Fixed
|
15
|
+
- `TestShouldUseBackgroundLinter` no longer suggests moving steps to the background if they have an outline parameter.
|
16
|
+
|
11
17
|
## [0.12.0] - 2020-02-13
|
12
18
|
|
13
19
|
### Added
|
@@ -129,7 +135,8 @@ Nothing yet...
|
|
129
135
|
- Custom linters, formatters, and command line usability
|
130
136
|
|
131
137
|
|
132
|
-
[Unreleased]: https://github.com/enkessler/cuke_linter/compare/v0.12.
|
138
|
+
[Unreleased]: https://github.com/enkessler/cuke_linter/compare/v0.12.1...HEAD
|
139
|
+
[0.12.1]: https://github.com/enkessler/cuke_linter/compare/v0.12.0...v0.12.1
|
133
140
|
[0.12.0]: https://github.com/enkessler/cuke_linter/compare/v0.11.1...v0.12.0
|
134
141
|
[0.11.1]: https://github.com/enkessler/cuke_linter/compare/v0.11.0...v0.11.1
|
135
142
|
[0.11.0]: https://github.com/enkessler/cuke_linter/compare/v0.10.0...v0.11.0
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module CukeLinter
|
2
2
|
|
3
|
+
# TODO: Make a new class that it is from the POV of a Feature model instead
|
3
4
|
# A linter that detects scenarios and outlines within a feature that all share common beginning steps
|
4
5
|
|
5
6
|
class TestShouldUseBackgroundLinter < Linter
|
@@ -13,10 +14,22 @@ module CukeLinter
|
|
13
14
|
|
14
15
|
return false unless parent_feature_model.tests.count > 1
|
15
16
|
|
16
|
-
parent_feature_model.tests.all? do |test|
|
17
|
+
matching_steps = parent_feature_model.tests.all? do |test|
|
17
18
|
test_steps = test.steps || []
|
18
19
|
test_steps.first == model_steps.first
|
19
20
|
end
|
21
|
+
|
22
|
+
none_parameterized = parent_feature_model.tests.none? do |test|
|
23
|
+
next false if test.is_a?(CukeModeler::Scenario)
|
24
|
+
|
25
|
+
test_steps = test.steps || []
|
26
|
+
params_used_by_test = test.examples.map(&:parameters).flatten.uniq
|
27
|
+
|
28
|
+
next false unless test_steps.any?
|
29
|
+
parameterized_step?(test_steps.first, parameters: params_used_by_test)
|
30
|
+
end
|
31
|
+
|
32
|
+
matching_steps && none_parameterized
|
20
33
|
end
|
21
34
|
|
22
35
|
# The message used to describe the problem that has been found
|
@@ -24,5 +37,36 @@ module CukeLinter
|
|
24
37
|
'Test shares steps with all other tests in feature. Use a background.'
|
25
38
|
end
|
26
39
|
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
|
44
|
+
def parameterized_step?(step_model, parameters:)
|
45
|
+
parameters.any? do |parameter|
|
46
|
+
parameter_string = "<#{parameter}>"
|
47
|
+
|
48
|
+
parameterized_text?(step_model, parameter_string) ||
|
49
|
+
parameterized_doc_string?(step_model, parameter_string) ||
|
50
|
+
parameterized_table?(step_model, parameter_string)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def parameterized_text?(step_model, parameter)
|
55
|
+
step_model.text.include?(parameter)
|
56
|
+
end
|
57
|
+
|
58
|
+
def parameterized_doc_string?(step_model, parameter)
|
59
|
+
return false unless step_model.block.is_a?(CukeModeler::DocString)
|
60
|
+
|
61
|
+
step_model.block.content.include?(parameter)
|
62
|
+
end
|
63
|
+
|
64
|
+
def parameterized_table?(step_model, parameter)
|
65
|
+
return false unless step_model.block.is_a?(CukeModeler::Table)
|
66
|
+
|
67
|
+
step_model.block.rows.map(&:cells).flatten.map(&:value).any? { |cell_text| cell_text.include?(parameter) }
|
68
|
+
end
|
69
|
+
|
27
70
|
end
|
71
|
+
|
28
72
|
end
|
data/lib/cuke_linter/version.rb
CHANGED
@@ -50,6 +50,90 @@ RSpec.describe CukeLinter::TestShouldUseBackgroundLinter do
|
|
50
50
|
|
51
51
|
end
|
52
52
|
|
53
|
+
context 'with parameters that are not really parameters' do
|
54
|
+
|
55
|
+
if (model_type == 'scenario')
|
56
|
+
|
57
|
+
# Scenarios don't actually have parameters, even if they look like they do
|
58
|
+
context 'because they are in scenarios' do
|
59
|
+
|
60
|
+
let(:test_model) do
|
61
|
+
step_text = 'the not really <parameterized> step'
|
62
|
+
feature_model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: model_file_path,
|
63
|
+
source_text: "Feature:
|
64
|
+
Scenario:
|
65
|
+
* #{step_text}
|
66
|
+
Scenario:
|
67
|
+
* #{step_text}")
|
68
|
+
|
69
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
|
70
|
+
model.steps = [CukeModeler::Step.new("* #{step_text}")]
|
71
|
+
|
72
|
+
model.parent_model = feature_model
|
73
|
+
feature_model.tests << model
|
74
|
+
|
75
|
+
model
|
76
|
+
end
|
77
|
+
|
78
|
+
it_should_behave_like 'a linter linting a bad model'
|
79
|
+
|
80
|
+
|
81
|
+
it 'records a problem' do
|
82
|
+
result = subject.lint(test_model)
|
83
|
+
|
84
|
+
expect(result[:problem]).to eq('Test shares steps with all other tests in feature. Use a background.')
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
if model_type == 'outline'
|
93
|
+
|
94
|
+
context 'because of extra whitespace' do
|
95
|
+
|
96
|
+
let(:test_model) do
|
97
|
+
# Whitespace is significant
|
98
|
+
step_text = "the step < param_foo >"
|
99
|
+
feature_model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: model_file_path,
|
100
|
+
source_text: "Feature:
|
101
|
+
Scenario Outline:
|
102
|
+
* #{step_text}
|
103
|
+
Examples:
|
104
|
+
| param_foo |
|
105
|
+
| value |
|
106
|
+
Scenario Outline:
|
107
|
+
* #{step_text}
|
108
|
+
Examples:
|
109
|
+
| param_foo |
|
110
|
+
| value |")
|
111
|
+
|
112
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
|
113
|
+
model.steps = [CukeModeler::Step.new("* #{step_text}")]
|
114
|
+
|
115
|
+
model.parent_model = feature_model
|
116
|
+
feature_model.tests << model
|
117
|
+
|
118
|
+
model
|
119
|
+
end
|
120
|
+
|
121
|
+
it_should_behave_like 'a linter linting a bad model'
|
122
|
+
|
123
|
+
|
124
|
+
it 'records a problem' do
|
125
|
+
result = subject.lint(test_model)
|
126
|
+
|
127
|
+
expect(result[:problem]).to eq('Test shares steps with all other tests in feature. Use a background.')
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
|
53
137
|
context "with a #{model_type} that does not share a first step with all other tests in the feature" do
|
54
138
|
|
55
139
|
context 'because the steps are different' do
|
@@ -211,6 +295,160 @@ RSpec.describe CukeLinter::TestShouldUseBackgroundLinter do
|
|
211
295
|
|
212
296
|
end
|
213
297
|
|
298
|
+
context 'because its first step contains a parameter' do
|
299
|
+
|
300
|
+
let(:test_model) do
|
301
|
+
step_text = 'the maybe <parameterized> step'
|
302
|
+
feature_model = CukeLinter::ModelFactory.generate_feature_model(source_text: "Feature:
|
303
|
+
Scenario:
|
304
|
+
* #{step_text}
|
305
|
+
Scenario Outline:
|
306
|
+
* #{step_text}
|
307
|
+
Examples:
|
308
|
+
| parameterized |
|
309
|
+
| value |")
|
310
|
+
|
311
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
|
312
|
+
model.steps = [CukeModeler::Step.new("* #{step_text}")]
|
313
|
+
|
314
|
+
model.parent_model = feature_model
|
315
|
+
feature_model.tests << model
|
316
|
+
|
317
|
+
model
|
318
|
+
end
|
319
|
+
|
320
|
+
it_should_behave_like 'a linter linting a good model'
|
321
|
+
|
322
|
+
if model_type == 'outline'
|
323
|
+
|
324
|
+
context 'even with a bunch of parameterized outlines' do
|
325
|
+
|
326
|
+
context 'with a parameter in the text of the step' do
|
327
|
+
|
328
|
+
let(:test_model) do
|
329
|
+
step_text = 'the <parameterized> step'
|
330
|
+
feature_model = CukeLinter::ModelFactory.generate_feature_model(source_text: "Feature:
|
331
|
+
Scenario Outline:
|
332
|
+
* #{step_text}
|
333
|
+
Examples:
|
334
|
+
| parameterized |
|
335
|
+
| value |
|
336
|
+
Scenario Outline:
|
337
|
+
* #{step_text}
|
338
|
+
Examples:
|
339
|
+
| parameterized |
|
340
|
+
| value |")
|
341
|
+
|
342
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
|
343
|
+
model.steps = [CukeModeler::Step.new("* #{step_text}")]
|
344
|
+
|
345
|
+
model.parent_model = feature_model
|
346
|
+
feature_model.tests << model
|
347
|
+
|
348
|
+
model
|
349
|
+
end
|
350
|
+
|
351
|
+
it_should_behave_like 'a linter linting a good model'
|
352
|
+
|
353
|
+
end
|
354
|
+
|
355
|
+
context 'with a parameter in the table of the step' do
|
356
|
+
|
357
|
+
let(:test_model) do
|
358
|
+
step_text = "the step\n | <param_foo> |"
|
359
|
+
feature_model = CukeLinter::ModelFactory.generate_feature_model(source_text: "Feature:
|
360
|
+
Scenario Outline:
|
361
|
+
* #{step_text}
|
362
|
+
Examples:
|
363
|
+
| param_foo |
|
364
|
+
| value |
|
365
|
+
Scenario Outline:
|
366
|
+
* #{step_text}
|
367
|
+
Examples:
|
368
|
+
| param_foo |
|
369
|
+
| value |")
|
370
|
+
|
371
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
|
372
|
+
model.steps = [CukeModeler::Step.new("* #{step_text}")]
|
373
|
+
|
374
|
+
model.parent_model = feature_model
|
375
|
+
feature_model.tests << model
|
376
|
+
|
377
|
+
model
|
378
|
+
end
|
379
|
+
|
380
|
+
it_should_behave_like 'a linter linting a good model'
|
381
|
+
|
382
|
+
end
|
383
|
+
|
384
|
+
context 'with a parameter in the doc string of the step' do
|
385
|
+
|
386
|
+
let(:test_model) do
|
387
|
+
step_text = "the step\n \"\"\"\n <param_foo>\n \"\"\""
|
388
|
+
feature_model = CukeLinter::ModelFactory.generate_feature_model(source_text: "Feature:
|
389
|
+
Scenario Outline:
|
390
|
+
* #{step_text}
|
391
|
+
Examples:
|
392
|
+
| param_foo |
|
393
|
+
| value |
|
394
|
+
Scenario Outline:
|
395
|
+
* #{step_text}
|
396
|
+
Examples:
|
397
|
+
| param_foo |
|
398
|
+
| value |")
|
399
|
+
|
400
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
|
401
|
+
model.steps = [CukeModeler::Step.new("* #{step_text}")]
|
402
|
+
|
403
|
+
model.parent_model = feature_model
|
404
|
+
feature_model.tests << model
|
405
|
+
|
406
|
+
model
|
407
|
+
end
|
408
|
+
|
409
|
+
it_should_behave_like 'a linter linting a good model'
|
410
|
+
|
411
|
+
end
|
412
|
+
|
413
|
+
context 'with inconsistent parameter usage' do
|
414
|
+
|
415
|
+
let(:test_model) do
|
416
|
+
step_text = "the step <param_foo>"
|
417
|
+
feature_model = CukeLinter::ModelFactory.generate_feature_model(source_text: "Feature:
|
418
|
+
Scenario Outline:
|
419
|
+
* #{step_text}
|
420
|
+
Examples:
|
421
|
+
| param_foo |
|
422
|
+
| value |
|
423
|
+
Scenario Outline:
|
424
|
+
* #{step_text}
|
425
|
+
Examples:
|
426
|
+
| param_bar |
|
427
|
+
| value |
|
428
|
+
Examples:
|
429
|
+
| param_foo |
|
430
|
+
| value |")
|
431
|
+
|
432
|
+
model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
|
433
|
+
model.steps = [CukeModeler::Step.new("* #{step_text}")]
|
434
|
+
|
435
|
+
model.parent_model = feature_model
|
436
|
+
feature_model.tests << model
|
437
|
+
|
438
|
+
model
|
439
|
+
end
|
440
|
+
|
441
|
+
it_should_behave_like 'a linter linting a good model'
|
442
|
+
|
443
|
+
end
|
444
|
+
|
445
|
+
# TODO: do outline parameters even get substituted in the doc string type?
|
446
|
+
end
|
447
|
+
|
448
|
+
end
|
449
|
+
|
450
|
+
end
|
451
|
+
|
214
452
|
end
|
215
453
|
|
216
454
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuke_linter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Kessler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cuke_modeler
|