-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcuke-steps.rb
More file actions
97 lines (81 loc) · 2.14 KB
/
cuke-steps.rb
File metadata and controls
97 lines (81 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env ruby
#-*- encoding: utf-8 -*-
require 'optparse'
require_relative 'step_parser'
require_relative 'confluence_step_outputter'
require_relative 'html_step_outputter'
# Parse command line
options = {}
opts = OptionParser.new do |opts|
opts.banner = "Usage: cuke-steps.rb [options] <directories...>"
opts.on("-o", "--output FILE", "Output to FILE") do |file|
options[:file] = file
end
opts.on("-f", "--format FMT", "Select output format: cf, html") do |format|
options[:format] = format
end
end
opts.parse!(ARGV)
# Default output options
if options[:file] && !options[:format]
options[:format] = options[:file].sub(/^.*\./, "")
end
if !options[:format]
options[:format] = "html"
end
if options[:format] && !options[:file]
options[:file] = "steps.#{options[:format]}"
end
# All other arguments are treated as input directories
dirs = ARGV
if dirs.size == 0
puts "No source directories provided, use -h for help"
exit 1
end
# Setup output
case options[:format]
when 'cf'
output = ConfluenceStepOutputter.new(options[:file])
when 'html'
output = HtmlStepOutputter.new(options[:file])
else
puts "Unknown output format: #{options[:format]}"
exit 1
end
puts "Writing output to file '#{options[:file]}'"
# Sort primarily by step type, secondarily by step definition
sorter = lambda do |a,b|
if a[:type] == b[:type]
a[:name].downcase <=> b[:name].downcase
else
weight = { "Given" => 1, "When" => 2, "Then" => 3, "Transform" => 4, "Before" => 5, "After" => 6, "AfterStep" => 7 }
wa = weight[a[:type]]
wb = weight[b[:type]]
wa <=> wb
end
end
# Read files and output
all_steps = []
output.header
dirs.each do |dir|
dir = dir.sub(/\/+$/, "")
s = StepParser.new
Dir.glob("#{dir}/**/*.rb") do |file|
s.read(file)
end
steps = s.steps
all_steps += steps
output.start_directory(dir)
steps.sort!(&sorter)
steps.each { |s| output.step(s) }
output.end_directory
end
# Uncomment to generate a section containing all steps in alphabetical order
#if dirs.size > 1
# output.start_all
# all_steps.sort!(&sorter)
# all_steps.each { |s| output.step(s) }
# output.end_all
#end
output.footer
output.close