cuke_linter 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -1
  3. data/CONTRIBUTING.md +26 -0
  4. data/README.md +2 -15
  5. data/lib/cuke_linter.rb +36 -18
  6. data/lib/cuke_linter/linters/example_without_name_linter.rb +1 -1
  7. data/lib/cuke_linter/linters/feature_with_too_many_different_tags_linter.rb +38 -0
  8. data/lib/cuke_linter/linters/test_should_use_background_linter.rb +28 -0
  9. data/lib/cuke_linter/linters/test_with_action_step_as_final_step_linter.rb +23 -0
  10. data/lib/cuke_linter/linters/test_with_setup_step_after_action_step_linter.rb +31 -0
  11. data/lib/cuke_linter/linters/test_with_setup_step_after_verification_step_linter.rb +31 -0
  12. data/lib/cuke_linter/linters/test_with_setup_step_as_final_step_linter.rb +23 -0
  13. data/lib/cuke_linter/version.rb +1 -1
  14. data/testing/cucumber/features/default_linters.feature +20 -14
  15. data/testing/cucumber/features/linters/example_without_name.feature +8 -6
  16. data/testing/cucumber/features/linters/feature_with_too_many_different_tags.feature +56 -0
  17. data/testing/cucumber/features/linters/step_with_end_period.feature +1 -1
  18. data/testing/cucumber/features/linters/test_should_use_background.feature +29 -0
  19. data/testing/cucumber/features/linters/test_with_action_as_final_step.feature +28 -0
  20. data/testing/cucumber/features/linters/test_with_setup_step_after_action_step.feature +30 -0
  21. data/testing/cucumber/features/linters/test_with_setup_step_after_verification_step.feature +30 -0
  22. data/testing/cucumber/features/linters/test_with_setup_step_as_final_step.feature +28 -0
  23. data/testing/cucumber/features/linters/test_with_too_many_steps.feature +5 -0
  24. data/testing/cucumber/step_definitions/setup_steps.rb +28 -0
  25. data/testing/model_factory.rb +1 -1
  26. data/testing/rspec/spec/integration/cuke_linter_integration_spec.rb +12 -0
  27. data/testing/rspec/spec/integration/linters/feature_with_too_many_different_tags_linter_integration_spec.rb +8 -0
  28. data/testing/rspec/spec/integration/linters/test_should_use_background_linter_integration_spec.rb +8 -0
  29. data/testing/rspec/spec/integration/linters/test_with_action_step_as_final_step_linter_integration_spec.rb +8 -0
  30. data/testing/rspec/spec/integration/linters/test_with_setup_step_after_action_step_linter_integration_spec.rb +8 -0
  31. data/testing/rspec/spec/integration/linters/test_with_setup_step_after_verification_step_linter_integration_spec.rb +8 -0
  32. data/testing/rspec/spec/integration/linters/test_with_setup_step_as_final_step_linter_integration_spec.rb +8 -0
  33. data/testing/rspec/spec/unit/linters/background_does_more_than_setup_linter_unit_spec.rb +20 -57
  34. data/testing/rspec/spec/unit/linters/element_with_too_many_tags_linter_unit_spec.rb +18 -52
  35. data/testing/rspec/spec/unit/linters/example_without_name_linter_unit_spec.rb +41 -43
  36. data/testing/rspec/spec/unit/linters/feature_with_too_many_different_tags_linter_unit_spec.rb +293 -0
  37. data/testing/rspec/spec/unit/linters/feature_without_description_linter_unit_spec.rb +25 -42
  38. data/testing/rspec/spec/unit/linters/feature_without_name_linter_unit_spec.rb +10 -38
  39. data/testing/rspec/spec/unit/linters/feature_without_scenarios_linter_unit_spec.rb +32 -52
  40. data/testing/rspec/spec/unit/linters/linter_unit_spec.rb +27 -10
  41. data/testing/rspec/spec/unit/linters/linter_unit_specs.rb +26 -12
  42. data/testing/rspec/spec/unit/linters/outline_with_single_example_row_linter_unit_spec.rb +19 -66
  43. data/testing/rspec/spec/unit/linters/single_test_background_linter_unit_spec.rb +12 -39
  44. data/testing/rspec/spec/unit/linters/step_with_end_period_linter_unit_spec.rb +9 -28
  45. data/testing/rspec/spec/unit/linters/step_with_too_many_characters_linter_unit_spec.rb +19 -45
  46. data/testing/rspec/spec/unit/linters/test_should_use_background_linter_unit_spec.rb +226 -0
  47. data/testing/rspec/spec/unit/linters/test_with_action_step_as_final_step_linter_unit_spec.rb +98 -0
  48. data/testing/rspec/spec/unit/linters/test_with_no_action_step_linter_unit_spec.rb +10 -51
  49. data/testing/rspec/spec/unit/linters/test_with_no_name_linter_unit_spec.rb +11 -38
  50. data/testing/rspec/spec/unit/linters/test_with_no_verification_step_linter_unit_spec.rb +16 -54
  51. data/testing/rspec/spec/unit/linters/test_with_setup_step_after_action_step_linter_unit_spec.rb +124 -0
  52. data/testing/rspec/spec/unit/linters/test_with_setup_step_after_verification_step_linter_unit_spec.rb +125 -0
  53. data/testing/rspec/spec/unit/linters/test_with_setup_step_as_final_step_linter_unit_spec.rb +98 -0
  54. data/testing/rspec/spec/unit/linters/test_with_too_many_steps_linter_unit_spec.rb +9 -49
  55. metadata +27 -2
