cuke_linter 0.9.0 → 0.10.0

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 (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,18 +3,7 @@ require_relative '../../../../../environments/rspec_env'
3
3
 
4
4
  RSpec.describe CukeLinter::FeatureWithoutDescriptionLinter do
5
5
 
6
- let(:good_data) do
7
- feature_text = 'Feature:
8
- with a description'
9
-
10
- CukeLinter::ModelFactory.generate_feature_model(source_text: feature_text)
11
- end
12
-
13
- let(:bad_data) do
14
- feature_text = 'Feature: without a description'
15
-
16
- CukeLinter::ModelFactory.generate_feature_model(source_text: feature_text)
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
 
@@ -22,75 +11,69 @@ RSpec.describe CukeLinter::FeatureWithoutDescriptionLinter do
22
11
  it 'has a name' do
23
12
  expect(subject.name).to eq('FeatureWithoutDescriptionLinter')
24
13
  end
25
-
14
+
26
15
  describe 'linting' do
27
-
16
+
28
17
  context 'a feature with no description' do
29
18
 
30
19
  context 'because the description is empty' do
31
20
 
32
- let(:feature_with_no_description) do
33
- model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: 'path_to_file')
21
+ let(:test_model) do
22
+ model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: model_file_path)
34
23
  model.description = ''
35
24
 
36
25
  model
37
26
  end
38
27
 
28
+ it_should_behave_like 'a linter linting a bad model'
29
+
39
30
 
40
31
  it 'records a problem' do
41
- result = subject.lint(feature_with_no_description)
32
+ result = subject.lint(test_model)
33
+
42
34
  expect(result[:problem]).to eq('Feature has no description')
43
35
  end
44
36
 
45
- it 'records the location of the problem' do
46
- result = subject.lint(feature_with_no_description)
47
- expect(result[:location]).to eq('path_to_file:1')
48
- end
49
37
  end
50
38
 
51
39
  context 'because the description is nil' do
52
40
 
53
- let(:feature_with_no_description) do
54
- model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: 'path_to_file')
41
+ let(:test_model) do
42
+ model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: model_file_path)
55
43
  model.description = nil
56
44
 
57
45
  model
58
46
  end
59
47
 
60
48
  it 'records a problem' do
61
- result = subject.lint(feature_with_no_description)
49
+ result = subject.lint(test_model)
50
+
62
51
  expect(result[:problem]).to eq('Feature has no description')
63
52
  end
64
53
 
65
- it 'records the location of the problem' do
66
- result = subject.lint(feature_with_no_description)
67
- expect(result[:location]).to eq('path_to_file:1')
68
- end
54
+ it_should_behave_like 'a linter linting a bad model'
69
55
 
70
56
  end
71
57
  end
72
-
58
+
73
59
  context 'a feature with a description' do
74
-
75
- let(:feature_with_a_description) do
60
+
61
+ let(:test_model) do
76
62
  model_source = "Feature:\n This feature has a description"
77
- CukeLinter::ModelFactory.generate_feature_model(source_text: model_source,
63
+ CukeLinter::ModelFactory.generate_feature_model(source_text: model_source,
78
64
  parent_file_path: 'path_to_file')
79
65
  end
80
-
81
- it 'does not record a problem' do
82
- result = subject.lint(feature_with_a_description)
83
- expect(result).to eq(nil)
84
- end
66
+
67
+ it_should_behave_like 'a linter linting a good model'
68
+
85
69
  end
86
70
 
87
71
  context 'a non-feature model' do
88
-
89
- it 'returns no results' do
90
- result = subject.lint(CukeModeler::Model.new)
91
72
 
92
- expect(result).to eq(nil)
93
- end
73
+ let(:test_model) { CukeModeler::Model.new }
74
+
75
+ it_should_behave_like 'a linter linting a good model'
76
+
94
77
  end
95
78
 
96
79
  end
@@ -3,14 +3,7 @@ require_relative '../../../../../environments/rspec_env'
3
3
 
4
4
  RSpec.describe CukeLinter::FeatureWithoutNameLinter do
5
5
 
6
- let(:good_data) do
7
- CukeLinter::ModelFactory.generate_feature_model(source_text: 'Feature: some name')
8
- end
9
-
10
- let(:bad_data) do
11
- CukeLinter::ModelFactory.generate_feature_model(source_text: 'Feature:')
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
 
@@ -26,55 +19,40 @@ RSpec.describe CukeLinter::FeatureWithoutNameLinter do
26
19
  context 'because its name is empty' do
27
20
 
28
21
  let(:test_model) do
29
- model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: 'path_to_file')
22
+ model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: model_file_path)
30
23
  model.name = ''
