cuke_sniffer 0.0.7 → 0.0.8
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.
- data/lib/cuke_sniffer.rb +8 -23
- data/lib/cuke_sniffer/cli.rb +38 -5
- data/lib/cuke_sniffer/constants.rb +1 -1
- data/lib/cuke_sniffer/cuke_sniffer_helper.rb +1 -1
- data/lib/cuke_sniffer/dead_steps_helper.rb +1 -1
- data/lib/cuke_sniffer/feature.rb +109 -104
- data/lib/cuke_sniffer/feature_rules_evaluator.rb +55 -56
- data/lib/cuke_sniffer/formatter.rb +1 -1
- data/lib/cuke_sniffer/hook.rb +103 -77
- data/lib/cuke_sniffer/report/rules.html.erb +0 -5
- data/lib/cuke_sniffer/rule.rb +26 -27
- data/lib/cuke_sniffer/rule_config.rb +114 -128
- data/lib/cuke_sniffer/rule_target.rb +78 -62
- data/lib/cuke_sniffer/rules_evaluator.rb +52 -64
- data/lib/cuke_sniffer/scenario.rb +123 -102
- data/lib/cuke_sniffer/step_definition.rb +176 -163
- data/lib/cuke_sniffer/summary_helper.rb +1 -1
- data/lib/cuke_sniffer/summary_node.rb +17 -18
- metadata +2 -2
@@ -1,163 +1,176 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
xml_accessor :
|
12
|
-
xml_accessor :
|
13
|
-
xml_accessor :
|
14
|
-
xml_accessor :
|
15
|
-
xml_accessor :
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
condensed_list[step_string]
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
def
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
def
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
1
|
+
module CukeSniffer
|
2
|
+
|
3
|
+
# Author:: Robert Cochran (mailto:cochrarj@miamioh.edu)
|
4
|
+
# Copyright:: Copyright (C) 2014 Robert Cochran
|
5
|
+
# License:: Distributes under the MIT License
|
6
|
+
# Translates and evaluates Cucumber step definitions
|
7
|
+
# Extends CukeSniffer::RulesEvaluator
|
8
|
+
class StepDefinition < RuleTarget
|
9
|
+
|
10
|
+
xml_accessor :start_line
|
11
|
+
xml_accessor :regex
|
12
|
+
xml_accessor :parameters, :as => [], :in => "parameters"
|
13
|
+
xml_accessor :nested_steps, :as => {:key => 'location', :value => 'call'}, :in => "nested_steps"
|
14
|
+
xml_accessor :calls, :as => {:key => 'location', :value => 'call'}, :in => "calls"
|
15
|
+
xml_accessor :code, :as => [], :in => "code"
|
16
|
+
|
17
|
+
# int: Line on which a step definition starts
|
18
|
+
attr_accessor :start_line
|
19
|
+
|
20
|
+
# Regex: Regex that cucumber uses to match step calls
|
21
|
+
attr_accessor :regex
|
22
|
+
|
23
|
+
# string array: List of the parameters a step definition has
|
24
|
+
attr_accessor :parameters
|
25
|
+
|
26
|
+
# hash: Contains each nested step call a step definition has
|
27
|
+
# * Key: location:line of the nested step
|
28
|
+
# * Value: The step call that appears on the line
|
29
|
+
attr_accessor :nested_steps
|
30
|
+
|
31
|
+
# hash: Contains each call that is made to a step definition
|
32
|
+
# * Key: Location in which the step definition is called from
|
33
|
+
# * Value: The step string that matched the regex
|
34
|
+
# In the case of a fuzzy match it will be a regex of the
|
35
|
+
# step call that was the inverse match of the regex translated
|
36
|
+
# into a string.
|
37
|
+
attr_accessor :calls
|
38
|
+
|
39
|
+
# string array: List of all of the content between the regex and the end of the step definition.
|
40
|
+
attr_accessor :code
|
41
|
+
|
42
|
+
# location must be in the format of "file_path\file_name.rb:line_number"
|
43
|
+
# step_definition_block is an array of strings that represents the step definition
|
44
|
+
# must contain the regex line and its pairing end
|
45
|
+
def initialize(location, step_definition_block)
|
46
|
+
@parameters = []
|
47
|
+
@calls = {}
|
48
|
+
@nested_steps = {}
|
49
|
+
super(location)
|
50
|
+
extract_start_line(location)
|
51
|
+
extract_code(step_definition_block)
|
52
|
+
extract_step_definition_signature(step_definition_block)
|
53
|
+
|
54
|
+
detect_nested_steps
|
55
|
+
end
|
56
|
+
|
57
|
+
# Adds new location => step_string pairs to the calls hash
|
58
|
+
def add_call(location, step_string)
|
59
|
+
@calls[location] = step_string
|
60
|
+
end
|
61
|
+
|
62
|
+
def ==(comparison_object) # :nodoc:
|
63
|
+
comparison_object.regex == regex && comparison_object.parameters == parameters
|
64
|
+
end
|
65
|
+
|
66
|
+
def condensed_call_list
|
67
|
+
condensed_list = {}
|
68
|
+
@calls.each do |call, step_string|
|
69
|
+
condensed_list[step_string] ||= []
|
70
|
+
condensed_list[step_string] << call
|
71
|
+
end
|
72
|
+
condensed_list
|
73
|
+
end
|
74
|
+
|
75
|
+
def recursive_nested_steps
|
76
|
+
recursive_nested_steps_map = {}
|
77
|
+
@nested_steps.each{|location, nested_step|
|
78
|
+
if nested_step =~ @regex
|
79
|
+
recursive_nested_steps_map[location] = nested_step
|
80
|
+
end
|
81
|
+
}
|
82
|
+
recursive_nested_steps_map
|
83
|
+
end
|
84
|
+
|
85
|
+
def todo
|
86
|
+
@code.select {|line|line =~ /#(TODO|todo)/ }
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
SIMPLE_NESTED_STEP_REGEX = /steps?\s"#{STEP_STYLES}(?<step_string>.*)"$/ # :nodoc:
|
92
|
+
START_COMPLEX_STEP_REGEX = /^steps?\s%(q|Q)?\{\s*/ # :nodoc:
|
93
|
+
SAME_LINE_COMPLEX_STEP_REGEX = /#{START_COMPLEX_STEP_REGEX}#{STEP_STYLES}(?<step_string>.*)}$/ # :nodoc:
|
94
|
+
END_COMPLEX_STEP_REGEX = /}$/ # :nodoc:
|
95
|
+
START_COMPLEX_WITH_STEP_REGEX = /#{START_COMPLEX_STEP_REGEX}#{STEP_STYLES}(?<step_string>.*)$/ # :nodoc:
|
96
|
+
END_COMPLEX_WITH_STEP_REGEX = /#{STEP_STYLES}(?<step_string>.*)}$/ # :nodoc:
|
97
|
+
|
98
|
+
def detect_nested_steps
|
99
|
+
multi_line_step_flag = false
|
100
|
+
counter = 1
|
101
|
+
@code.each do |line|
|
102
|
+
regex = nil
|
103
|
+
case line
|
104
|
+
when SIMPLE_NESTED_STEP_REGEX
|
105
|
+
regex = SIMPLE_NESTED_STEP_REGEX
|
106
|
+
when SAME_LINE_COMPLEX_STEP_REGEX
|
107
|
+
regex = SAME_LINE_COMPLEX_STEP_REGEX
|
108
|
+
when START_COMPLEX_WITH_STEP_REGEX
|
109
|
+
if line =~ /\}$/
|
110
|
+
if line.include?('#{')
|
111
|
+
reversed_line = line.reverse
|
112
|
+
last_capture = reversed_line[0..reversed_line.index('#')].reverse
|
113
|
+
if last_capture =~ /{.*}$/
|
114
|
+
multi_line_step_flag = true
|
115
|
+
regex = START_COMPLEX_WITH_STEP_REGEX
|
116
|
+
else
|
117
|
+
regex = SAME_LINE_COMPLEX_STEP_REGEX
|
118
|
+
end
|
119
|
+
else
|
120
|
+
regex = SAME_LINE_COMPLEX_STEP_REGEX
|
121
|
+
end
|
122
|
+
else
|
123
|
+
multi_line_step_flag = true
|
124
|
+
regex = START_COMPLEX_WITH_STEP_REGEX
|
125
|
+
end
|
126
|
+
when END_COMPLEX_WITH_STEP_REGEX
|
127
|
+
if line =~ /[#]{.*}$/ && multi_line_step_flag
|
128
|
+
regex = STEP_REGEX
|
129
|
+
else
|
130
|
+
regex = END_COMPLEX_WITH_STEP_REGEX
|
131
|
+
multi_line_step_flag = false
|
132
|
+
end
|
133
|
+
when START_COMPLEX_STEP_REGEX
|
134
|
+
multi_line_step_flag = true
|
135
|
+
when STEP_REGEX
|
136
|
+
regex = STEP_REGEX if multi_line_step_flag
|
137
|
+
when END_COMPLEX_STEP_REGEX
|
138
|
+
multi_line_step_flag = false
|
139
|
+
else
|
140
|
+
end
|
141
|
+
|
142
|
+
if regex and !is_comment?(line)
|
143
|
+
match = regex.match(line)
|
144
|
+
nested_step_line = (@start_line + counter)
|
145
|
+
@nested_steps[location.gsub(/:\d*$/, ":" + nested_step_line.to_s)] = match[:step_string].gsub("\\", "")
|
146
|
+
end
|
147
|
+
counter += 1
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def extract_step_definition_signature(step_definition_block)
|
152
|
+
regex_line = find_regex_line(step_definition_block)
|
153
|
+
unless regex_line.nil?
|
154
|
+
matches = STEP_DEFINITION_REGEX.match(regex_line)
|
155
|
+
@regex = Regexp.new(matches[:step])
|
156
|
+
@parameters = matches[:parameters].split(/,\s*/).collect { |param| param.strip } if matches[:parameters]
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def extract_start_line(location)
|
161
|
+
@start_line = location.match(/:(?<line>\d*)$/)[:line].to_i
|
162
|
+
end
|
163
|
+
|
164
|
+
def extract_code(step_definition_block)
|
165
|
+
end_match_index = (step_definition_block.size - 1) - step_definition_block.reverse.index("end")
|
166
|
+
@code = step_definition_block[1...end_match_index]
|
167
|
+
end
|
168
|
+
|
169
|
+
def find_regex_line(step_definition_block)
|
170
|
+
step_definition_block.each do |line|
|
171
|
+
return line if line =~ STEP_DEFINITION_REGEX
|
172
|
+
end
|
173
|
+
nil
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module CukeSniffer
|
2
2
|
# Author:: Robert Cochran (mailto:cochrarj@miamioh.edu)
|
3
|
-
# Copyright:: Copyright (C)
|
3
|
+
# Copyright:: Copyright (C) 2014 Robert Cochran
|
4
4
|
# License:: Distributes under the MIT License
|
5
5
|
# Mixins: CukeSniffer::Constants
|
6
6
|
# A static class used to help with handling summary data for CukeSniffer::CLI
|
@@ -1,19 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
xml_accessor :
|
12
|
-
xml_accessor :
|
13
|
-
xml_accessor :
|
14
|
-
xml_accessor :
|
15
|
-
xml_accessor :
|
16
|
-
|
17
|
-
|
18
|
-
|
1
|
+
module CukeSniffer
|
2
|
+
|
3
|
+
# Author:: Robert Cochran (mailto:cochrarj@miamioh.edu)
|
4
|
+
# Copyright:: Copyright (C) 2014 Robert Cochran
|
5
|
+
# License:: Distributes under the MIT License
|
6
|
+
# Single Summary Node object used for passing around results data and serializing out to xml
|
7
|
+
# Mixins: ROXML
|
8
|
+
class SummaryNode
|
9
|
+
include ROXML
|
10
|
+
xml_accessor :score
|
11
|
+
xml_accessor :count
|
12
|
+
xml_accessor :average
|
13
|
+
xml_accessor :good
|
14
|
+
xml_accessor :bad
|
15
|
+
xml_accessor :threshold
|
16
|
+
end # :nodoc:
|
17
|
+
|
19
18
|
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.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2014-04-01 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: roxml
|