@@ -3,27 +3,7 @@ require_relative '../../../../../environments/rspec_env'
3
3
 
4
4
  RSpec.describe CukeLinter::OutlineWithSingleExampleRowLinter do
5
5
 
6
- let(:good_data) do
7
- outline_text = 'Scenario Outline:
8
- * a step
9
- Examples:
10
- | param |
11
- | value 1 |
12
- | value 2 |'
13
-
14
- CukeLinter::ModelFactory.generate_outline_model(source_text: outline_text)
15
- end
16
-
17
- let(:bad_data) do
18
- outline_text = 'Scenario Outline:
19
- * a step
20
- Examples:
21
- | param |
22
- | value 1 |'
23
-
24
- CukeLinter::ModelFactory.generate_outline_model(source_text: outline_text)
25
- end
26
-
6
+ let(:model_file_path) { 'some_file_path' }
27
7
 
28
8
  it_should_behave_like 'a linter at the unit level'
29
9
 
@@ -45,9 +25,13 @@ RSpec.describe CukeLinter::OutlineWithSingleExampleRowLinter do
45
25
  | param |
46
26
  | value |'
47
27
 
48
- CukeLinter::ModelFactory.generate_outline_model(source_text: gherkin)
28
+ CukeLinter::ModelFactory.generate_outline_model(parent_file_path: model_file_path,
29
+ source_text: gherkin)
49
30
  end
50
31
 
32
+ it_should_behave_like 'a linter linting a bad model'
33
+
34
+
51
35
  it 'records a problem' do
52
36
  result = subject.lint(test_model)
53
37
 
@@ -67,9 +51,13 @@ RSpec.describe CukeLinter::OutlineWithSingleExampleRowLinter do
67
51
  | param |
68
52
  | value |'
69
53
 
70
- CukeLinter::ModelFactory.generate_outline_model(source_text: gherkin)
54
+ CukeLinter::ModelFactory.generate_outline_model(parent_file_path: model_file_path,
55
+ source_text: gherkin)
71
56
  end
72
57
 
58
+ it_should_behave_like 'a linter linting a bad model'
59
+
60
+
73
61
  it 'records a problem' do
74
62
  result = subject.lint(test_model)
75
63
 