31
24
 
32
25
  model
33
26
  end
34
27
 
28
+ it_should_behave_like 'a linter linting a bad model'
29
+
30
+
35
31
  it 'records a problem' do
36
32
  result = subject.lint(test_model)
37
33
 
38
34
  expect(result[:problem]).to eq('Feature does not have a name.')
39
35
  end
40
36
 
41
- it 'records the location of the problem' do
42
- test_model.source_line = 1
43
- result = subject.lint(test_model)
44
- expect(result[:location]).to eq('path_to_file:1')
45
-
46
- test_model.source_line = 3
47
- result = subject.lint(test_model)
48
- expect(result[:location]).to eq('path_to_file:3')
49
- end
50
-
51
37
  end
52
38
 
53
39
  context 'because its name is nil' do
54
40
 
55
41
  let(:test_model) do
56
- model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: 'path_to_file')
42
+ model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: model_file_path)
57
43
  model.name = nil
58
44
 
59
45
  model
60
46
  end
61
47
 
48
+ it_should_behave_like 'a linter linting a bad model'
49
+
62
50
  it 'records a problem' do
63
51
  result = subject.lint(test_model)
64
52
 
65
53
  expect(result[:problem]).to eq('Feature does not have a name.')
66
54
  end
67
55
 
68
- it 'records the location of the problem' do
69
- test_model.source_line = 1
70
- result = subject.lint(test_model)
71
- expect(result[:location]).to eq('path_to_file:1')
72
-
73
- test_model.source_line = 3
74
- result = subject.lint(test_model)
75
- expect(result[:location]).to eq('path_to_file:3')
76
- end
77
-
78
56
  end
79
57
 
80
58
  end
@@ -88,9 +66,7 @@ RSpec.describe CukeLinter::FeatureWithoutNameLinter do
88
66
  model
89
67
  end
90
68
 
91
- it 'does not record a problem' do
92
- expect(subject.lint(test_model)).to eq(nil)
93
- end
69
+ it_should_behave_like 'a linter linting a good model'
94
70
 
95
71
  end
96
72
 
@@ -99,11 +75,7 @@ RSpec.describe CukeLinter::FeatureWithoutNameLinter do
99
75
 
100
76
  let(:test_model) { CukeModeler::Model.new }
101
77
 
102
- it 'returns no result' do
103
- result = subject.lint(test_model)
104
-
105
- expect(result).to eq(nil)
106
- end
78
+ it_should_behave_like 'a linter linting a good model'
107
79
 
108
80
  end
109
81
 
@@ -3,20 +3,7 @@ require_relative '../../../../../environments/rspec_env'
3
3
 
4
4
  RSpec.describe CukeLinter::FeatureWithoutScenariosLinter do
5
5
 
6
- let(:good_data) do
7
- model = CukeLinter::ModelFactory.generate_feature_model
8
- model.tests = ['totally_a_test']
9
-
10
- model
11
- end
12
-
13
- let(:bad_data) do
14
- model = CukeLinter::ModelFactory.generate_feature_model
15
- model.tests = []
16
-
17
- model
18
- end
19
-
6
+ let(:model_file_path) { 'some_file_path' }
20
7
 
21
8
  it_should_behave_like 'a linter at the unit level'
22
9
 
@@ -27,50 +14,49 @@ RSpec.describe CukeLinter::FeatureWithoutScenariosLinter do
27
14
 
28
15
  describe 'linting' do
29
16
 
30
- context 'a feature with no scenarios' do
17
+ context 'a feature with no tests' do
31
18
 
