gherkin_lint 0.6.3 → 1.0.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 (61) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.rubocop.yml +19 -1
  4. data/Dockerfile +2 -0
  5. data/Gemfile +3 -2
  6. data/README.md +24 -2
  7. data/Rakefile +3 -3
  8. data/bin/gherkin_lint +10 -2
  9. data/config/default.yml +58 -0
  10. data/features/avoid_outline_for_single_example.feature +2 -1
  11. data/features/avoid_period.feature +1 -1
  12. data/features/avoid_scripting.feature +1 -1
  13. data/features/background_does_more_than_setup.feature +1 -1
  14. data/features/background_requires_scenario.feature +1 -1
  15. data/features/bad_scenario_name.feature +1 -1
  16. data/features/be_declarative.feature +1 -1
  17. data/features/disable_tags.feature +1 -2
  18. data/features/file_name_differs_feature_name.feature +2 -2
  19. data/features/invalid_file_name.feature +1 -1
  20. data/features/invalid_step_flow.feature +1 -1
  21. data/features/missing_example_name.feature +1 -2
  22. data/features/missing_feature_description.feature +1 -1
  23. data/features/missing_feature_name.feature +1 -1
  24. data/features/missing_scenario_name.feature +1 -1
  25. data/features/missing_test_action.feature +1 -2
  26. data/features/missing_verification.feature +1 -2
  27. data/features/precedence.feature +72 -0
  28. data/features/required_tags_starts_with.feature +95 -0
  29. data/features/same_tag_for_all_scenarios.feature +1 -5
  30. data/features/support/env.rb +72 -0
  31. data/features/tag_used_multiple_times.feature +1 -1
  32. data/features/too_clumsy.feature +1 -1
  33. data/features/too_long_step.feature +1 -1
  34. data/features/too_many_different_tags.feature +1 -1
  35. data/features/too_many_steps.feature +1 -1
  36. data/features/too_many_tags.feature +1 -1
  37. data/features/unique_scenario_names.feature +1 -1
  38. data/features/unknown_variable.feature +1 -1
  39. data/features/unused_variable.feature +1 -1
  40. data/features/use_background.feature +1 -2
  41. data/features/use_outline.feature +1 -2
  42. data/gherkin_lint.gemspec +3 -3
  43. data/lib/gherkin_lint.rb +44 -51
  44. data/lib/gherkin_lint/configuration.rb +32 -0
  45. data/lib/gherkin_lint/issue.rb +1 -1
  46. data/lib/gherkin_lint/linter.rb +6 -10
  47. data/lib/gherkin_lint/linter/avoid_scripting.rb +1 -1
  48. data/lib/gherkin_lint/linter/background_requires_multiple_scenarios.rb +1 -1
  49. data/lib/gherkin_lint/linter/bad_scenario_name.rb +1 -1
  50. data/lib/gherkin_lint/linter/be_declarative.rb +10 -8
  51. data/lib/gherkin_lint/linter/required_tags_starts_with.rb +16 -0
  52. data/lib/gherkin_lint/linter/tag_collector.rb +9 -0
  53. data/lib/gherkin_lint/linter/tag_constraint.rb +32 -0
  54. data/lib/gherkin_lint/linter/too_many_different_tags.rb +3 -0
  55. data/lib/gherkin_lint/linter/too_many_tags.rb +3 -0
  56. data/spec/configuration_spec.rb +58 -0
  57. data/spec/gherkin_lint_spec.rb +68 -0
  58. data/spec/required_tags_starts_with_spec.rb +74 -0
  59. data/spec/shared_contexts/file_exists.rb +12 -0
  60. data/spec/shared_contexts/gherkin_linter.rb +14 -0
  61. metadata +18 -3
@@ -1,8 +1,11 @@
1
1
  require 'gherkin_lint/linter'
2
+ require 'gherkin_lint/linter/tag_collector'
2
3
 
3
4
  module GherkinLint
4
5
  # service class to lint for too many different tags
