cuke_sniffer 0.0.8 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/cuke_sniffer +4 -1
- data/lib/cuke_sniffer/cli.rb +15 -4
- data/lib/cuke_sniffer/cuke_sniffer_helper.rb +4 -3
- data/lib/cuke_sniffer/dead_steps_helper.rb +53 -53
- data/lib/cuke_sniffer/formatter.rb +166 -125
- data/lib/cuke_sniffer/js/cuke_sniffer.js +184 -0
- data/lib/cuke_sniffer/report/css.html.erb +122 -132
- data/lib/cuke_sniffer/report/dead_steps.html.erb +61 -61
- data/lib/cuke_sniffer/report/dead_steps_min.html.erb +23 -0
- data/lib/cuke_sniffer/report/expand_and_collapse_buttons.html.erb +8 -0
- data/lib/cuke_sniffer/report/features.html.erb +124 -106
- data/lib/cuke_sniffer/report/hooks.html.erb +76 -76
- data/lib/cuke_sniffer/report/improvement_list.html.erb +34 -24
- data/lib/cuke_sniffer/report/information.html.erb +81 -0
- data/lib/cuke_sniffer/report/js.html.erb +9 -65
- data/lib/cuke_sniffer/report/min_template.html.erb +12 -7
- data/lib/cuke_sniffer/report/rules.html.erb +100 -68
- data/lib/cuke_sniffer/report/standard_template.html.erb +16 -12
- data/lib/cuke_sniffer/report/step_definitions.html.erb +69 -63
- data/lib/cuke_sniffer/report/summary.html.erb +131 -96
- data/lib/cuke_sniffer/report/title.html.erb +13 -9
- data/lib/cuke_sniffer/rule.rb +1 -0
- data/lib/cuke_sniffer/rule_config.rb +2 -2
- data/lib/cuke_sniffer/rules_evaluator.rb +1 -2
- data/lib/cuke_sniffer/scenario.rb +67 -23
- data/lib/cuke_sniffer/summary_helper.rb +90 -90
- metadata +31 -46
- data/lib/cuke_sniffer/report/legend.html.erb +0 -167
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 08622ee3780b51802880b03e082b31e87276a0ae
|
4
|
+
data.tar.gz: face498e4e3bcfe632b1f7fc1fdc15c71514ee6f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8b3f1802e042beefe36c066c01699c3bcc1fc3cfa75818749a3c070a52e84dee5e166e211e6a33ee0bed3aaed33aa7ddac8bd43855aa573e61440b4ebdb9d5db
|
7
|
+
data.tar.gz: 9693a75b3eb0321b14212cde4b3179b69b51096f8ce1b0bbfcf999aedb825f6256a8f1304dab9507625ede083799b9539d00c04eb263ec3c12d2b5e64df4382a
|
data/bin/cuke_sniffer
CHANGED
@@ -6,7 +6,7 @@ require 'cuke_sniffer'
|
|
6
6
|
help_cmd_txt = "Welcome to CukeSniffer!
|
7
7
|
Calling CukeSniffer with no arguments will run it against the current directory.
|
8
8
|
Other Options for Running include:
|
9
|
-
-o, --out <type> (name) : Where <type> is 'html', 'min_html' or 'xml'.
|
9
|
+
-o, --out <type> (name) : Where <type> is 'html', 'min_html', 'junit_xml' or 'xml'.
|
10
10
|
Runs CukeSniffer then outputs an
|
11
11
|
html/xml file in the current
|
12
12
|
directory (with optional name).
|
@@ -50,6 +50,7 @@ def handle_output(argv)
|
|
50
50
|
:html => "html",
|
51
51
|
:min_html => "min_html",
|
52
52
|
:xml => "xml",
|
53
|
+
:junit_xml => "junit_xml",
|
53
54
|
}
|
54
55
|
output_type_hash.each_value do |value|
|
55
56
|
index_of_key = argv.index(value)
|
@@ -72,6 +73,8 @@ def call_output(file_type, file_name)
|
|
72
73
|
file_name.nil? ? @cuke_sniffer.output_html : @cuke_sniffer.output_html(file_name)
|
73
74
|
when "min_html"
|
74
75
|
file_name.nil? ? @cuke_sniffer.output_min_html : @cuke_sniffer.output_min_html(file_name)
|
76
|
+
when "junit_xml"
|
77
|
+
file_name.nil? ? @cuke_sniffer.output_junit_xml : @cuke_sniffer.output_junit_xml(file_name)
|
75
78
|
else
|
76
79
|
puts "#{file_type} is not a supported version of cuke_sniffer output."
|
77
80
|
end
|
data/lib/cuke_sniffer/cli.rb
CHANGED
@@ -149,6 +149,15 @@ module CukeSniffer
|
|
149
149
|
CukeSniffer::Formatter.output_xml(self, file_name)
|
150
150
|
end
|
151
151
|
|
152
|
+
# Creates a xml file with the collected project details
|
153
|
+
# file_name defaults to "cuke_sniffer.xml" unless specified
|
154
|
+
# cuke_sniffer.output_xml
|
155
|
+
# Or
|
156
|
+
# cuke_sniffer.output_xml("cuke_sniffer01-01-0001.xml")
|
157
|
+
def output_junit_xml(file_name = DEFAULT_OUTPUT_FILE_NAME + ".xml")
|
158
|
+
CukeSniffer::Formatter.output_junit_xml(self, file_name)
|
159
|
+
end
|
160
|
+
|
152
161
|
# Gathers all StepDefinitions that have no calls
|
153
162
|
# Returns a hash that has two different types of records
|
154
163
|
# 1: String of the file with a dead step with an array of the line and regex of each dead step
|
@@ -205,9 +214,11 @@ module CukeSniffer
|
|
205
214
|
end
|
206
215
|
|
207
216
|
def initialize_locations(parameters)
|
208
|
-
|
209
|
-
|
210
|
-
@
|
217
|
+
default_location = parameters[:project_location] || Dir.getwd
|
218
|
+
|
219
|
+
@features_location = parameters[:features_location] || default_location
|
220
|
+
@step_definitions_location = parameters[:step_definitions_location] || default_location
|
221
|
+
@hooks_location = parameters[:hooks_location] || default_location
|
211
222
|
end
|
212
223
|
|
213
224
|
def initialize_feature_objects
|
@@ -260,7 +271,7 @@ module CukeSniffer
|
|
260
271
|
if File.file?(pattern_location)
|
261
272
|
[pattern_location]
|
262
273
|
else
|
263
|
-
Dir["#{pattern_location}/**/*.#{extension}"]
|
274
|
+
Dir["#{pattern_location}/**/*.#{extension}"].select { |f| File.file? f }
|
264
275
|
end
|
265
276
|
end
|
266
277
|
end
|
@@ -86,14 +86,15 @@ module CukeSniffer
|
|
86
86
|
# Builds a list of rule objects out of a hash. See CukeSniffer::RulesConfig for hash example.
|
87
87
|
def self.build_rules(rules)
|
88
88
|
return [] if rules.nil?
|
89
|
-
rules.collect do |
|
90
|
-
CukeSniffer::CukeSnifferHelper.build_rule(value)
|
89
|
+
rules.collect do |symbol, value|
|
90
|
+
CukeSniffer::CukeSnifferHelper.build_rule(symbol, value)
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
94
|
# Builds rule object out of a hash. See CukeSniffer::RulesConfig for hash example.
|
95
|
-
def self.build_rule(rule_hash)
|
95
|
+
def self.build_rule(symbol, rule_hash)
|
96
96
|
rule = CukeSniffer::Rule.new
|
97
|
+
rule.symbol = symbol
|
97
98
|
rule.phrase = rule_hash[:phrase]
|
98
99
|
rule.score = rule_hash[:score]
|
99
100
|
rule.enabled = rule_hash[:enabled]
|
@@ -1,54 +1,54 @@
|
|
1
|
-
module CukeSniffer
|
2
|
-
# Author:: Robert Cochran (mailto:cochrarj@miamioh.edu)
|
3
|
-
# Copyright:: Copyright (C) 2014 Robert Cochran
|
4
|
-
# License:: Distributes under the MIT License
|
5
|
-
# Mixins: CukeSniffer::Constants
|
6
|
-
# A static class to aid in the identification of dead steps.
|
7
|
-
class DeadStepsHelper
|
8
|
-
include CukeSniffer::Constants
|
9
|
-
|
10
|
-
# Returns a hash of dead steps for displaying in the html.
|
11
|
-
def self.build_dead_steps_hash(step_definitions)
|
12
|
-
dead_steps_hash = gather_all_dead_steps_by_file(step_definitions)
|
13
|
-
sort_dead_steps_in_file!(dead_steps_hash)
|
14
|
-
dead_steps_hash[:total] = count_dead_steps(dead_steps_hash)
|
15
|
-
dead_steps_hash
|
16
|
-
end
|
17
|
-
|
18
|
-
# Returns all dead step definitions in a file
|
19
|
-
def self.gather_all_dead_steps_by_file(step_definitions)
|
20
|
-
dead_steps_hash = {}
|
21
|
-
step_definitions.each do |step_definition|
|
22
|
-
location_match = step_definition.location.match(/(?<file>.*).rb:(?<line>\d+)/)
|
23
|
-
file_name = location_match[:file]
|
24
|
-
regex = format_step_definition_regex(step_definition.regex)
|
25
|
-
if step_definition.calls.empty?
|
26
|
-
dead_steps_hash[file_name] ||= []
|
27
|
-
dead_steps_hash[file_name] << "#{location_match[:line]}: /#{regex}/"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
dead_steps_hash
|
31
|
-
end
|
32
|
-
|
33
|
-
# Formats the regex of a step definition to remove the (?-mix) part of the to_s
|
34
|
-
def self.format_step_definition_regex(regex)
|
35
|
-
regex.to_s.match(/\(\?\-mix\:(?<regex>.*)\)/)[:regex]
|
36
|
-
end
|
37
|
-
|
38
|
-
# Sorts the dead steps found in a hash by the line number in the file
|
39
|
-
def self.sort_dead_steps_in_file!(dead_steps_hash)
|
40
|
-
dead_steps_hash.each_key do |file|
|
41
|
-
dead_steps_hash[file].sort_by! { |row| row[/^\d+/].to_i }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Returns the count of all possible dead steps in each file
|
46
|
-
def self.count_dead_steps(dead_steps_hash)
|
47
|
-
count = 0
|
48
|
-
dead_steps_hash.each_value do |dead_steps_in_file_list|
|
49
|
-
count += dead_steps_in_file_list.size
|
50
|
-
end
|
51
|
-
count
|
52
|
-
end
|
53
|
-
end
|
1
|
+
module CukeSniffer
|
2
|
+
# Author:: Robert Cochran (mailto:cochrarj@miamioh.edu)
|
3
|
+
# Copyright:: Copyright (C) 2014 Robert Cochran
|
4
|
+
# License:: Distributes under the MIT License
|
5
|
+
# Mixins: CukeSniffer::Constants
|
6
|
+
# A static class to aid in the identification of dead steps.
|
7
|
+
class DeadStepsHelper
|
8
|
+
include CukeSniffer::Constants
|
9
|
+
|
10
|
+
# Returns a hash of dead steps for displaying in the html.
|
11
|
+
def self.build_dead_steps_hash(step_definitions)
|
12
|
+
dead_steps_hash = gather_all_dead_steps_by_file(step_definitions)
|
13
|
+
sort_dead_steps_in_file!(dead_steps_hash)
|
14
|
+
dead_steps_hash[:total] = count_dead_steps(dead_steps_hash)
|
15
|
+
dead_steps_hash
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns all dead step definitions in a file
|
19
|
+
def self.gather_all_dead_steps_by_file(step_definitions)
|
20
|
+
dead_steps_hash = {}
|
21
|
+
step_definitions.each do |step_definition|
|
22
|
+
location_match = step_definition.location.match(/(?<file>.*).rb:(?<line>\d+)/)
|
23
|
+
file_name = location_match[:file]
|
24
|
+
regex = format_step_definition_regex(step_definition.regex)
|
25
|
+
if step_definition.calls.empty?
|
26
|
+
dead_steps_hash[file_name] ||= []
|
27
|
+
dead_steps_hash[file_name] << "#{location_match[:line]}: /#{regex}/"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
dead_steps_hash
|
31
|
+
end
|
32
|
+
|
33
|
+
# Formats the regex of a step definition to remove the (?-mix) part of the to_s
|
34
|
+
def self.format_step_definition_regex(regex)
|
35
|
+
regex.to_s.match(/\(\?\-mix\:(?<regex>.*)\)/)[:regex]
|
36
|
+
end
|
37
|
+
|
38
|
+
# Sorts the dead steps found in a hash by the line number in the file
|
39
|
+
def self.sort_dead_steps_in_file!(dead_steps_hash)
|
40
|
+
dead_steps_hash.each_key do |file|
|
41
|
+
dead_steps_hash[file].sort_by! { |row| row[/^\d+/].to_i }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns the count of all possible dead steps in each file
|
46
|
+
def self.count_dead_steps(dead_steps_hash)
|
47
|
+
count = 0
|
48
|
+
dead_steps_hash.each_value do |dead_steps_in_file_list|
|
49
|
+
count += dead_steps_in_file_list.size
|
50
|
+
end
|
51
|
+
count
|
52
|
+
end
|
53
|
+
end
|
54
54
|
end
|
@@ -1,125 +1,166 @@
|
|
1
|
-
require 'erb'
|
2
|
-
|
3
|
-
module CukeSniffer
|
4
|
-
# Author:: Robert Cochran (mailto:cochrarj@miamioh.edu)
|
5
|
-
# Copyright:: Copyright (C) 2014 Robert Cochran
|
6
|
-
# License:: Distributes under the MIT License
|
7
|
-
# Mixins: CukeSniffer::Constants
|
8
|
-
# Static class used to generate output for the CukeSniffer::CLI object.
|
9
|
-
class Formatter
|
10
|
-
include CukeSniffer::Constants
|
11
|
-
|
12
|
-
# Prints out a summary of the results and the list of improvements to be made
|
13
|
-
def self.output_console(cuke_sniffer)
|
14
|
-
summary = cuke_sniffer.summary
|
15
|
-
output = "Suite Summary" +
|
16
|
-
" Total Score: #{summary[:total_score]}\n" +
|
17
|
-
get_output_summary_nodes(cuke_sniffer) +
|
18
|
-
console_improvement_list(summary[:improvement_list])
|
19
|
-
|
20
|
-
puts output
|
21
|
-
end
|
22
|
-
|
23
|
-
# Returns a string of formatted output for all the object sections of summary
|
24
|
-
def self.get_output_summary_nodes(cuke_sniffer)
|
25
|
-
output = ""
|
26
|
-
[:features, :scenarios, :step_definitions, :hooks].each do |summary_section|
|
27
|
-
output += console_summary(summary_section.to_s.gsub("_", " ").capitalize, cuke_sniffer.summary[summary_section])
|
28
|
-
end
|
29
|
-
output
|
30
|
-
end
|
31
|
-
|
32
|
-
# Formats the section data for a summary object
|
33
|
-
def self.console_summary(name, summary)
|
34
|
-
" #{name}\n" +
|
35
|
-
" Min: #{summary[:min]}\n" +
|
36
|
-
" Max: #{summary[:max]}\n" +
|
37
|
-
" Average: #{summary[:average]}\n"
|
38
|
-
end
|
39
|
-
|
40
|
-
# Formats the improvement list data for summary
|
41
|
-
def self.console_improvement_list(improvement_list)
|
42
|
-
output = " Improvements to make:\n"
|
43
|
-
improvement_list.each do |improvement, count|
|
44
|
-
output << " (#{count}) #{improvement}\n"
|
45
|
-
end
|
46
|
-
output
|
47
|
-
end
|
48
|
-
|
49
|
-
# Creates a html file with the collected project details
|
50
|
-
# file_name defaults to "cuke_sniffer_results.html" unless specified
|
51
|
-
# Second parameter used for passing into the markup.
|
52
|
-
# cuke_sniffer.output_html
|
53
|
-
# Or
|
54
|
-
# cuke_sniffer.output_html("results01-01-0001.html")
|
55
|
-
def self.output_html(cuke_sniffer, file_name = DEFAULT_OUTPUT_FILE_NAME, template_name = "standard_template")
|
56
|
-
cuke_sniffer = sort_cuke_sniffer_lists(cuke_sniffer)
|
57
|
-
output = ERB.new(extract_markup("#{template_name}.html.erb")).result(binding)
|
58
|
-
File.open(format_html_file_name(file_name), 'w') do |f| f.write(output) end
|
59
|
-
end
|
60
|
-
|
61
|
-
# Returns an ERB page built up for the passed file name
|
62
|
-
def self.build_page(cuke_sniffer, erb_file)
|
63
|
-
ERB.new(extract_markup(erb_file)).result(binding)
|
64
|
-
end
|
65
|
-
|
66
|
-
# Assigns an html extension if one is not provided for the passed file name
|
67
|
-
def self.format_html_file_name(file_name)
|
68
|
-
if file_name =~ /\.html$/
|
69
|
-
file_name
|
70
|
-
else
|
71
|
-
file_name + ".html"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
# Creates a html file with minimum information: Summary, Rules, Improvement List.
|
76
|
-
# file_name defaults to "cuke_sniffer_results.html" unless specified
|
77
|
-
# Second parameter used for passing into the markup.
|
78
|
-
# cuke_sniffer.output_min_html
|
79
|
-
# Or
|
80
|
-
# cuke_sniffer.output_min_html("results01-01-0001.html")
|
81
|
-
def self.output_min_html(cuke_sniffer, file_name = DEFAULT_OUTPUT_FILE_NAME)
|
82
|
-
output_html(cuke_sniffer, file_name, "min_template")
|
83
|
-
end
|
84
|
-
|
85
|
-
# Returns the Rules erb page that utilizes sub page sections of enabled and disabled rules
|
86
|
-
def self.rules_template(cuke_sniffer)
|
87
|
-
ERB.new(extract_markup("rules.html.erb")).result(binding)
|
88
|
-
end
|
89
|
-
|
90
|
-
# Creates a xml file with the collected project details
|
91
|
-
# file_name defaults to "
|
92
|
-
# cuke_sniffer.output_xml
|
93
|
-
# Or
|
94
|
-
# cuke_sniffer.output_xml("cuke_sniffer01-01-0001.xml")
|
95
|
-
def self.output_xml(cuke_sniffer, file_name = DEFAULT_OUTPUT_FILE_NAME)
|
96
|
-
file_name = file_name + ".xml" unless file_name =~ /\.xml$/
|
97
|
-
|
98
|
-
doc = Nokogiri::XML::Document.new
|
99
|
-
doc.root = cuke_sniffer.to_xml
|
100
|
-
open(file_name, "w") do |file|
|
101
|
-
file << doc.serialize
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
#
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module CukeSniffer
|
4
|
+
# Author:: Robert Cochran (mailto:cochrarj@miamioh.edu)
|
5
|
+
# Copyright:: Copyright (C) 2014 Robert Cochran
|
6
|
+
# License:: Distributes under the MIT License
|
7
|
+
# Mixins: CukeSniffer::Constants
|
8
|
+
# Static class used to generate output for the CukeSniffer::CLI object.
|
9
|
+
class Formatter
|
10
|
+
include CukeSniffer::Constants
|
11
|
+
|
12
|
+
# Prints out a summary of the results and the list of improvements to be made
|
13
|
+
def self.output_console(cuke_sniffer)
|
14
|
+
summary = cuke_sniffer.summary
|
15
|
+
output = "Suite Summary" +
|
16
|
+
" Total Score: #{summary[:total_score]}\n" +
|
17
|
+
get_output_summary_nodes(cuke_sniffer) +
|
18
|
+
console_improvement_list(summary[:improvement_list])
|
19
|
+
|
20
|
+
puts output
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns a string of formatted output for all the object sections of summary
|
24
|
+
def self.get_output_summary_nodes(cuke_sniffer)
|
25
|
+
output = ""
|
26
|
+
[:features, :scenarios, :step_definitions, :hooks].each do |summary_section|
|
27
|
+
output += console_summary(summary_section.to_s.gsub("_", " ").capitalize, cuke_sniffer.summary[summary_section])
|
28
|
+
end
|
29
|
+
output
|
30
|
+
end
|
31
|
+
|
32
|
+
# Formats the section data for a summary object
|
33
|
+
def self.console_summary(name, summary)
|
34
|
+
" #{name}\n" +
|
35
|
+
" Min: #{summary[:min]}\n" +
|
36
|
+
" Max: #{summary[:max]}\n" +
|
37
|
+
" Average: #{summary[:average]}\n"
|
38
|
+
end
|
39
|
+
|
40
|
+
# Formats the improvement list data for summary
|
41
|
+
def self.console_improvement_list(improvement_list)
|
42
|
+
output = " Improvements to make:\n"
|
43
|
+
improvement_list.each do |improvement, count|
|
44
|
+
output << " (#{count}) #{improvement}\n"
|
45
|
+
end
|
46
|
+
output
|
47
|
+
end
|
48
|
+
|
49
|
+
# Creates a html file with the collected project details
|
50
|
+
# file_name defaults to "cuke_sniffer_results.html" unless specified
|
51
|
+
# Second parameter used for passing into the markup.
|
52
|
+
# cuke_sniffer.output_html
|
53
|
+
# Or
|
54
|
+
# cuke_sniffer.output_html("results01-01-0001.html")
|
55
|
+
def self.output_html(cuke_sniffer, file_name = DEFAULT_OUTPUT_FILE_NAME, template_name = "standard_template")
|
56
|
+
cuke_sniffer = sort_cuke_sniffer_lists(cuke_sniffer)
|
57
|
+
output = ERB.new(extract_markup("#{template_name}.html.erb")).result(binding)
|
58
|
+
File.open(format_html_file_name(file_name), 'w') do |f| f.write(output) end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns an ERB page built up for the passed file name
|
62
|
+
def self.build_page(cuke_sniffer, erb_file)
|
63
|
+
ERB.new(extract_markup(erb_file)).result(binding)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Assigns an html extension if one is not provided for the passed file name
|
67
|
+
def self.format_html_file_name(file_name)
|
68
|
+
if file_name =~ /\.html$/
|
69
|
+
file_name
|
70
|
+
else
|
71
|
+
file_name + ".html"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Creates a html file with minimum information: Summary, Rules, Improvement List.
|
76
|
+
# file_name defaults to "cuke_sniffer_results.html" unless specified
|
77
|
+
# Second parameter used for passing into the markup.
|
78
|
+
# cuke_sniffer.output_min_html
|
79
|
+
# Or
|
80
|
+
# cuke_sniffer.output_min_html("results01-01-0001.html")
|
81
|
+
def self.output_min_html(cuke_sniffer, file_name = DEFAULT_OUTPUT_FILE_NAME)
|
82
|
+
output_html(cuke_sniffer, file_name, "min_template")
|
83
|
+
end
|
84
|
+
|
85
|
+
# Returns the Rules erb page that utilizes sub page sections of enabled and disabled rules
|
86
|
+
def self.rules_template(cuke_sniffer)
|
87
|
+
ERB.new(extract_markup("rules.html.erb")).result(binding)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Creates a xml file with the collected project details
|
91
|
+
# file_name defaults to "cuke_sniffer_result.xml" unless specified
|
92
|
+
# cuke_sniffer.output_xml
|
93
|
+
# Or
|
94
|
+
# cuke_sniffer.output_xml("cuke_sniffer01-01-0001.xml")
|
95
|
+
def self.output_xml(cuke_sniffer, file_name = DEFAULT_OUTPUT_FILE_NAME)
|
96
|
+
file_name = file_name + ".xml" unless file_name =~ /\.xml$/
|
97
|
+
|
98
|
+
doc = Nokogiri::XML::Document.new
|
99
|
+
doc.root = cuke_sniffer.to_xml
|
100
|
+
open(file_name, "w") do |file|
|
101
|
+
file << doc.serialize
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# Creates an xml file in the junit with issues organized by file.
|
106
|
+
# file_name defaults to "cuke_sniffer_result.xml" unless specified
|
107
|
+
# cuke_sniffer.output_xml
|
108
|
+
# Or
|
109
|
+
# cuke_sniffer.output_xml("cuke_sniffer01-01-0001.xml")
|
110
|
+
def self.output_junit_xml(cuke_sniffer, file_name = DEFAULT_OUTPUT_FILE_NAME)
|
111
|
+
file_name = file_name + ".xml" unless file_name =~ /\.xml$/
|
112
|
+
results = {}
|
113
|
+
failures = 0
|
114
|
+
current = cuke_sniffer.features
|
115
|
+
current.concat cuke_sniffer.scenarios
|
116
|
+
current.concat cuke_sniffer.step_definitions
|
117
|
+
current.concat cuke_sniffer.hooks
|
118
|
+
current.each do |test|
|
119
|
+
location = test.location.gsub("#{Dir.pwd}/", '')
|
120
|
+
location_no_line = location.gsub(/:[0-9]*/,'')
|
121
|
+
line_num = location.include?(":") ? location.gsub(/.*:(.*)/, "\\1") : "full_file"
|
122
|
+
errors = test.rules_hash.keys.map {|f| {:line => line_num,
|
123
|
+
:severity => test.rules_hash,
|
124
|
+
:error => f,
|
125
|
+
:formatted => "Severity: #{test.rules_hash[f]}\nLocation: #{location}\nError: #{f}"}}
|
126
|
+
results[location_no_line] = results[location_no_line].nil? ? errors : results[location_no_line].concat(errors)
|
127
|
+
failures += test.rules_hash.size
|
128
|
+
end
|
129
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
130
|
+
xml.testsuites(:tests => results.size, :failures => failures) do
|
131
|
+
results.each do |location, failures|
|
132
|
+
failures.each do |failure|
|
133
|
+
xml.testcase(:classname => location, :name => failure[:line], :time => 0) do
|
134
|
+
xml.failure(failure[:formatted], :type => 'failure', :message => failure[:error])
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
output = builder.to_xml
|
141
|
+
File.open(file_name, 'w') do |f| f.write(output) end
|
142
|
+
# Return here to aid testing.
|
143
|
+
output
|
144
|
+
end
|
145
|
+
|
146
|
+
# Sorts all of the lists on a cuke_sniffer object to be in descending order for each objects score.
|
147
|
+
def self.sort_cuke_sniffer_lists(cuke_sniffer)
|
148
|
+
cuke_sniffer.features = cuke_sniffer.features.sort_by { |feature| feature.total_score }.reverse
|
149
|
+
cuke_sniffer.step_definitions = cuke_sniffer.step_definitions.sort_by { |step_definition| step_definition.score }.reverse
|
150
|
+
cuke_sniffer.hooks = cuke_sniffer.hooks.sort_by { |hook| hook.score }.reverse
|
151
|
+
cuke_sniffer.rules = cuke_sniffer.rules.sort_by { |rule| rule.score }.reverse
|
152
|
+
cuke_sniffer
|
153
|
+
end
|
154
|
+
|
155
|
+
# Returns the markup for a desired erb file.
|
156
|
+
def self.extract_markup(template_name = "markup.html.erb", markup_source = MARKUP_SOURCE)
|
157
|
+
markup_location = "#{markup_source}/#{template_name}"
|
158
|
+
markup = ""
|
159
|
+
File.open(markup_location).each_line do |line|
|
160
|
+
markup << line
|
161
|
+
end
|
162
|
+
markup
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
end
|