32
- let(:test_model_with_empty_scenarios) do
33
- model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: 'path_to_file')
34
- model.tests = []
19
+ context 'because the tests are empty' do
35
20
 
36
- model
37
- end
21
+ let(:test_model) do
22
+ model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: model_file_path)
23
+ model.tests = []
24
+
25
+ model
26
+ end
38
27
 
39
- let(:test_model_with_nil_scenarios) do
40
- model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: 'path_to_file')
41
- model.tests = nil
28
+ it_should_behave_like 'a linter linting a bad model'
29
+
30
+ it 'records a problem' do
31
+ result = subject.lint(test_model)
32
+
33
+ expect(result[:problem]).to eq('Feature has no scenarios')
34
+ end
42
35
 
43
- model
44
36
  end
45
37
 
46
- it 'records a problem' do
47
- result = subject.lint(test_model_with_empty_scenarios)
38
+ context 'because the tests are nil' do
48
39
 
49
- expect(result[:problem]).to eq('Feature has no scenarios')
40
+ let(:test_model) do
41
+ model = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: model_file_path)
42
+ model.tests = nil
50
43
 
51
- result = subject.lint(test_model_with_nil_scenarios)
44
+ model
45
+ end
52
46
 
53
- expect(result[:problem]).to eq('Feature has no scenarios')
54
- end
47
+ it_should_behave_like 'a linter linting a bad model'
55
48
 
56
- it 'records the location of the problem' do
57
- model_1 = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: 'path_to_file')
58
- model_1.tests = []
59
- model_1.source_line = 1
60
- model_2 = CukeLinter::ModelFactory.generate_feature_model(parent_file_path: 'path_to_file')
61
- model_2.tests = []
62
- model_2.source_line = 3
49
+ it 'records a problem' do
50
+ result = subject.lint(test_model)
63
51
 
64
- result = subject.lint(model_1)
65
- expect(result[:location]).to eq('path_to_file:1')
52
+ expect(result[:problem]).to eq('Feature has no scenarios')
53
+ end
66
54
 
67
- result = subject.lint(model_2)
68
- expect(result[:location]).to eq('path_to_file:3')
69
55
  end
70
56
 
71
57
  end
72
58
 
73
- context 'a feature with scenarios' do
59
+ context 'a feature with tests' do
74
60
 
75
61
  context 'with a scenario' do
76
62
 
@@ -82,9 +68,7 @@ RSpec.describe CukeLinter::FeatureWithoutScenariosLinter do
82
68
  CukeLinter::ModelFactory.generate_feature_model(source_text: gherkin)
83
69
  end
84
70
 
85
- it 'does not record a problem' do
86
- expect(subject.lint(test_model)).to eq(nil)
87
- end
71
+ it_should_behave_like 'a linter linting a good model'
88
72
 
89
73
  end
90
74
 
@@ -101,9 +85,7 @@ RSpec.describe CukeLinter::FeatureWithoutScenariosLinter do
101
85
  CukeLinter::ModelFactory.generate_feature_model(source_text: gherkin)
102
86
  end
103
87
 
104
- it 'does not record a problem' do
105
- expect(subject.lint(test_model)).to eq(nil)
106
- end
88
+ it_should_behave_like 'a linter linting a good model'
107
89
 
108
90
  end
109
91
 
@@ -111,11 +93,9 @@ RSpec.describe CukeLinter::FeatureWithoutScenariosLinter do
111
93
 
112
94
  context 'a non-feature model' do
113
95
 
114
- it 'returns no result' do
115
- result = subject.lint(CukeModeler::Model.new)
96
+ let(:test_model) { CukeModeler::Model.new }
116
97
 
117
- expect(result).to eq(nil)
118
- end
98
+ it_should_behave_like 'a linter linting a good model'
119
99
 
120
100
  end
121
101
  end
@@ -3,17 +3,39 @@ require_relative '../../../../../environments/rspec_env'
3
3
 
4
4
  RSpec.describe CukeLinter::Linter do
5
5
 
