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