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,14 +3,7 @@ require_relative '../../../../../environments/rspec_env'
3
3
 
4
4
  RSpec.describe CukeLinter::TestWithNoNameLinter do
5
5
 
6
- let(:good_data) do
7
- CukeLinter::ModelFactory.generate_scenario_model(source_text: 'Scenario: some name')
8
- end
9
-
10
- let(:bad_data) do
11
- CukeLinter::ModelFactory.generate_scenario_model(source_text: 'Scenario:')
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
 
@@ -28,55 +21,41 @@ RSpec.describe CukeLinter::TestWithNoNameLinter do
28
21
  context 'because its name is empty' do
29
22
 
30
23
  let(:test_model) do
31
- model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: 'path_to_file')
24
+ model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: model_file_path)
32
25
  model.name = ''
33
26
 
34
27
  model
35
28
  end
36
29
 
30
+ it_should_behave_like 'a linter linting a bad model'
31
+
32
+
37
33
  it 'records a problem' do
38
34
  result = subject.lint(test_model)
39
35
 
40
36
  expect(result[:problem]).to eq('Test does not have a name.')
41
37
  end
42
38
 
43
- it 'records the location of the problem' do
44
- test_model.source_line = 1
45
- result = subject.lint(test_model)
46
- expect(result[:location]).to eq('path_to_file:1')
47
-
48
- test_model.source_line = 3
49
- result = subject.lint(test_model)
50
- expect(result[:location]).to eq('path_to_file:3')
51
- end
52
-
53
39
  end
54
40
 
55
41
  context 'because its name is nil' do
56
42
 
57
43
  let(:test_model) do
58
- model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: 'path_to_file')
44
+ model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: model_file_path)
59
45
  model.name = nil
60
46
 
61
47
  model
62
48
  end
63
49
 
50
+ it_should_behave_like 'a linter linting a bad model'
51
+
52
+
64
53
  it 'records a problem' do
65
54
  result = subject.lint(test_model)
66
55
 
67
56
  expect(result[:problem]).to eq('Test does not have a name.')
68
57
  end
69
58
 
70
- it 'records the location of the problem' do
71
- test_model.source_line = 1
72
- result = subject.lint(test_model)
73
- expect(result[:location]).to eq('path_to_file:1')
74
-
75
- test_model.source_line = 3
76
- result = subject.lint(test_model)
77
- expect(result[:location]).to eq('path_to_file:3')
78
- end
79
-
80
59
  end
81
60
 
82
61
  end
@@ -90,9 +69,7 @@ RSpec.describe CukeLinter::TestWithNoNameLinter do
90
69
  model
91
70
  end
92
71
 
93
- it 'does not record a problem' do
94
- expect(subject.lint(test_model)).to eq(nil)
95
- end
72
+ it_should_behave_like 'a linter linting a good model'
96
73
 
97
74
  end
98
75
 
@@ -102,11 +79,7 @@ RSpec.describe CukeLinter::TestWithNoNameLinter do
102
79
 
103
80
  let(:test_model) { CukeModeler::Model.new }
104
81
 
105
- it 'returns no result' do
106
- result = subject.lint(test_model)
107
-
108
- expect(result).to eq(nil)
109
- end
82
+ it_should_behave_like 'a linter linting a good model'
110
83
 
111
84
  end
112
85
 
@@ -3,16 +3,7 @@ require_relative '../../../../../environments/rspec_env'
3
3
 
4
4
  RSpec.describe CukeLinter::TestWithNoVerificationStepLinter do
5
5
 