5
6
  class TooManyDifferentTags < Linter
7
+ include TagCollector
8
+
6
9
  def lint
7
10
  overall_tags = []
8
11
  overall_references = []
@@ -1,8 +1,11 @@
1
1
  require 'gherkin_lint/linter'
2
+ require 'gherkin_lint/linter/tag_collector'
2
3
 
3
4
  module GherkinLint
4
5
  # service class to lint for too many tags
5
6
  class TooManyTags < Linter
7
+ include TagCollector
8
+
6
9
  def lint
7
10
  scenarios do |file, feature, scenario|
8
11
  tags = gather_tags(feature) + gather_tags(scenario)
@@ -0,0 +1,58 @@
1
+ require 'rspec'
2
+ require 'gherkin_lint/configuration'
3
+ require 'shared_contexts/file_exists'
4
+
5
+ describe GherkinLint::Configuration do
6
+ subject { GherkinLint::Configuration.new file }
7
+ let(:file) { 'default.yml' }
8
+
9
+ it 'should do something' do
10
+ expect(subject.config).to eq('')
11
+ end
12
+
13
+ it 'should have a default config path' do
14
+ expect(subject.configuration_path).not_to be nil
15
+ end
16
+ context 'when a empty config file is present' do
17
+ include_context 'a file exists'
18
+ let(:file_content) { '---' }
19
+ it 'should load a file from the config path' do
20
+ expect(subject.config).to eq ''
21
+ end
22
+ end
23
+
24
+ context 'when a non-YAML config file is present' do
25
+ include_context 'a file exists'
26
+ let(:file_content) do
27
+ <<-content
28
+ foo: [
29
+ ‘bar’, {
30
+ baz: 42
31
+ }
32
+ ]'
33
+ content
34
+ end
35
+
36
+ it 'should load a file from the config path but fail to parse' do
37
+ expect { subject.load_configuration }.to raise_error
38
+ expect { subject.config }.to raise_error
39
+ end
40
+ end
41
+ context 'when a valid YAML file is present' do
42
+ include_context 'a file exists'
43
+ let(:file_content) do
44
+ <<-content
45
+ ---
46
+ :parent_key: parent_value
47
+ :child_key: child_value
48
+ content
49
+ end
50
+ before :each do
51
+ subject.load_configuration
52
+ end
53
+
54
+ it 'should load the values from the config file' do
55
+ expect(subject.config).to eq(parent_key: 'parent_value', child_key: 'child_value')
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,68 @@
1
+ require 'rspec'
2
+ require 'gherkin_lint'
3
+ require 'gherkin_lint/linter/tag_constraint'
4
+ require 'shared_contexts/file_exists'
5
+
6
+ describe GherkinLint::GherkinLint do
7
+ it 'should have the constant set' do
8
+ expect(GherkinLint::GherkinLint.const_defined?(:LINTER)).to be true
9
+ end
10
+
11
+ subject { GherkinLint::GherkinLint.new }
12
+
13
+ describe '#initialize' do
14
+ it 'sets the files instance variable to empty' do
15
+ expect(subject.instance_variable_get(:@files)).to eq({})
16
+ end
17
+
18
+ it 'sets the linter instance variable to empty' do
19
+ expect(subject.instance_variable_get(:@linter).size).to eq(0)
20
+ end
21
+ end
22
+
23
+ describe '#enable' do
24
+ it 'enables the linter passed in' do
25
+ subject.enable ['RequiredTagsStartsWith']
26
+ expect(subject.instance_variable_get(:@config).config).to include('RequiredTagsStartsWith' => { 'Enabled' => true })
27
+ end
28
+ end
29
+
30
+ context 'when user configuration is not present' do
31
+ let(:file) { 'config/default.yml' }
32
+ it 'should load the expected values from the config file' do
33
+ expect(subject.instance_variable_get(:@config).config).to include('AvoidOutlineForSingleExample' => { 'Enabled' => true })
34
+ end
35
+ end
36
+
37
+ context 'when user provided YAML is present' do
38
+ include_context 'a file exists'
39
+ let(:file) { '.gherkin_lint.yml' }
40
+ let(:file_content) do
41
+ <<-content
42
+ ---
43
+ AvoidOutlineForSingleExample:
44
+ Enabled: false
45
+ content
46
+ end
47
+ it 'should load and merge the expected values from the user config file' do
48
+ expect(subject.instance_variable_get(:@config).config).to include('AvoidOutlineForSingleExample' => { 'Enabled' => false })
49
+ end
50
+ end
51
+
52
+ context 'when linter member value is passed by the user' do
53
+ include_context 'a file exists'
54
+ let(:file) { '.gherkin_lint.yml' }
55
+ let(:file_content) do
56
+ <<-content
57
+ ---
58
+ RequiredTags:
59
+ Enabled: true
60
+ Member: Value
61
+ content
62
+ end
63
+
64
+ it 'updates the member in the config' do
65
+ expect(subject.instance_variable_get(:@config).config).to include('RequiredTags' => { 'Enabled' => true, 'Member' => 'Value' })
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,74 @@
1
+ require 'rspec'
2
+ require 'gherkin_lint/linter/required_tags_starts_with'
3
+ require 'gherkin_lint'
4
+ require 'shared_contexts/gherkin_linter'
5
+
6
+ describe GherkinLint::RequiredTagsStartsWith do
7
+ let(:linter) { GherkinLint::GherkinLint.new }
8
+ let(:file) { 'lint.feature' }
9
+ let(:pattern) { %w[MCC PB] }
10
+ describe '#matcher' do
11
+ it 'should raise an error when pattern is nil' do
12
+ expect { subject.matcher(nil) }.to raise_error('No Tags provided in the YAML')
13
+ end
14
+ it 'should raise an error when pattern is empty' do
15
+ expect { subject.matcher('') }.to output("Required Tags matcher has no value\n").to_stderr
16
+ end
17
+ end
18
+
19
+ describe '#issues' do
20
+ context 'before linting' do
21
+ it 'should have no issue' do
22
+ expect(subject.issues.size).to eq(0)
23
+ end
24
+ end
25
+
26
+ context 'after linting a feature file with valid PB tag at the feature level' do
27
+ include_context 'a gherkin linter'
28
+
29
+ let(:file_content) do
30
+ <<-content
31
+ @PB
32
+ Feature: Test
33
+ @scenario_tag
34
+ Scenario: A
35
+ content
36
+ end
37
+ it 'should have no issues' do
38
+ expect(subject.issues.size).to eq(0)
39
+ end
40
+ end
41
+
42
+ context 'after linting a file with a MCC tag at the scenario level' do
43
+ include_context 'a gherkin linter'
44
+ let(:file_content) do
45
+ <<-content
46
+ @feature_tag
47
+ Feature: Test
48
+ @MCC
49
+ Scenario: A
50
+ content
51
+ end
52
+
53
+ it 'should have no issues' do
54
+ expect(subject.issues.size).to eq(0)
55
+ end
56
+ end
57
+
58
+ context 'after linting a file with no required tags' do
59
+ include_context 'a gherkin linter'
60
+ let(:file_content) do
61
+ <<-content
62
+ @feature_tag
63
+ Feature: Test
64
+ @scenario_tag
65
+ Scenario: A
66
+ content
67
+ end
68
+
69
+ it 'should have issues after linting a file without PB or MCC tags' do
70
+ expect(subject.issues[0].name).to eq(subject.class.name.split('::').last)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,12 @@
1
+ # needs file and file_content defined
2
+ shared_context 'a file exists' do
3
+ before :each do
4
+ File.open(file, 'w') do |f|
5
+ f.write file_content
6
+ end
7
+ end
8
+
9
+ after :each do
10
+ File.delete(file) if File.exist?(file)
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ require 'rspec'
2
+ require_relative 'file_exists'
3
+
4
+ shared_context 'a gherkin linter' do
5
+ include_context 'a file exists'
6
+
7
+ let(:files) { linter.analyze file }
8
+ let(:disable_tags) { linter.disable_tags }
9
+
10
+ before :each do
11
+ subject.instance_variable_set(:@pattern, pattern)
12
+ subject.lint_files({ file: files }, disable_tags)
13
+ end
14
+ end
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gherkin_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Rohe
8
+ - Nishtha Argawal
9
+ - John Gluck
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
- date: 2017-03-12 00:00:00.000000000 Z
13
+ date: 2017-08-25 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: gherkin
@@ -101,6 +103,7 @@ executables:
101
103
  extensions: []
