cuke_steps 0.2.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5ad2be95b4f540466be1b163cc1410a669620800
4
+ data.tar.gz: 17f1228b2c8137686bc1aaf5694ce80a60e5748a
5
+ SHA512:
6
+ metadata.gz: def5b79e7dcc8d0eb50fd0f2c3327f2098c763a36567d75b50286d3e78c9653a67d59d974a646faeca28befc561af9a3bcc87d158587785b7f80d3a43d808090
7
+ data.tar.gz: 79ed1e349de756db9c832d7c41f06a42470791cccb3b33a3cc5233c8287960f68c8fb78f3e11d74216708d1e53a75221207110552c0c866107133daab2697f24
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/
11
+ /.buildpath
12
+ /.project
13
+ /.settings
14
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.3
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cuke_steps_gem.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ [![Build Status](https://travis-ci.org/raels/cuke-steps.svg?branch=master)](https://travis-ci.org/raels/cuke-steps)
2
+
3
+ cuke-steps
4
+ ==========
5
+
6
+ Cucumber step documentation.
7
+
8
+ This is a small script that reads Cucumber/Gherkin step definition files and outputs pretty-printed documentation of those steps. It is meant as a tool for developers to easily see what step definitions already exist.
9
+
10
+ Currently supported output formats include HTML and Confluence wiki markup. The documentation can be pushed into a wiki using the [Confluence Publisher Plugin] [cpp] for Jenkins. Adding outputters for other formats is straightforward.
11
+
12
+ [cpp]: https://wiki.jenkins-ci.org/display/JENKINS/Confluence+Publisher+Plugin
13
+
14
+
15
+ Usage
16
+ -----
17
+
18
+ You might install with either the gem command or using bundler.
19
+
20
+ Assuming you installed with Bundler:
21
+
22
+ > bundle exec cuke-steps \[options\] <directories...>
23
+
24
+ In its simplest form:
25
+
26
+ > bundle exec cuke-steps features/
27
+
28
+ Supported options:
29
+
30
+ * -f FORMAT, --format FORMAT
31
+ Select output format, either "html" or "cf"
32
+
33
+ * -o FILE, --output FILE
34
+ Output to FILE, default "steps.html" or "steps.cf"
35
+
36
+ * -h, --help
37
+ Usage instructions
38
+
39
+ This will scan the provided directories for step definition files (*.rb) and output the documentation in the specified file.
40
+
41
+ The tool supports having step definitions in multiple directories. It will generate a separate section for each directory specified on the command line, and (if multiple directories are provided) a section containing all step definitions.
42
+
43
+
44
+ TODO
45
+ ----
46
+
47
+ * Add options for defining a base URL prefix and postfix, and make the file names in the output link to a source repo or Jenkins workspace
48
+
49
+
50
+ BSD License
51
+ -----------
52
+
53
+ Copyright (c) 2012, Sampo Niskanen
54
+ All rights reserved.
55
+
56
+ Redistribution and use in source and binary forms, with or without
57
+ modification, are permitted provided that the following conditions are met:
58
+
59
+ 1. Redistributions of source code must retain the above copyright notice, this
60
+ list of conditions and the following disclaimer.
61
+ 2. Redistributions in binary form must reproduce the above copyright notice,
62
+ this list of conditions and the following disclaimer in the documentation
63
+ and/or other materials provided with the distribution.
64
+
65
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
66
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
67
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
68
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
69
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
70
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
71
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
72
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
73
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
74
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cuke_steps_gem"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/cuke-steps ADDED
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env ruby
2
+ #-*- encoding: utf-8 -*-
3
+
4
+ require 'optparse'
5
+
6
+ require 'step_parser'
7
+ require 'confluence_step_outputter'
8
+ require 'html_step_outputter'
9
+
10
+
11
+ # Parse command line
12
+ options = {}
13
+ opts = OptionParser.new do |opts|
14
+ opts.banner = "Usage: cuke-steps.rb [options] <directories...>"
15
+
16
+ opts.on("-o", "--output FILE", "Output to FILE") do |file|
17
+ options[:file] = file
18
+ end
19
+ opts.on("-f", "--format FMT", "Select output format: cf, html") do |format|
20
+ options[:format] = format
21
+ end
22
+ end
23
+ opts.parse!(ARGV)
24
+
25
+ # Default output options
26
+ if options[:file] && !options[:format]
27
+ options[:format] = options[:file].sub(/^.*\./, "")
28
+ end
29
+ if !options[:format]
30
+ options[:format] = "html"
31
+ end
32
+ if options[:format] && !options[:file]
33
+ options[:file] = "steps.#{options[:format]}"
34
+ end
35
+
36
+
37
+ # All other arguments are treated as input directories
38
+ dirs = ARGV
39
+ if dirs.size == 0
40
+ puts "No source directories provided, use -h for help"
41
+ exit 1
42
+ end
43
+
44
+ # Setup output
45
+ case options[:format]
46
+ when 'cf'
47
+ output = ConfluenceStepOutputter.new(options[:file])
48
+ when 'html'
49
+ output = HtmlStepOutputter.new(options[:file])
50
+ else
51
+ puts "Unknown output format: #{options[:format]}"
52
+ exit 1
53
+ end
54
+ puts "Writing output to file '#{options[:file]}'"
55
+
56
+
57
+ # Sort primarily by step type, secondarily by step definition
58
+ sorter = lambda do |a,b|
59
+ if a[:type] == b[:type]
60
+ a[:name].downcase <=> b[:name].downcase
61
+ else
62
+ weight = { "Given" => 1, "When" => 2, "Then" => 3, "Transform" => 4, "Before" => 5, "After" => 6, "AfterStep" => 7 }
63
+ wa = weight[a[:type]]
64
+ wb = weight[b[:type]]
65
+ wa <=> wb
66
+ end
67
+ end
68
+
69
+
70
+ # Read files and output
71
+ all_steps = []
72
+ output.header
73
+ dirs.each do |dir|
74
+ dir = dir.sub(/\/+$/, "")
75
+ s = StepParser.new
76
+ Dir.glob("#{dir}/**/*.rb") do |file|
77
+ s.read(file)
78
+ end
79
+ steps = s.steps
80
+ all_steps += steps
81
+
82
+ output.start_directory(dir)
83
+ steps.sort!(&sorter)
84
+ steps.each { |s| output.step(s) }
85
+ output.end_directory
86
+ end
87
+
88
+ if dirs.size > 1
89
+ output.start_all
90
+ all_steps.sort!(&sorter)
91
+ all_steps.each { |s| output.step(s) }
92
+ output.end_all
93
+ end
94
+
95
+ output.footer
96
+ output.close
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cuke_steps_gem/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cuke_steps"
8
+ spec.version = CukeStepsGem::VERSION
9
+ spec.authors = ["plaa, packager:raels"]
10
+ spec.email = [""]
11
+
12
+
13
+ spec.summary = %q{Generates Gherkin step reference page}
14
+ spec.description = %q{This gem offers a program to generate a reference index for your Gherkin step definitions.
15
+ It was written by plaa, and packaged by raels.}
16
+ spec.homepage = "https://raels.github.io/cuke-steps/"
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ # if spec.respond_to?(:metadata)
21
+ # spec.metadata['allowed_push_host'] = "http://rubygems.org"
22
+ # else
23
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ spec.bindir = "bin"
28
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.12"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ end
@@ -0,0 +1,64 @@
1
+ # Outputter that generates Confluence markup
2
+
3
+ require 'cgi'
4
+ require 'fileutils'
5
+
6
+ class ConfluenceStepOutputter
7
+ def initialize(file)
8
+ @file = File.open(file, 'w')
9
+ @previous_type = ""
10
+ end
11
+
12
+ def header
13
+ # No-op
14
+ end
15
+ def footer
16
+ @file.puts %(<p>&nbsp;</p>)
17
+ @file.puts %(<p><em>Documentation generated #{Time.now}</em></p>)
18
+ end
19
+
20
+ def close
21
+ @file.close
22
+ end
23
+
24
+ def start_directory(dir)
25
+ @file.puts %(<p>&nbsp;</p>)
26
+ @file.puts "<h2>#{dir}</h2>"
27
+ @previous_type = ""
28
+ end
29
+
30
+ def end_directory
31
+ # No-op
32
+ end
33
+
34
+ def start_all
35
+ @file.puts %(<p>&nbsp;</p>)
36
+ @file.puts "<h2>All definitions alphabetically</h2>"
37
+ @previous_type = ""
38
+ end
39
+
40
+ def end_all
41
+ # No-op
42
+ end
43
+
44
+ def step(step)
45
+ if @previous_type != step[:type]
46
+ @file.puts %(<h3>#{step[:type]} definitions</h3>)
47
+ @previous_type = step[:type]
48
+ end
49
+ @file.puts %(<ac:macro ac:name="expand">)
50
+ @file.puts %( <ac:parameter ac:name="title">#{CGI.escapeHTML(step[:name])}</ac:parameter>)
51
+ @file.puts %( <ac:rich-text-body>)
52
+ # TODO: Add link to source repo or Jenkins workspace
53
+ # <p><a href=".../#{CGI.escapeHTML(step[:filename])}" style="color: #888;">#{CGI.escapeHTML(step[:filename])}:#{step[:line_number]}</a></p>
54
+ @file.puts %( <p style="color: #888;">#{CGI.escapeHTML(step[:filename])}:#{step[:line_number]}</p>)
55
+ @file.puts %( <pre style="background-color: #ddd; padding-top: 1.2em;">)
56
+ step[:code].each do |line|
57
+ @file.puts %( #{CGI.escapeHTML(line)})
58
+ end
59
+ @file.puts %( </pre>)
60
+ @file.puts %( </ac:rich-text-body>)
61
+ @file.puts %(</ac:macro>)
62
+ end
63
+
64
+ end
@@ -0,0 +1,8 @@
1
+ require "cuke_steps_gem/version"
2
+ require 'step_parser'
3
+ require 'html_step_outputter'
4
+ require 'confluence_step_outputter'
5
+
6
+ module CukeStepsGem
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,3 @@
1
+ module CukeStepsGem
2
+ VERSION = "0.2.2"
3
+ end
@@ -0,0 +1,119 @@
1
+ # Outputter that generates HTML markup
2
+ # Feel free to customize the below code for your needs
3
+
4
+ require 'cgi'
5
+ require 'fileutils'
6
+
7
+ class HtmlStepOutputter
8
+
9
+ def initialize(file)
10
+ @file = File.open(file, 'w')
11
+ @previous_type = ""
12
+ @id_number = 0
13
+ end
14
+
15
+ # HTML file header - customize as needed
16
+ def header
17
+ @file.puts <<-eos
18
+ <!DOCTYPE html>
19
+ <html>
20
+ <head>
21
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
22
+ <title>Cucumber step documentation</title>
23
+ <style>
24
+ .stepdefs {
25
+ font-size: smaller;
26
+ }
27
+ .stepdefs li {
28
+ margin-bottom: 0.25em;
29
+ list-style-type: none;
30
+ }
31
+ .stepdefs li:before {
32
+ content: "\u00BB ";
33
+ font-size: larger;
34
+ padding-right: 0.3em;
35
+ }
36
+ .stepdef {
37
+ color: #111;
38
+ text-decoration: none;
39
+ }
40
+ .extrainfo {
41
+ display: none;
42
+ overflow: hidden; /* Fixes jumping issue in jQuery slideToggle() */
43
+ }
44
+ </style>
45
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
46
+ </head>
47
+ <body>
48
+ eos
49
+ end
50
+
51
+ def footer
52
+ @file.puts <<-eos
53
+ </ul>
54
+ <p>&nbsp;</p>
55
+ <p><em>Documentation generated #{Time.now}</em></p>
56
+ </body>
57
+ </html>
58
+ eos
59
+ end
60
+
61
+
62
+ def close
63
+ @file.close
64
+ end
65
+
66
+ def start_directory(dir)
67
+ @file.puts %(</ul>) if @previous_type != ""
68
+ @file.puts %(<p>&nbsp;</p>)
69
+ @file.puts %(<h2>Step definitions in #{dir}/</h2>)
70
+ @previous_type = ""
71
+ end
72
+
73
+ def end_directory
74
+ # No-op
75
+ end
76
+
77
+ def start_all
78
+ @file.puts %(</ul>)
79
+ @file.puts %(<p>&nbsp;</p>)
80
+ @file.puts %(<h2>All definitions alphabetically</h2>)
81
+ @previous_type = ""
82
+ end
83
+
84
+ def end_all
85
+ # No-op
86
+ end
87
+
88
+ def step(step)
89
+ if @previous_type != step[:type]
90
+ @file.puts %(</ul>) if @previous_type != ""
91
+ @file.puts %(<h3>#{step[:type]} definitions</h3>)
92
+ @file.puts %(<ul class="stepdefs">)
93
+ @previous_type = step[:type]
94
+ end
95
+
96
+ id = new_id
97
+ @file.puts %(<li>)
98
+ @file.puts %( <a href="#" onclick="$('##{id}').slideToggle(); return false;" class="stepdef">#{CGI.escapeHTML(step[:name])}</a>)
99
+ @file.puts %( <div id="#{id}" class="extrainfo">)
100
+ # TODO: Add link to source repo or Jenkins workspace
101
+ # <p><a href=".../#{CGI.escapeHTML(step[:filename])}" style="color: #888;">#{CGI.escapeHTML(step[:filename])}:#{step[:line_number]}</a></p>
102
+ @file.puts %( <p style="color: #888;">#{CGI.escapeHTML(step[:filename])}:#{step[:line_number]}</p>)
103
+ @file.puts %( <pre style="background-color: #ddd; padding-top: 1.2em;">)
104
+ step[:code].each do |line|
105
+ @file.puts %( #{CGI.escapeHTML(line)})
106
+ end
107
+ @file.puts %( </pre>)
108
+ @file.puts %( </div>)
109
+ @file.puts %(</li>)
110
+ end
111
+
112
+ private
113
+
114
+ def new_id
115
+ @id_number += 1
116
+ "id#{@id_number}"
117
+ end
118
+
119
+ end
@@ -0,0 +1,75 @@
1
+ # Class that parses step definitions from Ruby files
2
+
3
+ class StepParser
4
+
5
+ attr_reader :steps
6
+ def initialize
7
+ @steps = []
8
+ end
9
+
10
+ def read(file)
11
+ @current_file = file
12
+ @line_number = 0
13
+ @lines = IO.read(file).split(/\r?\n/)
14
+ parse_lines
15
+ end
16
+
17
+
18
+ private
19
+
20
+ def next_line
21
+ @line_number += 1
22
+ @lines.shift
23
+ end
24
+
25
+ def unread(line)
26
+ @line_number -= 1
27
+ @lines.unshift(line)
28
+ end
29
+
30
+ def parse_lines
31
+ @comments = []
32
+ while not @lines.empty?
33
+
34
+ line = next_line
35
+ case line
36
+ when /^ *#/
37
+ @comments << line
38
+ when /^(Given|When|Then|Before|After|AfterStep|Transform)[ (]/
39
+ unread(line)
40
+ parse_step
41
+ @comments = []
42
+ when /^\s+(Given|When|Then|Before|After|AfterStep|Transform)[ (]/
43
+ puts "WARNING: Indented step definition in file #{@current_file}: #{line}"
44
+ @comments = []
45
+ else
46
+ @comments = []
47
+ end
48
+
49
+ end
50
+ end
51
+
52
+ def parse_step
53
+ type = parse_step_type(@lines.first)
54
+ name = parse_step_name(@lines.first)
55
+ line_number = @line_number + 1
56
+ code = @comments
57
+ line = ""
58
+ while !@lines.empty? && !(line =~ /^end\s*$/)
59
+ line = next_line
60
+ code << line
61
+ end
62
+ @steps << { :type => type, :name => name, :filename => @current_file, :code => code, :line_number => line_number }
63
+ end
64
+
65
+ def parse_step_type(line)
66
+ line.sub(/^([A-Za-z]+).*/, '\1')
67
+ end
68
+
69
+ def parse_step_name(line)
70
+ line = line.sub(/^(Given|When|Then|Transform) *\(?\/\^?(.*?)\$?\/.*/, '\1 \2')
71
+ line = line.gsub('\ ', ' ')
72
+ line
73
+ end
74
+
75
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cuke_steps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - plaa, packager:raels
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: |-
56
+ This gem offers a program to generate a reference index for your Gherkin step definitions.
57
+ It was written by plaa, and packaged by raels.
58
+ email:
59
+ - ''
60
+ executables:
61
+ - console
62
+ - cuke-steps
63
+ - setup
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - ".gitignore"
68
+ - ".rspec"
69
+ - ".travis.yml"
70
+ - Gemfile
71
+ - README.md
72
+ - Rakefile
73
+ - bin/console
74
+ - bin/cuke-steps
75
+ - bin/setup
76
+ - cuke_steps_gem.gemspec
77
+ - lib/confluence_step_outputter.rb
78
+ - lib/cuke_steps_gem.rb
79
+ - lib/cuke_steps_gem/version.rb
80
+ - lib/html_step_outputter.rb
81
+ - lib/step_parser.rb
82
+ homepage: https://raels.github.io/cuke-steps/
83
+ licenses: []
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.4.5.1
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Generates Gherkin step reference page
105
+ test_files: []