6
- let(:good_data) do
7
- CukeLinter::ModelFactory.generate_scenario_model(source_text: 'Scenario:
8
- Then a verification step')
9
- end
10
-
11
- let(:bad_data) do
12
- CukeLinter::ModelFactory.generate_scenario_model(source_text: 'Scenario:
13
- * no verification step')
14
- end
15
-
6
+ let(:model_file_path) { 'some_file_path' }
16
7
 
17
8
  it_should_behave_like 'a linter at the unit level'
18
9
 
@@ -32,55 +23,41 @@ RSpec.describe CukeLinter::TestWithNoVerificationStepLinter do
32
23
  context 'because its steps are empty' do
33
24
 
34
25
  let(:test_model) do
35
- model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: 'path_to_file')
26
+ model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: model_file_path)
36
27
  model.steps = []
37
28
 
38
29
  model
39
30
  end
40
31
 
32
+ it_should_behave_like 'a linter linting a bad model'
33
+
34
+
41
35
  it 'records a problem' do
42
36
  result = subject.lint(test_model)
43
37
 
44
38
  expect(result[:problem]).to eq("Test does not have a 'Then' step.")
45
39
  end
46
40
 
47
- it 'records the location of the problem' do
48
- test_model.source_line = 1
49
- result = subject.lint(test_model)
50
- expect(result[:location]).to eq('path_to_file:1')
51
-
52
- test_model.source_line = 3
53
- result = subject.lint(test_model)
54
- expect(result[:location]).to eq('path_to_file:3')
55
- end
56
-
57
41
  end
58
42
 
59
43
  context 'because its steps are nil' do
60
44
 
61
45
  let(:test_model) do
62
- model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: 'path_to_file')
46
+ model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: model_file_path)
63
47
  model.steps = nil
64
48
 
65
49
  model
66
50
  end
67
51
 
52
+ it_should_behave_like 'a linter linting a bad model'
53
+
54
+
68
55
  it 'records a problem' do
69
56
  result = subject.lint(test_model)
70
57
 
71
58
  expect(result[:problem]).to eq("Test does not have a 'Then' step.")
72
59
  end
73
60
 
74
- it 'records the location of the problem' do
75
- test_model.source_line = 1
76
- result = subject.lint(test_model)
77
- expect(result[:location]).to eq('path_to_file:1')
78
-
79
- test_model.source_line = 3
80
- result = subject.lint(test_model)
81
- expect(result[:location]).to eq('path_to_file:3')
82
- end
83
-
84
61
  end
85
62
 
86
63
  end
@@ -88,28 +65,21 @@ RSpec.describe CukeLinter::TestWithNoVerificationStepLinter do
88
65
  context 'because none of its steps is a verification step' do
89
66
 
90
67
  let(:test_model) do
91
- model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: 'path_to_file')
68
+ model = CukeLinter::ModelFactory.send("generate_#{model_type}_model", parent_file_path: model_file_path)
92
69
  model.steps = [CukeModeler::Step.new('* not a verification step')]
93
70
 
94
71
  model
95
72
  end
96
73
 
74
+ it_should_behave_like 'a linter linting a bad model'
75
+
76
+
97
77
  it 'records a problem' do
98
78
  result = subject.lint(test_model)
99
79
 
100
80
  expect(result[:problem]).to eq("Test does not have a 'Then' step.")
101
81
  end
102
82
 
103
- it 'records the location of the problem' do
104
- test_model.source_line = 1
105
- result = subject.lint(test_model)
106
- expect(result[:location]).to eq('path_to_file:1')
107
-
108
- test_model.source_line = 3
109
- result = subject.lint(test_model)
110
- expect(result[:location]).to eq('path_to_file:3')
111
- end
112
-
113
83
  end
114
84
 
115
85
  end
@@ -128,9 +98,7 @@ RSpec.describe CukeLinter::TestWithNoVerificationStepLinter do
128
98
  model
129
99
  end
130
100
 
131
- it 'does not record a problem' do
132
- expect(subject.lint(test_model)).to eq(nil)
133
- end
101
+ it_should_behave_like 'a linter linting a good model'
134
102
 
135
103
  end
136
104
 
@@ -143,9 +111,7 @@ RSpec.describe CukeLinter::TestWithNoVerificationStepLinter do
143
111
  model
