cucumber_junit_to_json 0.1.0

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: e055dbdeb6bef8126bb5704abfdaf6c60d884b38
4
+ data.tar.gz: a123979749fb783ac8aaf228e564df6706335ce4
5
+ SHA512:
6
+ metadata.gz: 33a7662c3a61a25edb8528662e3fbabba19c858c078c27362b540d29c070f5f6cc59cfa7b6806c7ab6156e1a6d16dff85fdec5638948bea6fcc6c9523777bb3b
7
+ data.tar.gz: 8e3d206280732deae37770352300447fccec1e71ae0f3a7c43f3da4b8f7608f299644ab1a7650fc7ba04fe0ea6747ccb0dee65daaebd26b054440096a658e819
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .DS_Store
11
+ .byebug_history
12
+ *.gem
data/.rubocop.yml ADDED
@@ -0,0 +1,34 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+ Exclude:
4
+ - Gemfile
5
+ - bin/*
6
+ Style/ClassAndModuleChildren:
7
+ Enabled: false
8
+ Metrics/LineLength:
9
+ Enabled: false
10
+ Metrics/ClassLength:
11
+ Max: 170
12
+ Performance/RegexpMatch:
13
+ Enabled: false
14
+ Metrics/PerceivedComplexity:
15
+ Max: 20
16
+ MethodLength:
17
+ Max: 50
18
+ Metrics/ParameterLists:
19
+ Max: 10
20
+ Metrics/AbcSize:
21
+ Enabled: false
22
+ Naming/PredicateName:
23
+ Enabled: false
24
+ Metrics/CyclomaticComplexity:
25
+ Max: 10
26
+ Security/Eval:
27
+ Enabled: false
28
+ Metrics/BlockLength:
29
+ Max: 50
30
+ Exclude:
31
+ - rake/**/*.rake
32
+ - cucumber_junit_to_json.gemspec
33
+ Naming/VariableName:
34
+ Enabled: false
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ransom4real@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cucumber_junit_to_json.gemspec
4
+ gemspec
5
+
6
+ gem 'temporaries'
7
+
8
+ group :dev do
9
+ gem 'looksee'
10
+ gem 'pry'
11
+ gem 'rubocop'
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Voke Ransom Anighoro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # CucumberJunitToJson
2
+
3
+ The Cucumber JUNIT to JSON gem does what it says on the tin. Takes a directory of Cucumber generated JUNIT .xml files, recursively converts them to JSON cucumber compatible format and outputs into a single .json file
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cucumber_junit_to_json'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cucumber_junit_to_json
20
+
21
+ ## Usage
22
+
23
+ Run:
24
+
25
+ ```bash
26
+ cucumber_junit_to_json --junit-dir /path/to/junit/xml --feature-dir /path/to/feature/files
27
+ ```
28
+
29
+ The above command will process all JUNIT .xml files in the --junit-dir and link steps to your your .feature file passed on in --feature-dir . Ensure your feature files are up to date with the result from your JUNIT .xml file. All non conformant JUNIT files will be skipped during processing.
30
+
31
+ JSON result will be stored in cucumber.json by default. To override this name, provide a --output flag with the name of the output file you prefer as below
32
+
33
+ ```bash
34
+ cucumber_junit_to_json --junit-dir /path/to/junit/xml --feature-dir /path/to/feature/files --output path/to/output.json
35
+ ```
36
+
37
+
38
+ Help:
39
+
40
+ For more information about flags to pass on to the cucumber_junit_to_json executable
41
+
42
+ ```bash
43
+ cucumber_junit_to_json --help
44
+ ```
45
+
46
+ ## Development
47
+
48
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+
50
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ransom4real/cucumber_junit_to_json. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
55
+
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
60
+
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cucumber_junit_to_json"
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
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/cucumber_junit_to_json/app'
4
+
5
+ exit CucumberJunitToJson::App.new.run(*ARGV)
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,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'cucumber_junit_to_json/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'cucumber_junit_to_json'
9
+ spec.version = CucumberJunitToJson::VERSION
10
+ spec.authors = ['Voke Ransom Anighoro']
11
+ spec.email = ['ransom4real@gmail.com']
12
+
13
+ spec.summary = 'Converts cucumber JUNIT xml reports to cucumber JSON format'
14
+ spec.description = 'Converts cucumber JUNIT xml reports to cucumber JSON format'
15
+ spec.homepage = 'https://github.com/ransom4real/cucumber_junit_to_json'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+
22
+ spec.executables = `git ls-files -- bin/*`.split("\n").map { |f|
23
+ File.basename(f)
24
+ }
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.13'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_runtime_dependency 'jbuilder', '~> 2.7'
30
+ spec.add_runtime_dependency 'json', '~> 2.1'
31
+ spec.add_runtime_dependency 'nokogiri', '~> 1.8'
32
+ spec.add_runtime_dependency 'similar_text', '~> 0.0.4'
33
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Cucumber Junit to Json Module
4
+ module CucumberJunitToJson
5
+ autoload :App, 'cucumber_junit_to_json/app'
6
+ autoload :VERSION, 'cucumber_junit_to_json/version'
7
+ end
@@ -0,0 +1,147 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'optparse'
4
+ require 'find'
5
+ require 'fileutils'
6
+ require 'json'
7
+ require 'nokogiri'
8
+ require 'pry'
9
+ require 'pathname'
10
+ require_relative 'models/feature'
11
+ require_relative 'models/scenario'
12
+ require_relative 'models/step'
13
+ require_relative 'feature_json_builder'
14
+ require_relative 'parsers/feature_parser'
15
+ require_relative 'parsers/junit_parser'
16
+ require_relative 'version'
17
+
18
+ module CucumberJunitToJson
19
+ # The Cucumber Junit to Json app class that handles std inputs and command line args
20
+ class App
21
+ Error = Class.new(RuntimeError)
22
+
23
+ def initialize(options = {})
24
+ @stdin = options[:stdin] || STDIN
25
+ @stdout = options[:stdout] || STDOUT
26
+ @stderr = options[:stderr] || STDERR
27
+ @feature_id = 1
28
+ @scenario_id = 1
29
+ end
30
+
31
+ attr_reader :stdin, :stdout, :stderr, :junit_parser, :feature_parser
32
+
33
+ def run(*args)
34
+ options = parse_args(args)
35
+ @junit_parser = CucumberJunitToJson::Parsers::JunitParser.new(options.junit_dir)
36
+ @feature_parser = CucumberJunitToJson::Parsers::FeatureParser.new(options.feature_dir)
37
+ output_file = options.output_file || 'cucumber.json'
38
+ features = []
39
+ puts output_file
40
+ unless File.file?(output_file)
41
+ output_directory = File.dirname(output_file)
42
+ FileUtils.mkdir_p(output_directory) unless File.directory?(output_directory)
43
+ FileUtils.touch(output_file)
44
+ raise Error, "Could not create output file #{output_file}" unless File.file?(output_file)
45
+ end
46
+ # if we are dealing with a directory of xml files
47
+ if File.directory?(junit_parser.path_to_junit)
48
+ Find.find(junit_parser.path_to_junit) do |path_to_file|
49
+ next unless File.file?(path_to_file) && File.extname(path_to_file) == '.xml'
50
+ features.push(convert_to_json(path_to_file))
51
+ end
52
+ # if we are dealing with just a single xml file
53
+ elsif File.exist?(junit_parser.path_to_junit)
54
+ features.push(convert_to_json(junit_parser.path_to_junit))
55
+ end
56
+ open(output_file, 'w') { |f| f.write(features.to_json) }
57
+ 0
58
+ rescue Error, OptionParser::ParseError => error
59
+ stderr.puts error.message
60
+ 1
61
+ end
62
+
63
+ private
64
+
65
+ def convert_to_json(file)
66
+ file_content = @junit_parser.read(file)
67
+
68
+ return if file_content.empty?
69
+
70
+ document = Nokogiri::XML::Document.parse(file_content)
71
+ testsuite = document.at_css('testsuite')
72
+ feature_uri = Pathname.new(File.join(@feature_parser.path_to_features, @junit_parser.path_to_file(testsuite['name']))).realpath.to_s
73
+ feature = CucumberJunitToJson::Models::Feature.new
74
+ feature.keyword = 'Feature'
75
+ feature.name = @junit_parser.feature_name(testsuite['name'])
76
+ feature.uri = feature_uri
77
+ feature.id = @feature_id
78
+ feature.tags, feature.line = @feature_parser.tags_and_line_number_matching(feature_uri, "#{feature.keyword}:")
79
+
80
+ testcases = testsuite.css('testcase')
81
+ scenarios = []
82
+ testcases.each do |testcase|
83
+ scenario = CucumberJunitToJson::Models::Scenario.new
84
+ # Removing scenario outline added blob gives you the actual scenario name
85
+ scenario.name = testcase['name'].split('-- @').first.strip
86
+ scenario.tags, scenario.line = @feature_parser.tags_and_line_number_matching(feature_uri, scenario.name, true)
87
+ scenario_line_text = @feature_parser.text_and_line_number_matching(feature_uri, scenario.name, true).first
88
+ scenario.keyword = scenario_line_text.split(':').first.strip
89
+ scenario.type = 'scenario'
90
+ scenario.uri = feature_uri
91
+ scenario.id = @scenario_id
92
+ scenario_output = get_string_between(testcase.at_css('system-out').text, '@scenario.begin', '@scenario.end')
93
+ scenario.steps = CucumberJunitToJson::Models::Step.get_steps_for(scenario.name, scenario_output, feature_uri)
94
+ scenarios.push(scenario)
95
+ @scenario_id += 1
96
+ end
97
+ feature.elements = scenarios
98
+ builder = CucumberJunitToJson::FeatureJsonBuilder.new(feature)
99
+ @feature_id += 1
100
+ JSON.parse(builder.feature_json)
101
+ end
102
+
103
+ def get_string_between(str, start_at, end_at)
104
+ regex = /#{start_at}(.*?)#{end_at}/m
105
+ str[regex, 1]
106
+ end
107
+
108
+ def parse_args(args)
109
+ options = OpenStruct.new
110
+ options.junit_dir = nil
111
+ options.feature_dir = nil
112
+ options.output_file = nil
113
+ parser = OptionParser.new do |p|
114
+ p.banner = "USAGE: #{$PROGRAM_NAME} --junit-dir JUNITDIR --feature-dir FEATUREDIR"
115
+ p.separator ''
116
+ p.separator 'Specific options:'
117
+
118
+ p.on '-j', '--junit-dir JUNITDIR', 'Provide a path to junit .xml files.' do |junit_dir|
119
+ options.junit_dir = junit_dir
120
+ end
121
+
122
+ p.on '-f', '--feature-dir FEATUREDIR', 'Provide a path to .feature files.' do |feature_dir|
123
+ options.feature_dir = feature_dir
124
+ end
125
+
126
+ p.on '-o', '--output [OUTPUT]', 'Provide a path to output json file.' do |output|
127
+ options.output_file = output
128
+ end
129
+
130
+ p.on_tail('-h', '--help', 'Show this message') do
131
+ puts p
132
+ exit
133
+ end
134
+
135
+ # Another typical switch to print the version.
136
+ p.on_tail('--version', 'Show version') do
137
+ puts CucumberJunitToJson::VERSION
138
+ exit
139
+ end
140
+ end
141
+
142
+ parser.parse!(args)
143
+ raise Error, parser.banner unless options.junit_dir && options.feature_dir
144
+ options
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jbuilder'
4
+ # Top level module
5
+ module CucumberJunitToJson
6
+ # Uses JBuilder to model a JSON feature object
7
+ class FeatureJsonBuilder
8
+ attr_accessor :feature_json
9
+ def initialize(feature)
10
+ @feature_json = Jbuilder.encode do |json|
11
+ json.keyword feature.keyword
12
+ json.name feature.name
13
+ json.tags feature.tags do |tag|
14
+ json.name tag.name
15
+ json.line tag.line
16
+ end
17
+ json.elements feature.elements do |scenario|
18
+ json.type scenario.type
19
+ json.keyword scenario.keyword
20
+ json.name scenario.name
21
+ json.tags scenario.tags do |tag|
22
+ json.name tag.name
23
+ json.line tag.line
24
+ end
25
+ json.steps scenario.steps do |step|
26
+ json.keyword step.keyword
27
+ json.name step.name
28
+ json.match do
29
+ json.location step.match.location
30
+ json.arguments step.match.arguments
31
+ end
32
+ json.result do
33
+ json.status step.result.status
34
+ json.duration step.result.duration
35
+ end
36
+ unless step.table.headings.size.zero?
37
+ json.table do
38
+ json.headings step.table.headings
39
+ json.rows step.table.rows
40
+ end
41
+ end
42
+ json.line step.line
43
+ end
44
+ json.line scenario.line
45
+ json.uri scenario.uri
46
+ json.description scenario.description
47
+ json.id scenario.id
48
+ end
49
+ json.description feature.description
50
+ json.line feature.line
51
+ json.uri feature.uri
52
+ json.id feature.id
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Top level module
4
+ module CucumberJunitToJson
5
+ # module for all models
6
+ module Models
7
+ # Abstract representation of a cucumber step argument attribute
8
+ class Argument
9
+ attr_accessor :value
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Top level module
4
+ module CucumberJunitToJson
5
+ # module for all models
6
+ module Models
7
+ # Abstract representation of a cucumber feature attribute
8
+ class Feature
9
+ attr_accessor :keyword, :name, :tags, :description, :elements, :line, :uri, :id
10
+ def initialize
11
+ @description = ''
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Top level module
4
+ module CucumberJunitToJson
5
+ # module for all models
6
+ module Models
7
+ # Abstract representation of a cucumber step definition match attribute
8
+ class Match
9
+ attr_accessor :location, :arguments
10
+ def initialize(location = '', arguments = [])
11
+ @location = location
12
+ @arguments = arguments
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Top level module
4
+ module CucumberJunitToJson
5
+ # module for all models
6
+ module Models
7
+ # Abstract representation of a cucumber step result attribute
8
+ class Result
9
+ attr_accessor :status, :duration
10
+ def initialize(status, duration)
11
+ @status = status.to_s.strip
12
+ @duration = duration.to_f
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Top level module
4
+ module CucumberJunitToJson
5
+ # module for all models
6
+ module Models
7
+ # Abstract representation of a cucumber scenario attribute
8
+ class Scenario
9
+ attr_accessor :type, :keyword, :name, :tags, :steps, :line, :uri, :description, :id
10
+ def initialize
11
+ @description = ''
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'similar_text'
4
+ require_relative 'table'
5
+ require_relative 'match'
6
+ require_relative 'result'
7
+ # Top level module
8
+ module CucumberJunitToJson
9
+ # module for all models
10
+ module Models
11
+ # Abstract representation of a cucumber step attribute
12
+ class Step
13
+ attr_accessor :keyword, :name, :match, :table, :result, :line
14
+ def initialize
15
+ @table = CucumberJunitToJson::Models::Table.new
16
+ end
17
+
18
+ def self.get_steps_for(scenario_title, scenario_str, feature_file_path)
19
+ steps = []
20
+ table = []
21
+ prev_step_has_table = false
22
+ keywords = %w[Given When Then And But]
23
+ scenario_steps = scenario_str.split("\n").reject(&:empty?)
24
+ scenario_steps.each do |scenario_step|
25
+ step = Step.new
26
+ scenario_step = scenario_step.to_s.strip
27
+ if scenario_step.start_with?(*keywords)
28
+ # If we are still processing scenarios
29
+ # and the last step had tables, let us
30
+ # process that table
31
+ if prev_step_has_table == true
32
+ steps.last.table = CucumberJunitToJson::Models::Table.parse(table)
33
+ prev_step_has_table = false
34
+ table = []
35
+ end
36
+ step.keyword = scenario_step.split(' ').first.strip
37
+ step.name = scenario_step.split('...').first.split(' ').drop(1).join(' ').strip
38
+ step.match = CucumberJunitToJson::Models::Match.new
39
+ result_duration_str = scenario_step.split('...').last
40
+ status, duration = result_duration_str.split('in')
41
+ step.result = CucumberJunitToJson::Models::Result.new(status, duration)
42
+ step.line = get_scenario_step_matching(scenario_title, feature_file_path, scenario_step.split('...').first.strip).last
43
+ steps.push(step)
44
+ elsif scenario_step.start_with?('|')
45
+ prev_step_has_table = true
46
+ table.push(scenario_step.to_s.strip)
47
+ end
48
+ end
49
+ # if the last final step had a table
50
+ # it means we would have not had the chance to
51
+ # process it, hence lets do it before we exit this method
52
+ if prev_step_has_table == true
53
+ steps.last.table = CucumberJunitToJson::Models::Table.parse(table)
54
+ prev_step_has_table = false
55
+ table = []
56
+ end
57
+ steps
58
+ end
59
+
60
+ def self.get_scenario_step_matching(scenario, file, step)
61
+ count = 0
62
+ found_scenario = false
63
+ File.open(file, 'r') do |f|
64
+ f.each_line do |line|
65
+ count += 1
66
+ # Check if we got a match anchor in line.
67
+ # If there is, use a similar matcher
68
+ if line =~ /<\S+>/
69
+ # A match percentage greater than 80 is an indication
70
+ # of a good match for scenarios
71
+ found_scenario = true if line.similar(scenario) >= 80
72
+ elsif line =~ /#{scenario}/
73
+ found_scenario = true
74
+ end
75
+ if found_scenario
76
+ # Check if we got a match anchor in line.
77
+ # If there is, use a similar matcher
78
+ if line =~ /<\S+>/
79
+ # A match percentage greater than 76 is an indication
80
+ # of a good match for steps
81
+ return line, count if line.similar(step) >= 76
82
+ elsif line =~ /#{step}/
83
+ return line, count
84
+ end
85
+ end
86
+ end
87
+ end
88
+ raise Error, "Could not find step '#{step}' in '#{scenario}' looking into #{file}"
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Top level module
4
+ module CucumberJunitToJson
5
+ # module for all models
6
+ module Models
7
+ # Abstract representation of a cucumber step table attribute
8
+ class Table
9
+ attr_accessor :headings, :rows
10
+ def initialize
11
+ @headings = []
12
+ @rows = []
13
+ end
14
+
15
+ def self.parse(data)
16
+ table = Table.new
17
+ table.headings = data.first.split('|').compact.collect(&:strip).reject(&:empty?)
18
+ rows = []
19
+ data.drop(1).each do |row|
20
+ rows.push(row.split('|').compact.collect(&:strip).reject(&:empty?))
21
+ end
22
+ table.rows = rows
23
+ table
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Top level module
4
+ module CucumberJunitToJson
5
+ # module for all models
6
+ module Models
7
+ # Abstract representation of a cucumber tag attribute
8
+ class Tag
9
+ attr_accessor :name, :line
10
+ def initialize(name, line)
11
+ @name = name
12
+ @line = line
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'similar_text'
4
+ require_relative '../models/tag'
5
+ # Top level module
6
+ module CucumberJunitToJson
7
+ # module for all models
8
+ module Parsers
9
+ # Abstract representation of a cucumber feature file parser
10
+ class FeatureParser
11
+ Error = Class.new(RuntimeError)
12
+ attr_accessor :path_to_features
13
+
14
+ def initialize(path_to_features)
15
+ STDERR.puts 'warning: no junit directory given' if path_to_features.empty?
16
+ raise Error, "no such dir(s): #{path_to_features}" unless Dir.exist?(path_to_features)
17
+ @path_to_features = path_to_features
18
+ end
19
+
20
+ def tags_and_line_number_matching(file, text, partial_match = false)
21
+ tags, line = text_and_line_number_before_match(file, text, partial_match)
22
+ tag_objects = []
23
+ tags.split(' ').each do |tag|
24
+ if tag.strip.start_with?('@')
25
+ tag_objects.push(CucumberJunitToJson::Models::Tag.new(tag, line - 1))
26
+ end
27
+ end
28
+ [tag_objects, line]
29
+ end
30
+
31
+ def text_and_line_number_before_match(file, text, partial_match = false)
32
+ count = 0
33
+ prev_line_text = ''
34
+ File.open(file, 'r') do |f|
35
+ f.each_line do |line|
36
+ count += 1
37
+ if partial_match == true
38
+ return prev_line_text, count if line.similar(text) >= 80
39
+ elsif line =~ /#{text}/
40
+ return prev_line_text, count
41
+ end
42
+ prev_line_text = line
43
+ end
44
+ end
45
+ raise Error, "Could not find #{text} in #{file}"
46
+ end
47
+
48
+ def text_and_line_number_matching(file, text, partial_match = false)
49
+ count = 0
50
+ File.open(file, 'r') do |f|
51
+ f.each_line do |line|
52
+ count += 1
53
+ if partial_match == true
54
+ return line, count if line.similar(text) >= 80
55
+ elsif line =~ /#{text}/
56
+ return line, count
57
+ end
58
+ end
59
+ end
60
+ raise Error, "Could not find #{text} in #{file}"
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Top level module
4
+ module CucumberJunitToJson
5
+ # module for all models
6
+ module Parsers
7
+ # Abstract representation of a junit xml file parser
8
+ class JunitParser
9
+ Error = Class.new(RuntimeError)
10
+ attr_accessor :path_to_junit
11
+ def initialize(path_to_junit)
12
+ STDERR.puts 'warning: no junit directory given' if path_to_junit.empty?
13
+ raise Error, "no such dir(s): #{path_to_junit}" unless Dir.exist?(path_to_junit)
14
+ @path_to_junit = path_to_junit
15
+ end
16
+
17
+ def read(file)
18
+ File.read(file).encode!('UTF-8', invalid: :replace)
19
+ end
20
+
21
+ def path_to_file(str)
22
+ arr = str.split('.')
23
+ "#{arr.first(arr.size - 1).join('/')}.feature"
24
+ end
25
+
26
+ def feature_name(str)
27
+ str.split('.').last.strip
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Cucumber Junit to Json version module
4
+ module CucumberJunitToJson
5
+ VERSION = '0.1.0'
6
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber_junit_to_json
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Voke Ransom Anighoro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-21 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
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: jbuilder
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.7'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.8'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: similar_text
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.0.4
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.0.4
97
+ description: Converts cucumber JUNIT xml reports to cucumber JSON format
98
+ email:
99
+ - ransom4real@gmail.com
100
+ executables:
101
+ - console
102
+ - cucumber_junit_to_json
103
+ - setup
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - ".gitignore"
108
+ - ".rubocop.yml"
109
+ - CODE_OF_CONDUCT.md
110
+ - Gemfile
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/cucumber_junit_to_json
116
+ - bin/setup
117
+ - cucumber_junit_to_json.gemspec
118
+ - lib/cucumber_junit_to_json.rb
119
+ - lib/cucumber_junit_to_json/app.rb
120
+ - lib/cucumber_junit_to_json/feature_json_builder.rb
121
+ - lib/cucumber_junit_to_json/models/argument.rb
122
+ - lib/cucumber_junit_to_json/models/feature.rb
123
+ - lib/cucumber_junit_to_json/models/match.rb
124
+ - lib/cucumber_junit_to_json/models/result.rb
125
+ - lib/cucumber_junit_to_json/models/scenario.rb
126
+ - lib/cucumber_junit_to_json/models/step.rb
127
+ - lib/cucumber_junit_to_json/models/table.rb
128
+ - lib/cucumber_junit_to_json/models/tag.rb
129
+ - lib/cucumber_junit_to_json/parsers/feature_parser.rb
130
+ - lib/cucumber_junit_to_json/parsers/junit_parser.rb
131
+ - lib/cucumber_junit_to_json/version.rb
132
+ homepage: https://github.com/ransom4real/cucumber_junit_to_json
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.4.8
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Converts cucumber JUNIT xml reports to cucumber JSON format
156
+ test_files: []