102
104
  extra_rdoc_files: []
103
105
  files:
106
+ - ".gitignore"
104
107
  - ".rubocop.yml"
105
108
  - ".travis.yml"
106
109
  - Dockerfile
@@ -110,6 +113,7 @@ files:
110
113
  - README.md
111
114
  - Rakefile
112
115
  - bin/gherkin_lint
116
+ - config/default.yml
113
117
  - features/avoid_outline_for_single_example.feature
114
118
  - features/avoid_period.feature
115
119
  - features/avoid_scripting.feature
@@ -127,6 +131,8 @@ files:
127
131
  - features/missing_scenario_name.feature
128
132
  - features/missing_test_action.feature
129
133
  - features/missing_verification.feature
134
+ - features/precedence.feature
135
+ - features/required_tags_starts_with.feature
130
136
  - features/same_tag_for_all_scenarios.feature
131
137
  - features/support/env.rb
132
138
  - features/tag_used_multiple_times.feature
@@ -142,6 +148,7 @@ files:
142
148
  - features/use_outline.feature
143
149
  - gherkin_lint.gemspec
144
150
  - lib/gherkin_lint.rb
151
+ - lib/gherkin_lint/configuration.rb
145
152
  - lib/gherkin_lint/issue.rb
146
153
  - lib/gherkin_lint/linter.rb
