cuke_sniffer 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/cuke_sniffer.rb +51 -34
- data/lib/cuke_sniffer.rb +13 -13
- data/lib/cuke_sniffer/cli.rb +246 -226
- data/lib/cuke_sniffer/constants.rb +22 -35
- data/lib/cuke_sniffer/feature.rb +107 -116
- data/lib/cuke_sniffer/report/markup.rhtml +385 -310
- data/lib/cuke_sniffer/rule_config.rb +161 -161
- data/lib/cuke_sniffer/rules_evaluator.rb +50 -41
- data/lib/cuke_sniffer/scenario.rb +164 -163
- data/lib/cuke_sniffer/step_definition.rb +143 -116
- metadata +10 -4
@@ -1,116 +1,143 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@
|
18
|
-
|
19
|
-
|
20
|
-
@
|
21
|
-
|
22
|
-
raw_code.
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
def
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
def
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
1
|
+
module CukeSniffer
|
2
|
+
class StepDefinition < RulesEvaluator
|
3
|
+
include CukeSniffer::Constants
|
4
|
+
include CukeSniffer::RuleConfig
|
5
|
+
|
6
|
+
SIMPLE_NESTED_STEP_REGEX = /steps\s"#{STEP_STYLES}(?<step_string>.*)"$/
|
7
|
+
SAME_LINE_COMPLEX_STEP_REGEX = /^steps\s%Q?{#{STEP_STYLES}(?<step_string>.*)}$/
|
8
|
+
START_COMPLEX_STEP_REGEX = /^steps\s%Q?\{\s*/
|
9
|
+
END_COMPLEX_STEP_REGEX = /}$/
|
10
|
+
START_COMPLEX_WITH_STEP_REGEX = /steps\s%Q?\{#{STEP_STYLES}(?<step_string>.*)$/
|
11
|
+
END_COMPLEX_WITH_STEP_REGEX = /#{STEP_STYLES}(?<step_string>.*)}$/
|
12
|
+
attr_accessor :start_line, :regex, :code, :parameters, :calls, :nested_steps
|
13
|
+
|
14
|
+
def initialize(location, raw_code)
|
15
|
+
super(location)
|
16
|
+
|
17
|
+
@parameters = []
|
18
|
+
@calls = {}
|
19
|
+
@nested_steps = {}
|
20
|
+
@start_line = location.match(/:(?<line>\d*)/)[:line].to_i
|
21
|
+
|
22
|
+
end_match_index = (raw_code.size - 1) - raw_code.reverse.index("end")
|
23
|
+
@code = raw_code[1...end_match_index]
|
24
|
+
|
25
|
+
raw_code.each do |line|
|
26
|
+
if line =~ STEP_DEFINITION_REGEX
|
27
|
+
matches = STEP_DEFINITION_REGEX.match(line)
|
28
|
+
@regex = Regexp.new(matches[:step])
|
29
|
+
@parameters = matches[:parameters].split(",") unless matches[:parameters].nil?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
detect_nested_steps
|
34
|
+
evaluate_score
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_call(location, step_string)
|
38
|
+
@calls[location] = step_string
|
39
|
+
end
|
40
|
+
|
41
|
+
def detect_nested_steps
|
42
|
+
multi_line_step_flag = false
|
43
|
+
counter = 1
|
44
|
+
@code.each do |line|
|
45
|
+
regex = nil
|
46
|
+
case line
|
47
|
+
when SIMPLE_NESTED_STEP_REGEX
|
48
|
+
regex = SIMPLE_NESTED_STEP_REGEX
|
49
|
+
when SAME_LINE_COMPLEX_STEP_REGEX
|
50
|
+
regex = SAME_LINE_COMPLEX_STEP_REGEX
|
51
|
+
when START_COMPLEX_WITH_STEP_REGEX
|
52
|
+
multi_line_step_flag = true
|
53
|
+
regex = START_COMPLEX_WITH_STEP_REGEX
|
54
|
+
when START_COMPLEX_STEP_REGEX
|
55
|
+
multi_line_step_flag = true
|
56
|
+
when END_COMPLEX_WITH_STEP_REGEX
|
57
|
+
if line =~ /[#]{.*}$/ && multi_line_step_flag
|
58
|
+
regex = STEP_REGEX
|
59
|
+
else
|
60
|
+
regex = END_COMPLEX_WITH_STEP_REGEX
|
61
|
+
multi_line_step_flag = false
|
62
|
+
end
|
63
|
+
when STEP_REGEX
|
64
|
+
regex = STEP_REGEX if multi_line_step_flag
|
65
|
+
when END_COMPLEX_STEP_REGEX
|
66
|
+
multi_line_step_flag = false
|
67
|
+
else
|
68
|
+
end
|
69
|
+
|
70
|
+
if regex
|
71
|
+
index = 0
|
72
|
+
while line.include?('#{') and index <= line.length
|
73
|
+
index = line.index('#{')
|
74
|
+
replace_string = ""
|
75
|
+
while index <= line.length and line[index - 1] != "}"
|
76
|
+
replace_string << line[index]
|
77
|
+
index += 1
|
78
|
+
end
|
79
|
+
line.gsub!(replace_string, "variable")
|
80
|
+
end
|
81
|
+
|
82
|
+
match = regex.match(line)
|
83
|
+
nested_step_line = (@start_line + counter)
|
84
|
+
@nested_steps[location.gsub(/:\d*/, ":" + nested_step_line.to_s)] = match[:step_string]
|
85
|
+
end
|
86
|
+
counter += 1
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def condensed_call_list
|
91
|
+
condensed_list = {}
|
92
|
+
@calls.each{|call, step_string|
|
93
|
+
condensed_list[step_string] ||= []
|
94
|
+
condensed_list[step_string] << call
|
95
|
+
}
|
96
|
+
condensed_list
|
97
|
+
end
|
98
|
+
|
99
|
+
def ==(comparison_object)
|
100
|
+
super(comparison_object)
|
101
|
+
comparison_object.regex == regex
|
102
|
+
comparison_object.code == code
|
103
|
+
comparison_object.parameters == parameters
|
104
|
+
comparison_object.calls == calls
|
105
|
+
comparison_object.nested_steps == nested_steps
|
106
|
+
end
|
107
|
+
|
108
|
+
def evaluate_score
|
109
|
+
super
|
110
|
+
rule_no_code
|
111
|
+
rule_too_many_parameters
|
112
|
+
rule_nested_steps
|
113
|
+
rule_recursive_nested_step
|
114
|
+
rule_commented_code
|
115
|
+
end
|
116
|
+
|
117
|
+
def rule_no_code
|
118
|
+
store_rule(STEP_DEFINITION_RULES[:no_code]) if code.empty?
|
119
|
+
end
|
120
|
+
|
121
|
+
def rule_too_many_parameters
|
122
|
+
rule = STEP_DEFINITION_RULES[:too_many_parameters]
|
123
|
+
store_rule(rule) if parameters.size >= rule[:max]
|
124
|
+
end
|
125
|
+
|
126
|
+
def rule_nested_steps
|
127
|
+
store_rule(STEP_DEFINITION_RULES[:nested_step]) unless nested_steps.empty?
|
128
|
+
end
|
129
|
+
|
130
|
+
def rule_recursive_nested_step
|
131
|
+
nested_steps.each_value do |nested_step|
|
132
|
+
store_rule(STEP_DEFINITION_RULES[:recursive_nested_step]) if nested_step =~ regex
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def rule_commented_code
|
137
|
+
code.each do |line|
|
138
|
+
store_rule(STEP_DEFINITION_RULES[:commented_code]) if is_comment?(line)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuke_sniffer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,10 +11,10 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-
|
14
|
+
date: 2013-02-15 00:00:00.000000000 Z
|
15
15
|
dependencies: []
|
16
16
|
description: A ruby library used to root out smells in your cukes.
|
17
|
-
email:
|
17
|
+
email: ''
|
18
18
|
executables:
|
19
19
|
- cuke_sniffer.rb
|
20
20
|
extensions: []
|
@@ -43,15 +43,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
hash: -320967053
|
46
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
50
|
none: false
|
48
51
|
requirements:
|
49
52
|
- - ! '>='
|
50
53
|
- !ruby/object:Gem::Version
|
51
54
|
version: '0'
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
hash: -320967053
|
52
58
|
requirements: []
|
53
59
|
rubyforge_project:
|
54
|
-
rubygems_version: 1.8.
|
60
|
+
rubygems_version: 1.8.24
|
55
61
|
signing_key:
|
56
62
|
specification_version: 3
|
57
63
|
summary: CukeSniffer
|