@@ -78,27 +66,6 @@ RSpec.describe CukeLinter::OutlineWithSingleExampleRowLinter do
78
66
 
79
67
  end
80
68
 
81
-
82
- it 'records the location of the problem' do
83
- gherkin = 'Scenario Outline:
84
- * a step
85
- Examples:
86
- | param |
87
- | value |'
88
-
89
- model_1 = CukeLinter::ModelFactory.generate_outline_model(source_text: gherkin, parent_file_path: 'path_to_file')
90
- model_2 = CukeLinter::ModelFactory.generate_outline_model(source_text: gherkin, parent_file_path: 'path_to_file')
91
-
92
- model_1.source_line = 1
93
- model_2.source_line = 3
94
-
95
- result = subject.lint(model_1)
96
- expect(result[:location]).to eq('path_to_file:1')
97
-
98
- result = subject.lint(model_2)
99
- expect(result[:location]).to eq('path_to_file:3')
100
- end
101
-
102
69
  end
103
70
 
104
71
  context 'an outline with more than one example row' do
@@ -116,9 +83,7 @@ RSpec.describe CukeLinter::OutlineWithSingleExampleRowLinter do
116
83
  CukeLinter::ModelFactory.generate_outline_model(source_text: gherkin)
117
84
  end
118
85
 
119
- it 'does not record a problem' do
120
- expect(subject.lint(test_model)).to eq(nil)
121
- end
86
+ it_should_behave_like 'a linter linting a good model'
122
87
 
123
88
  end
124
89
 
@@ -137,9 +102,7 @@ RSpec.describe CukeLinter::OutlineWithSingleExampleRowLinter do
137
102
  CukeLinter::ModelFactory.generate_outline_model(source_text: gherkin)
138
103
  end
139
104
 
140
- it 'does not record a problem' do
141
- expect(subject.lint(test_model)).to eq(nil)
142
- end
105
+ it_should_behave_like 'a linter linting a good model'
143
106
 
144
107
  end
145
108
 
@@ -158,9 +121,7 @@ RSpec.describe CukeLinter::OutlineWithSingleExampleRowLinter do
158
121
  model
159
122
  end
160
123
 
161
- it 'does not record a problem' do
162
- expect(subject.lint(test_model)).to eq(nil)
163
- end
124
+ it_should_behave_like 'a linter linting a good model'
164
125
 
165
126
  end
166
127
 
@@ -172,9 +133,7 @@ RSpec.describe CukeLinter::OutlineWithSingleExampleRowLinter do
172
133
  model
173
134
  end
174
135
 
175
- it 'does not record a problem' do
176
- expect(subject.lint(test_model)).to eq(nil)
177
- end
136
+ it_should_behave_like 'a linter linting a good model'
178
137
 
179
138
  end
180
139
 
@@ -191,9 +150,7 @@ RSpec.describe CukeLinter::OutlineWithSingleExampleRowLinter do
191
150
  CukeLinter::ModelFactory.generate_outline_model(source_text: gherkin)
192
151
  end
193
152
 
194
- it 'does not record a problem' do
195
- expect(subject.lint(test_model)).to eq(nil)
196
- end
153
+ it_should_behave_like 'a linter linting a good model'
197
154
 
198
155
  end
199
156
 
@@ -210,9 +167,7 @@ RSpec.describe CukeLinter::OutlineWithSingleExampleRowLinter do
210
167
  CukeLinter::ModelFactory.generate_outline_model(source_text: gherkin)
211
168
  end
212
169
 
213
- it 'does not record a problem' do
214
- expect(subject.lint(test_model)).to eq(nil)
215
- end
170
+ it_should_behave_like 'a linter linting a good model'
216
171
 
217
172
  end
218
173
 
@@ -220,11 +175,9 @@ RSpec.describe CukeLinter::OutlineWithSingleExampleRowLinter do
220
175
 
221
176
  context 'a non-outline model' do
222
177
 
