cucumber_lint 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -4
- data/.travis.yml +9 -0
- data/Gemfile +7 -5
- data/Gemfile.lock +3 -1
- data/README.md +28 -40
- data/Rakefile +12 -6
- data/cucumber_lint.gemspec +2 -0
- data/features/cucumber_lint/fix/nothing.feature +12 -0
- data/features/cucumber_lint/fix/repeating_steps.feature +25 -0
- data/features/cucumber_lint/fix/table_whitespace.feature +25 -0
- data/features/cucumber_lint/fix/uppercase_table_headers.feature +25 -0
- data/features/cucumber_lint/lint/nothing.feature +12 -0
- data/features/cucumber_lint/lint/repeating_steps.feature +31 -0
- data/features/cucumber_lint/lint/table_whitespace.feature +27 -0
- data/features/cucumber_lint/lint/uppercase_table_headers.feature +30 -0
- data/features/step_definitions/cli_steps.rb +9 -6
- data/features/step_definitions/fixtures/repeating_steps/bad.feature.example +12 -0
- data/features/step_definitions/fixtures/repeating_steps/good.feature.example +12 -0
- data/features/step_definitions/fixtures/table_whitespace/bad.feature.example +20 -0
- data/features/step_definitions/fixtures/table_whitespace/good.feature.example +20 -0
- data/features/step_definitions/fixtures/uppercase_table_headers/bad.feature.example +20 -0
- data/features/step_definitions/fixtures/uppercase_table_headers/good.feature.example +20 -0
- data/lib/core_ext/hash.rb +29 -0
- data/lib/cucumber_lint/cli.rb +50 -38
- data/lib/cucumber_lint/fix_list.rb +37 -0
- data/lib/cucumber_lint/linter/feature_linter.rb +92 -0
- data/lib/cucumber_lint/linter/scenario_outline_linter.rb +34 -0
- data/lib/cucumber_lint/linter/steps_linter.rb +49 -0
- data/lib/cucumber_lint/linter/table_linter.rb +70 -0
- data/lib/cucumber_lint/linter.rb +21 -0
- data/lib/cucumber_lint/version.rb +2 -2
- data/lib/cucumber_lint.rb +7 -4
- metadata +64 -16
- data/features/cucumber_lint/cli_fix.feature +0 -51
- data/features/cucumber_lint/cli_lint.feature +0 -55
- data/features/cucumber_lint/feature_formatter.feature +0 -106
- data/features/cucumber_lint/steps_formatter.feature +0 -30
- data/features/cucumber_lint/table_formatter.feature +0 -45
- data/features/step_definitions/fixtures/formatted.feature.example +0 -9
- data/features/step_definitions/fixtures/unformatted.feature.example +0 -9
- data/features/step_definitions/steps_formatter_steps.rb +0 -15
- data/features/step_definitions/table_formatter_steps.rb +0 -15
- data/lib/core_ext/array.rb +0 -22
- data/lib/cucumber_lint/feature_formatter.rb +0 -48
- data/lib/cucumber_lint/steps_formatter.rb +0 -50
- data/lib/cucumber_lint/table_formatter.rb +0 -65
- data/spec/core_ext/array_spec.rb +0 -19
@@ -1,30 +0,0 @@
|
|
1
|
-
Feature: table formatter
|
2
|
-
|
3
|
-
Scenario: unformatted steps
|
4
|
-
Given steps
|
5
|
-
"""
|
6
|
-
Given A
|
7
|
-
Given B
|
8
|
-
When C
|
9
|
-
Then D
|
10
|
-
Then E
|
11
|
-
"""
|
12
|
-
Then the formatted steps are
|
13
|
-
"""
|
14
|
-
Given A
|
15
|
-
And B
|
16
|
-
When C
|
17
|
-
Then D
|
18
|
-
And E
|
19
|
-
"""
|
20
|
-
|
21
|
-
Scenario: formatted steps
|
22
|
-
Given steps
|
23
|
-
"""
|
24
|
-
Given A
|
25
|
-
And B
|
26
|
-
When C
|
27
|
-
Then D
|
28
|
-
And E
|
29
|
-
"""
|
30
|
-
Then the steps are formatted
|
@@ -1,45 +0,0 @@
|
|
1
|
-
Feature: table formatter
|
2
|
-
|
3
|
-
Scenario: minimal table
|
4
|
-
Given table lines
|
5
|
-
"""
|
6
|
-
|header_column1|header_column2|
|
7
|
-
|row1_column1|row1_column2|
|
8
|
-
|row2_column1|row2_column2|
|
9
|
-
|row3_column1|row3_column2|
|
10
|
-
"""
|
11
|
-
Then the formatted table lines are
|
12
|
-
"""
|
13
|
-
| header_column1 | header_column2 |
|
14
|
-
| row1_column1 | row1_column2 |
|
15
|
-
| row2_column1 | row2_column2 |
|
16
|
-
| row3_column1 | row3_column2 |
|
17
|
-
"""
|
18
|
-
|
19
|
-
|
20
|
-
Scenario: misaligned spacing in table
|
21
|
-
Given table lines
|
22
|
-
"""
|
23
|
-
| header_column1 | header_column2 |
|
24
|
-
| row1_column1 | row1_column2 |
|
25
|
-
| row2_column1 | row2_column2 |
|
26
|
-
| row3_column1 | row3_column2 |
|
27
|
-
"""
|
28
|
-
Then the formatted table lines are
|
29
|
-
"""
|
30
|
-
| header_column1 | header_column2 |
|
31
|
-
| row1_column1 | row1_column2 |
|
32
|
-
| row2_column1 | row2_column2 |
|
33
|
-
| row3_column1 | row3_column2 |
|
34
|
-
"""
|
35
|
-
|
36
|
-
|
37
|
-
Scenario: formatted table
|
38
|
-
Given table lines
|
39
|
-
"""
|
40
|
-
| header_column1 | header_column2 |
|
41
|
-
| row1_column1 | row1_column2 |
|
42
|
-
| row2_column1 | row2_column2 |
|
43
|
-
| row3_column1 | row3_column2 |
|
44
|
-
"""
|
45
|
-
Then the table is formatted
|
@@ -1,15 +0,0 @@
|
|
1
|
-
Given(/^steps$/) do |steps|
|
2
|
-
@steps = steps.split("\n", -1)
|
3
|
-
end
|
4
|
-
|
5
|
-
|
6
|
-
Then(/^the formatted steps are$/) do |steps|
|
7
|
-
expected = steps.split("\n", -1)
|
8
|
-
actual = CucumberLint::StepsFormatter.new(@steps).formatted_content
|
9
|
-
expect(actual).to eql expected
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
Then(/^the steps are formatted$/) do
|
14
|
-
expect(CucumberLint::StepsFormatter.new(@steps)).to be_formatted
|
15
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
Given(/^table lines$/) do |lines|
|
2
|
-
@lines = lines.split("\n", -1)
|
3
|
-
end
|
4
|
-
|
5
|
-
|
6
|
-
Then(/^the formatted table lines are$/) do |lines|
|
7
|
-
expected = lines.split("\n", -1)
|
8
|
-
actual = CucumberLint::TableFormatter.new(@lines).formatted_content
|
9
|
-
expect(actual).to eql expected
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
Then(/^the table is formatted$/) do
|
14
|
-
expect(CucumberLint::TableFormatter.new(@lines)).to be_formatted
|
15
|
-
end
|
data/lib/core_ext/array.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# Monkey-patching Array
|
2
|
-
class Array
|
3
|
-
|
4
|
-
def group
|
5
|
-
groups = []
|
6
|
-
last_group = { passing: true, values: [] }
|
7
|
-
|
8
|
-
each do |element|
|
9
|
-
passing = yield element
|
10
|
-
|
11
|
-
if passing != last_group[:passing]
|
12
|
-
groups << last_group unless last_group[:values].empty?
|
13
|
-
last_group = { passing: passing, values: [] }
|
14
|
-
end
|
15
|
-
|
16
|
-
last_group[:values] << element
|
17
|
-
end
|
18
|
-
|
19
|
-
groups + [last_group]
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'core_ext/array'
|
2
|
-
|
3
|
-
module CucumberLint
|
4
|
-
# A class that takes in the content that make up a cucumber feature
|
5
|
-
# and can determine if it is formatted and output the formatted content
|
6
|
-
class FeatureFormatter
|
7
|
-
|
8
|
-
attr_reader :formatted_content
|
9
|
-
|
10
|
-
def initialize content
|
11
|
-
@content = content
|
12
|
-
@formatted_content = format
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
def formatted?
|
17
|
-
@content == @formatted_content
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
|
24
|
-
def format
|
25
|
-
lines = format_steps @content.split("\n", -1)
|
26
|
-
groupings = lines.group { |line| line =~ /^\s*\|/ }
|
27
|
-
|
28
|
-
groupings.map do |group|
|
29
|
-
if group[:passing]
|
30
|
-
format_table group[:values]
|
31
|
-
else
|
32
|
-
group[:values]
|
33
|
-
end
|
34
|
-
end.flatten.join("\n")
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
def format_table lines
|
39
|
-
TableFormatter.new(lines).formatted_content
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
|
-
def format_steps steps
|
44
|
-
StepsFormatter.new(steps).formatted_content
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module CucumberLint
|
2
|
-
# A class that takes in the lines of a cucumber feature
|
3
|
-
# and can determine if the steps are formatted and output the formatted steps
|
4
|
-
class StepsFormatter
|
5
|
-
|
6
|
-
attr_reader :formatted_content
|
7
|
-
|
8
|
-
def initialize lines
|
9
|
-
@lines = lines
|
10
|
-
@formatted_content = format
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
def formatted?
|
15
|
-
@lines == @formatted_content
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
RESET_KEYWORDS = %w(Background Scenario)
|
21
|
-
STEP_TYPES = %w(Given When Then)
|
22
|
-
|
23
|
-
def format
|
24
|
-
@lines.map { |line| format_line line }
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
def format_line line
|
29
|
-
@previous_step_type = nil if should_reset_previous_step_type? line
|
30
|
-
|
31
|
-
step_type = line.split(' ', -1)[0]
|
32
|
-
|
33
|
-
if STEP_TYPES.include?(step_type)
|
34
|
-
if @previous_step_type == step_type
|
35
|
-
line.sub! step_type, 'And'
|
36
|
-
else
|
37
|
-
@previous_step_type = step_type
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
line
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
def should_reset_previous_step_type? line
|
46
|
-
RESET_KEYWORDS.any? { |keyword| line.start_with? keyword }
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
module CucumberLint
|
2
|
-
# A class that takes in the lines that make up a cucumber table
|
3
|
-
# and can determine if it is formatted and output the formatted table
|
4
|
-
class TableFormatter
|
5
|
-
|
6
|
-
attr_reader :formatted_content
|
7
|
-
|
8
|
-
def initialize lines
|
9
|
-
@lines = lines
|
10
|
-
@column_widths = column_widths
|
11
|
-
@formatted_content = format
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
def formatted?
|
16
|
-
@lines == @formatted_content
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
|
23
|
-
def column_widths
|
24
|
-
widths_by_line = @lines.map { |line| line_column_widths line }
|
25
|
-
grouped_widths = widths_by_line[0].zip(*widths_by_line[1..-1])
|
26
|
-
grouped_widths.each_with_index.map do |width, i|
|
27
|
-
i == 0 ? width.min : width.max
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
def format
|
33
|
-
@lines.each_with_index.map do |line|
|
34
|
-
line.split('|', -1).each_with_index.map do |piece, index|
|
35
|
-
format_piece piece, index
|
36
|
-
end.join('|')
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
def format_piece piece, index
|
42
|
-
if index == 0
|
43
|
-
' ' * column_widths[index]
|
44
|
-
elsif index == column_widths.length - 1
|
45
|
-
piece
|
46
|
-
else
|
47
|
-
" #{piece.strip} ".ljust column_widths[index]
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
def line_column_widths line
|
53
|
-
pieces = line.split('|', -1)
|
54
|
-
pieces.each_with_index.map do |piece, index|
|
55
|
-
if index == 0 || index == pieces.length - 1
|
56
|
-
piece.length
|
57
|
-
else
|
58
|
-
piece.strip!
|
59
|
-
piece.length + 2 # one space padding on each side
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
end
|
data/spec/core_ext/array_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'core_ext/array'
|
2
|
-
|
3
|
-
describe Array do
|
4
|
-
describe '#group' do
|
5
|
-
it 'returns elements grouped by whether of not they pass the given block' do
|
6
|
-
array = [1, 1, 2, 3, 5, 8, 13, 21, 34]
|
7
|
-
expected = array.group(&:odd?)
|
8
|
-
actual = [
|
9
|
-
{ passing: true, values: [1, 1] },
|
10
|
-
{ passing: false, values: [2] },
|
11
|
-
{ passing: true, values: [3, 5] },
|
12
|
-
{ passing: false, values: [8] },
|
13
|
-
{ passing: true, values: [13, 21] },
|
14
|
-
{ passing: false, values: [34] }
|
15
|
-
]
|
16
|
-
expect(expected).to eql actual
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|