144
112
  end
145
113
 
146
- it 'does not record a problem' do
147
- expect(subject.lint(test_model)).to eq(nil)
148
- end
114
+ it_should_behave_like 'a linter linting a good model'
149
115
 
150
116
  end
151
117
 
@@ -206,11 +172,7 @@ RSpec.describe CukeLinter::TestWithNoVerificationStepLinter do
206
172
 
207
173
  let(:test_model) { CukeModeler::Model.new }
208
174
 
209
- it 'returns no result' do
210
- result = subject.lint(test_model)
211
-
212
- expect(result).to eq(nil)
213
- end
175
+ it_should_behave_like 'a linter linting a good model'
214
176
 
215
177
  end
216
178
  end
@@ -0,0 +1,124 @@
1
+ require_relative '../../../../../environments/rspec_env'
2
+
3
+
4
+ RSpec.describe CukeLinter::TestWithSetupStepAfterActionStepLinter do
5
+
6
+ let(:model_file_path) { 'some_file_path' }
7
+
8
+ it_should_behave_like 'a linter at the unit level'
9
+
10
+
11
+ it 'has a name' do
12
+ expect(subject.name).to eq('TestWithSetupStepAfterActionStepLinter')
13
+ end
14
+
15
+ describe 'linting' do
16
+
17
+ ['scenario', 'outline'].each do |model_type|
18
+
19
+ context "with a #{model_type} that has a setup step after an action step" do
20
+
21
+ let(:test_model) do
22
+ model = CukeLinter::ModelFactory.send("generate_#{model_type}_model",
23
+ parent_file_path: model_file_path)
24
+ model.steps = [CukeModeler::Step.new('When a step'),
25
+ CukeModeler::Step.new('Given a step')]
26
+
27
+ model
28
+ end
29
+
30
+ it_should_behave_like 'a linter linting a bad model'
31
+
32
+
33
+ it 'records a problem' do
34
+ result = subject.lint(test_model)
35
+
36
+ expect(result[:problem]).to eq("Test has 'Given' step after 'When' step.")
37
+ end
38
+
39
+ end
40
+
41
+ context "with a #{model_type} that does not have a setup step after an action step" do
42
+
43
+ context 'because it has no steps' do
44
+
45
+ context 'because its steps are empty' do
46
+
47
+ let(:test_model) do
48
+ model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
49
+ model.steps = []
50
+
51
+ model
52
+ end
53
+
54
+ it_should_behave_like 'a linter linting a good model'
55
+
56
+ end
57
+
58
+ context 'because its steps are nil' do
59
+
60
+ let(:test_model) do
61
+ model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
62
+ model.steps = nil
63
+
64
+ model
65
+ end
66
+
67
+ it_should_behave_like 'a linter linting a good model'
68
+
69
+ end
70
+
71
+ end
72
+
73
+ context 'because its setup steps come before its action steps' do
74
+
75
+ let(:test_model) do
76
+ model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
77
+ model.steps = [CukeModeler::Step.new('* a step')]
78
+
79
+ model
80
+ end
81
+
82
+ it_should_behave_like 'a linter linting a good model'
83
+
84
+ end
85
+
86
+ end
87
+
88
+ context "with a #{model_type} that has an associated background" do
89
+
90
+ let(:test_model) do
91
+ feature_model = CukeLinter::ModelFactory.generate_feature_model(source_text: 'Feature:
92
+ Background:
93
+ Given a step
94
+ When a step
95
+ Given a step
96
+ When a step')
97
+
98
+ model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
99
+ model.steps = [CukeModeler::Step.new('Given a step')]
100
+
101
+ model.parent_model = feature_model
102
+ feature_model.tests << model
103
+
104
+ model
105
+ end
106
+
107
+ it 'does not consider those steps when linting' do
108
+ expect(subject.lint(test_model)).to eq(nil)
109
+ end
110
+
111
+ end
112
+
113
+ end
114
+
115
+
116
+ context 'a non-test model' do
117
+
118
+ let(:test_model) { CukeModeler::Model.new }
119
+
120
+ it_should_behave_like 'a linter linting a good model'
121
+
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,125 @@
1
+ require_relative '../../../../../environments/rspec_env'
2
+
3
+
4
+ RSpec.describe CukeLinter::TestWithSetupStepAfterVerificationStepLinter do
5
+
6
+ let(:model_file_path) { 'some_file_path' }
7
+
8
+ it_should_behave_like 'a linter at the unit level'
9
+
10
+
11
+ it 'has a name' do
12
+ expect(subject.name).to eq('TestWithSetupStepAfterVerificationStepLinter')
13
+ end
14
+
15
+ describe 'linting' do
16
+
17
+ ['scenario', 'outline'].each do |model_type|
18
+
19
+ context "with a #{model_type} that has a setup step after a verification step" do
20
+
21
+ let(:test_model) do
22
+ model = CukeLinter::ModelFactory.send("generate_#{model_type}_model",
23
+ parent_file_path: model_file_path)
24
+ model.steps = [CukeModeler::Step.new('Then a step'),
25
+ CukeModeler::Step.new('Given a step')]
26
+
27
+ model
28
+ end
29
+
30
+ it_should_behave_like 'a linter linting a bad model'
31
+
32
+
33
+ it 'records a problem' do
34
+ result = subject.lint(test_model)
35
+
36
+ expect(result[:problem]).to eq("Test has 'Given' step after 'Then' step.")
37
+ end
38
+
39
+ end
40
+
41
+ context "with a #{model_type} that does not have a setup step after a verification step" do
42
+
43
+ context 'because it has no steps' do
44
+
45
+ context 'because its steps are empty' do
46
+
47
+ let(:test_model) do
48
+ model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
49
+ model.steps = []
50
+
51
+ model
52
+ end
53
+
54
+ it_should_behave_like 'a linter linting a good model'
55
+
56
+ end
57
+
58
+ context 'because its steps are nil' do
59
+
60
+ let(:test_model) do
61
+ model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
62
+ model.steps = nil
63
+
64
+ model
65
+ end
66
+
67
+ it_should_behave_like 'a linter linting a good model'
68
+
69
+ end
70
+
71
+ end
72
+
73
+ context 'because its setup steps come before its verification steps' do
74
+
75
+ let(:test_model) do
76
+ model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
77
+ model.steps = [CukeModeler::Step.new('Given a step'),
78
+ CukeModeler::Step.new('Then a step'),]
79
+
80
+ model
81
+ end
82
+
83
+ it_should_behave_like 'a linter linting a good model'
84
+
85
+ end
86
+
87
+ end
88
+
89
+ context "with a #{model_type} that has an associated background" do
90
+
91
+ let(:test_model) do
92
+ feature_model = CukeLinter::ModelFactory.generate_feature_model(source_text: 'Feature:
93
+ Background:
94
+ Given a step
95
+ Then a step
96
+ Given a step
97
+ Then a step')
98
+
99
+ model = CukeLinter::ModelFactory.send("generate_#{model_type}_model")
100
+ model.steps = [CukeModeler::Step.new('Given a step')]
101
+
102
+ model.parent_model = feature_model
103
+ feature_model.tests << model
104
+
105
+ model
106
+ end
107
+
108
+ it 'does not consider those steps when linting' do
109
+ expect(subject.lint(test_model)).to eq(nil)
110
+ end
111
+
112
+ end
113
+
114
+ end
115
+
116
+
117
+ context 'a non-test model' do
118
+
119
+ let(:test_model) { CukeModeler::Model.new }
120
+
121
+ it_should_behave_like 'a linter linting a good model'
122
+
123
+ end
124
+ end
125
+ end