147
154
  - lib/gherkin_lint/linter/avoid_outline_for_single_example.rb
@@ -160,7 +167,10 @@ files:
160
167
  - lib/gherkin_lint/linter/missing_scenario_name.rb
161
168
  - lib/gherkin_lint/linter/missing_test_action.rb
162
169
  - lib/gherkin_lint/linter/missing_verification.rb
170
+ - lib/gherkin_lint/linter/required_tags_starts_with.rb
163
171
  - lib/gherkin_lint/linter/same_tag_for_all_scenarios.rb
172
+ - lib/gherkin_lint/linter/tag_collector.rb
173
+ - lib/gherkin_lint/linter/tag_constraint.rb
164
174
  - lib/gherkin_lint/linter/tag_used_multiple_times.rb
165
175
  - lib/gherkin_lint/linter/too_clumsy.rb
166
176
  - lib/gherkin_lint/linter/too_long_step.rb
@@ -172,6 +182,11 @@ files:
172
182
  - lib/gherkin_lint/linter/unused_variable.rb
173
183
  - lib/gherkin_lint/linter/use_background.rb
174
184
  - lib/gherkin_lint/linter/use_outline.rb
185
+ - spec/configuration_spec.rb
186
+ - spec/gherkin_lint_spec.rb
187
+ - spec/required_tags_starts_with_spec.rb
188
+ - spec/shared_contexts/file_exists.rb
189
+ - spec/shared_contexts/gherkin_linter.rb
175
190
  homepage: http://github.com/funkwerk/gherkin_lint/
176
191
  licenses: []
177
192
  metadata: {}
@@ -191,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
206
  version: '0'
192
207
  requirements: []
193
208
  rubyforge_project:
194
- rubygems_version: 2.2.2
209
+ rubygems_version: 2.5.1
195
210
  signing_key:
196
211
  specification_version: 4
197
212
  summary: Gherkin Lint