223
- it 'returns no result' do
224
- result = subject.lint(CukeModeler::Model.new)
178
+ let(:test_model) { CukeModeler::Model.new }
225
179
 
226
- expect(result).to eq(nil)
227
- end
180
+ it_should_behave_like 'a linter linting a good model'
228
181
 
229
182
  end
230
183
  end
@@ -3,21 +3,7 @@ require_relative '../../../../../environments/rspec_env'
3
3
 
4
4
  RSpec.describe CukeLinter::SingleTestBackgroundLinter do
5
5
 
6
- let(:good_data) do
7
- CukeLinter::ModelFactory.generate_feature_model(source_text: 'Feature:
8
- Background:
9
- * a step
10
- Scenario:
11
- Scenario:').background
12
- end
13
-
14
- let(:bad_data) do
15
- CukeLinter::ModelFactory.generate_feature_model(source_text: 'Feature:
16
- Background:
17
- * a step
18
- Scenario:').background
19
- end
20
-
6
+ let(:model_file_path) { 'some_file_path' }
21
7
 
22
8
  it_should_behave_like 'a linter at the unit level'
23
9
 
@@ -35,9 +21,10 @@ RSpec.describe CukeLinter::SingleTestBackgroundLinter do
35
21
  context "and that test is a #{model_type}" do
36
22
 
37
23
  let(:test_model) do
38
- background_model = CukeLinter::ModelFactory.generate_feature_model(source_text: 'Feature:
39
- Background:
40
- * a step').background
24
+ background_model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: model_file_path,
25
+ source_text: 'Feature:
26
+ Background:
27
+ * a step').background
41
28
 
42
29
  background_model.parent_model.tests.clear
43
30
  background_model.parent_model.tests << CukeLinter::ModelFactory.send("generate_#{model_type}_model")
@@ -45,22 +32,15 @@ RSpec.describe CukeLinter::SingleTestBackgroundLinter do
45
32
  background_model
46
33
  end
47
34
 
35
+ it_should_behave_like 'a linter linting a bad model'
36
+
37
+
48
38
  it 'records a problem' do
49
39
  result = subject.lint(test_model)
50
40
 
51
41
  expect(result[:problem]).to match('Background used with only one test')
52
42
  end
53
43
 
54
- it 'records the location of the problem' do
55
- test_model.source_line = 1
56
- result = subject.lint(test_model)
57
- expect(result[:location]).to eq('path_to_file:1')
58
-
59
- test_model.source_line = 3
60
- result = subject.lint(test_model)
61
- expect(result[:location]).to eq('path_to_file:3')
62
- end
63
-
64
44
  end
65
45
 
66
46
  end
@@ -81,9 +61,7 @@ RSpec.describe CukeLinter::SingleTestBackgroundLinter do
81
61
  |value|').background
82
62
  end
83
63
 
84
- it 'does not record a problem' do
85
- expect(subject.lint(test_model)).to eq(nil)
86
- end
64
+ it_should_behave_like 'a linter linting a good model'
87
65
 
88
66
  end
89
67
 
@@ -95,9 +73,7 @@ RSpec.describe CukeLinter::SingleTestBackgroundLinter do
95
73
  * a step').background
96
74
  end
97
75
 
98
- it 'does not record a problem' do
99
- expect(subject.lint(test_model)).to eq(nil)
100
- end
76
+ it_should_behave_like 'a linter linting a good model'
101
77
 
102
78
  end
103
79
 
@@ -105,12 +81,9 @@ RSpec.describe CukeLinter::SingleTestBackgroundLinter do
105
81
 
106
82
  let(:test_model) { CukeModeler::Model.new }
107
83
 
108
- it 'returns no result' do
109
- result = subject.lint(test_model)
110
-
111
- expect(result).to eq(nil)
112
- end
84
+ it_should_behave_like 'a linter linting a good model'
113
85
 
114
86
  end
87
+
115
88
  end
116
89
  end
@@ -3,14 +3,7 @@ require_relative '../../../../../environments/rspec_env'
3
3
 
4
4
  RSpec.describe CukeLinter::StepWithEndPeriodLinter do
5
5
 
6
- let(:good_data) do
7
- CukeLinter::ModelFactory.generate_step_model(source_text: '* without a period')
8
- end
9
-
10
- let(:bad_data) do
11
- CukeLinter::ModelFactory.generate_step_model(source_text: '* with a period.')
12
- end
13
-
6
+ let(:model_file_path) { 'some_file_path' }
14
7
 
15
8
  it_should_behave_like 'a linter at the unit level'
16
9
 
@@ -24,37 +17,28 @@ RSpec.describe CukeLinter::StepWithEndPeriodLinter do
24
17
  context "with a step that ends with a period" do
25
18
 
26
19
  let(:test_model) do
27
- CukeLinter::ModelFactory.generate_step_model(source_text: '* with a period.')
20
+ CukeLinter::ModelFactory.generate_step_model(parent_file_path: model_file_path,
21
+ source_text: '* with a period.')
28
22
  end
29
23
 
24
+ it_should_behave_like 'a linter linting a bad model'
25
+
26
+
30
27
  it 'records a problem' do
31
28
  result = subject.lint(test_model)
32
29
 
33
30
  expect(result[:problem]).to match('Step ends with a period')
34
31
  end
35
32
 
36
- it 'records the location of the problem' do
37
- test_model.source_line = 1
38
- result = subject.lint(test_model)
39
- expect(result[:location]).to eq('path_to_file:1')
40
-
41
- test_model.source_line = 3
42
- result = subject.lint(test_model)
43
- expect(result[:location]).to eq('path_to_file:3')
44
- end
45
-
46
33
  end
47
34
 
48
35
  context "with a step that does not end with a period" do
49
36
 
50
-
51
37
  let(:test_model) do
52
38
  CukeLinter::ModelFactory.generate_step_model(source_text: '* without a period')
53
39
  end
54
40
 
55
- it 'does not record a problem' do
56
- expect(subject.lint(test_model)).to eq(nil)
57
- end
41
+ it_should_behave_like 'a linter linting a good model'
58
42
 
59
43
  end
60
44
 
@@ -62,12 +46,9 @@ RSpec.describe CukeLinter::StepWithEndPeriodLinter do
62
46
 
63
47
  let(:test_model) { CukeModeler::Model.new }
64
48
 
65
- it 'returns no result' do
66
- result = subject.lint(test_model)
67
-
68
- expect(result).to eq(nil)
69
- end
49
+ it_should_behave_like 'a linter linting a good model'
70
50
 
71
51
  end
52
+
72
53
  end
73
54
  end
@@ -3,18 +3,7 @@ require_relative '../../../../../environments/rspec_env'
3
3
 
4
4
  RSpec.describe CukeLinter::StepWithTooManyCharactersLinter do
5
5
 
6
- let(:good_data) do
7
- CukeLinter::ModelFactory.generate_step_model(source_text: '* a short step')
8
- end
9
-
10
- let(:bad_data) do
11
- long_step = <<~EOL.delete("\n")
12
- * this is a very long string which will violate the linter
13
- rule which expects step rules to have fewer than one hundred
14
- and twenty characters
15
- EOL
16
- CukeLinter::ModelFactory.generate_step_model(source_text: long_step)
17
- end
6
+ let(:model_file_path) { 'some_file_path' }
18
7
 
19
8
  it_should_behave_like 'a linter at the unit level'
20
9
  it_should_behave_like 'a configurable linter at the unit level'
@@ -30,30 +19,28 @@ RSpec.describe CukeLinter::StepWithTooManyCharactersLinter do
30
19
 
31
20
  context 'when the step is too long' do
32
21
 
33
- let(:step_too_long_model) do
22
+ let(:test_model) do
34
23
  step = 'x' * (default_character_threshold + 1)
35
- CukeLinter::ModelFactory.generate_step_model(source_text: "* #{step}")
24
+ CukeLinter::ModelFactory.generate_step_model(parent_file_path: model_file_path,
25
+ source_text: "* #{step}")
36
26
  end
37
27
 
38
- it 'reports a problem' do
39
- result = subject.lint(step_too_long_model)
28
+ it_should_behave_like 'a linter linting a bad model'
40
29
 
41
- expect(result[:problem]).to match(/^Step is too long. \d+ characters found \(max 80\)/)
42
- end
43
30
 
44
- it 'records the location of the problem' do
45
- result = subject.lint(step_too_long_model)
31
+ it 'reports a problem' do
32
+ result = subject.lint(test_model)
46
33
 
47
- expect(result[:location]).to eq('path_to_file:4')
34
+ expect(result[:problem]).to match(/^Step is too long. \d+ characters found \(max 80\)/)
48
35
  end
49
36
 
50
37
  it 'includes the number of characters found in the problem record' do
51
- character_count = step_too_long_model.text.length
52
- result = subject.lint(step_too_long_model)
38
+ character_count = test_model.text.length
39
+ result = subject.lint(test_model)
53
40
  expect(result[:problem]).to eq("Step is too long. #{character_count} characters found (max 80)")
54
41
 
55
- step_too_long_model.text += 'x'
56
- result = subject.lint(step_too_long_model)
42
+ test_model.text += 'x'
43
+ result = subject.lint(test_model)
57
44
  expect(result[:problem]).to eq("Step is too long. #{character_count + 1} characters found (max 80)")
58
45
  end
59
46
 
@@ -61,45 +48,36 @@ RSpec.describe CukeLinter::StepWithTooManyCharactersLinter do
61
48
 
62
49
  context 'when the step is the maximum length' do
63
50
 
64
- let(:step_mex_length_model) do
51
+ let(:test_model) do
65
52
  step = 'x' * default_character_threshold
66
53
  CukeLinter::ModelFactory.generate_step_model(source_text: "* #{step}")
67
54
  end
68
55
 
69
- it 'does not record a problem' do
70
- result = subject.lint(step_mex_length_model)
71
- expect(result).to eq(nil)
72
- end
56
+ it_should_behave_like 'a linter linting a good model'
73
57
 
74
58
  end
75
59
 
76
60
  context 'when the step is below the maximum length' do
77
61
 
78
- let(:step_below_length_model) do
62
+ let(:test_model) do
79
63
  step = 'x' * (default_character_threshold - 1)
80
64
  CukeLinter::ModelFactory.generate_step_model(source_text: "* #{step}")
81
65
  end
82
66
 
83
- it 'does not record a problem' do
84
- result = subject.lint(step_below_length_model)
85
- expect(result).to eq(nil)
86
- end
67
+ it_should_behave_like 'a linter linting a good model'
87
68
 
88
69
  end
89
70
 
90
71
  context 'when the step has no text' do
91
72
 
92
- let(:step_with_nil_text_model) do
73
+ let(:test_model) do
93
74
  model = CukeLinter::ModelFactory.generate_step_model
94
75
  model.text = nil
95
76
 
96
77
  model
97
78
  end
98
79
 
99
- it 'does not record a problem' do
100
- result = subject.lint(step_with_nil_text_model)
101
- expect(result).to eq(nil)
102
- end
80
+ it_should_behave_like 'a linter linting a good model'
103
81
 
104
82
  end
105
83
 
@@ -107,11 +85,7 @@ RSpec.describe CukeLinter::StepWithTooManyCharactersLinter do
107
85
 
108
86
  let(:test_model) { CukeModeler::Model.new }
109
87
 
110
- it 'returns no result' do
111
- result = subject.lint(test_model)
112
-
113
- expect(result).to eq(nil)
114
- end
88
+ it_should_behave_like 'a linter linting a good model'
115
89
 
116
90
  end
117
91