6
+ let(:model_file_path) { 'some_file_path' }
7
+
6
8
  let(:linter_name) { 'FooLinter' }
7
9
  let(:linter_message) { 'Foo!' }
8
10
  let(:linter_rule) { lambda { |model| !model.is_a?(CukeModeler::Example) } }
9
11
  let(:linter_options) { { name: linter_name, message: linter_message, rule: linter_rule } }
10
12
 
11
- let(:good_data) do
12
- CukeLinter::ModelFactory.generate_example_model
13
- end
13
+ let(:good_data) { CukeLinter::ModelFactory.generate_example_model }
14
+ let(:bad_data) { CukeLinter::ModelFactory.generate_outline_model }
15
+
16
+
17
+ it_should_behave_like 'a linter at the unit level'
18
+
19
+ context 'with a linting rule' do
20
+
21
+ subject { CukeLinter::Linter.new(linter_options.merge({ rule: linter_rule })) }
22
+
23
+ context 'with a good model' do
24
+
25
+ let(:test_model) { CukeLinter::ModelFactory.generate_example_model }
26
+
27
+ it_should_behave_like 'a linter linting a good model'
28
+
29
+ end
30
+
31
+ context 'with a bad model' do
32
+
33
+ let(:test_model) { CukeLinter::ModelFactory.generate_outline_model(parent_file_path: model_file_path) }
34
+
35
+ it_should_behave_like 'a linter linting a bad model'
36
+
37
+ end
14
38
 
15
- let(:bad_data) do
16
- CukeLinter::ModelFactory.generate_outline_model
17
39
  end
18
40
 
19
41
 
@@ -21,9 +43,6 @@ RSpec.describe CukeLinter::Linter do
21
43
 
22
44
  subject { CukeLinter::Linter.new(linter_options) }
23
45
 
24
-
25
- it_should_behave_like 'a linter at the unit level'
26
-
27
46
  it 'uses the provided name' do
28
47
  expect(subject.name).to eq(linter_name)
29
48
  end
@@ -61,8 +80,6 @@ RSpec.describe CukeLinter::Linter do
61
80
  linter }
62
81
 
63
82
 
64
- it_should_behave_like 'a linter at the unit level'
65
-
66
83
  it 'uses the provided #name' do
67
84
  expect(subject.name).to eq(linter_name)
68
85
  end
@@ -14,25 +14,39 @@ shared_examples_for 'a linter at the unit level' do
14
14
  expect(subject.method(:lint).arity).to eq(1)
15
15
  end
16
16
 
17
- context 'with good data' do
17
+ end
18
+
18
19
 
19
- it 'returns no problem' do
20
- expect(subject.lint(good_data)).to be_nil
21
- end
20
+ shared_examples_for 'a linter linting a good model' do
22
21
 
22
+ it 'returns no problem' do
23
+ expect(subject.lint(test_model)).to be_nil
23
24
  end
24
25
 
25
- context 'with bad data' do
26
+ end
26
27
 
27
- it 'returns a detected problems' do
28
- expect(subject.lint(bad_data)).to_not be_nil
29
- end
30
28
 
31
- it 'includes the problem and its locations in its result' do
32
- result = subject.lint(bad_data)
29
+ shared_examples_for 'a linter linting a bad model' do
30
+
31
+ it 'returns a detected problem' do
32
+ expect(subject.lint(test_model)).to_not be_nil
33
+ end
33
34
 
34
- expect(result.keys).to match_array([:problem, :location])
35
- end
35
+ it 'includes the problem and its location in its result' do
36
+ result = subject.lint(test_model)
36
37
 
38
+ expect(result).to_not be_nil
39
+ expect(result.keys).to match_array([:problem, :location])
37
40
  end
41
+
42
+ it 'correctly records the location of the problem' do
43
+ test_model.source_line = 1
44
+ result = subject.lint(test_model)
45
+ expect(result[:location]).to eq("#{model_file_path}:1")
46
+
47
+ test_model.source_line = 3
48
+ result = subject.lint(test_model)
49
+ expect(result[:location]).to eq("#{model_file_path}:3")
50
+ end
51
+
38
52
  end