cucumber_json_merge 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 45758bccd10b41321f1f99c13764161f34db8b7c
4
+ data.tar.gz: ef24380ebfb4fc19044ab2dab7bd90da77fc7320
5
+ SHA512:
6
+ metadata.gz: 637aadb9fae1509aaa8b58dbc0ce7fb566f88433f5908437a8bf51a05dbe8ff45185dc920b87af5d71a200aa363ae4ae782f2a2c66e27d961422c10ec2202404
7
+ data.tar.gz: dc0102503005ca03083dcd4bf4297879d56a82a77680952607ca717a9bd3ea6aa81c00cdc61f73bccb2f675144553f85065061437140ba8f140cee95a8ae6423
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,35 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+ Exclude:
4
+ - Gemfile
5
+ Style/ClassAndModuleChildren:
6
+ Enabled: false
7
+ Style/WhileUntilModifier:
8
+ MaxLineLength: 110
9
+ Style/IfUnlessModifier:
10
+ MaxLineLength: 110
11
+ Metrics/LineLength:
12
+ Enabled: false
13
+ Metrics/ClassLength:
14
+ Max: 170
15
+ Performance/RegexpMatch:
16
+ Enabled: false
17
+ Metrics/PerceivedComplexity:
18
+ Max: 20
19
+ MethodLength:
20
+ Max: 35
21
+ Metrics/ParameterLists:
22
+ Max: 10
23
+ Metrics/AbcSize:
24
+ Enabled: false
25
+ Style/PredicateName:
26
+ Enabled: false
27
+ Metrics/CyclomaticComplexity:
28
+ Max: 10
29
+ Security/Eval:
30
+ Enabled: false
31
+ Metrics/BlockLength:
32
+ Exclude:
33
+ - rake/**/*.rake
34
+ Style/VariableName:
35
+ 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_json_merge.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,45 @@
1
+ # Cucumber Json Merge
2
+
3
+ Merges two or more Cucumber JSON reports, such that results from the source JSON file overwrites the results on the target JSON file. Reports may be single files or directory trees.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'json_merge'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install json_merge
20
+
21
+ ## Usage
22
+
23
+ Run:
24
+
25
+ ```bash
26
+ cucumber_json_merge SOURCE.json SOURCE2.json ... TARGET.json
27
+ ```
28
+
29
+ Test results in the source JSON matching any results in the target JSON will overwrite them. If they are not existent in the target JSON then they will be appended to the target JSON file
30
+
31
+ ## Development
32
+
33
+ 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.
34
+
35
+ 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).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ransom4real/json_merge. 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.
40
+
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
45
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ # frozen_string_literal: true
2
+ require 'bundler/gem_tasks'
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ #!/usr/bin/env ruby
3
+
4
+ require 'bundler/setup'
5
+ require 'cucumber_json_merge'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ #!/usr/bin/env ruby
3
+
4
+ require_relative '../lib/cucumber_json_merge/app'
5
+
6
+ exit CucumberJsonMerge::App.new.run(*ARGV)
data/bin/setup ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ #!/usr/bin/env bash
3
+ set -euo pipefail
4
+ IFS=$'\n\t'
5
+ set -vx
6
+
7
+ bundle install
8
+
9
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+ # coding: utf-8
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'cucumber_json_merge/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'cucumber_json_merge'
9
+ spec.version = CucumberJsonMerge::VERSION
10
+ spec.authors = ['Voke Ransom Anighoro']
11
+ spec.email = ['voke.anighoro@gmail.com']
12
+
13
+ spec.summary = 'Tool to merge cucumber generated JSON files'
14
+ spec.description = 'Tool to merge cucumber generated JSON files'
15
+ spec.homepage = 'https://github.com/ransom4real/cucumber_json_merge'
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 'json', '~> 2.1'
30
+ spec.add_runtime_dependency 'deep_merge', '~> 1.2'
31
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+ require 'optparse'
3
+ require 'find'
4
+ require 'fileutils'
5
+ require 'json'
6
+ require 'deep_merge'
7
+
8
+ module CucumberJsonMerge
9
+ # The Cucumber Json Merge app class that handles std inputs and command line args
10
+ class App
11
+ Error = Class.new(RuntimeError)
12
+
13
+ def initialize(options = {})
14
+ @stdin = options[:stdin] || STDIN
15
+ @stdout = options[:stdout] || STDOUT
16
+ @stderr = options[:stderr] || STDERR
17
+ end
18
+
19
+ attr_reader :stdin, :stdout, :stderr
20
+
21
+ def run(*args)
22
+ *source_paths, target_path = parse_args(args)
23
+ all_paths = [*source_paths, target_path]
24
+
25
+ not_found = all_paths.select { |path| !File.exist?(path) }
26
+ raise Error, "no such file(s): #{not_found.join(', ')}" unless
27
+ not_found.empty?
28
+
29
+ if source_paths.empty?
30
+ stderr.puts 'warning: no source files given'
31
+ else
32
+ source_paths.each do |source_path|
33
+ if File.directory?(source_path)
34
+ Find.find(source_path) do |source_file_path|
35
+ next unless File.file?(source_file_path)
36
+ target_file_path = source_file_path.sub(source_path, target_path)
37
+ if File.exist?(target_file_path)
38
+ merge_file(source_file_path, target_file_path)
39
+ elsif !@update_only
40
+ FileUtils.mkdir_p(File.dirname(target_file_path))
41
+ FileUtils.cp(source_file_path, target_file_path)
42
+ end
43
+ end
44
+ elsif File.exist?(source_path)
45
+ merge_file(source_path, target_path)
46
+ end
47
+ end
48
+ end
49
+ 0
50
+ rescue Error, OptionParser::ParseError => error
51
+ stderr.puts error.message
52
+ 1
53
+ end
54
+
55
+ private
56
+
57
+ def merge_file(source_path, target_path)
58
+ source_text = File.read(source_path).encode!('UTF-8', invalid: :replace)
59
+ target_text = File.read(target_path).encode!('UTF-8', invalid: :replace)
60
+
61
+ return if target_text =~ /\A\s*\z/m
62
+
63
+ if source_text =~ /\A\s*\z/m
64
+ FileUtils.cp source_path, target_path
65
+ return
66
+ end
67
+
68
+ source = JSON.parse(source_text)
69
+ target = JSON.parse(target_text)
70
+
71
+ source.each do |source_feature|
72
+ target_feature_match = false
73
+ target.each do |target_feature|
74
+ next unless target_feature['name'] == source_feature['name']
75
+ target_feature_match = true
76
+ source_feature['elements'].each do |source_scenario|
77
+ target_scenario_match = false
78
+ target_feature['elements'].each_with_index do |target_scenario, s_index|
79
+ next unless target_scenario['keyword'] == source_scenario[
80
+ 'keyword'] && target_scenario['name'] == source_scenario[
81
+ 'name']
82
+ target_scenario_match = true
83
+ target_feature['elements'][s_index] = source_scenario
84
+ end
85
+ target_feature['elements'].push(source_scenario) unless target_scenario_match
86
+ end
87
+ end
88
+ unless target_feature_match
89
+ source_feature['id'] = target.size + 1
90
+ target.push(source_feature)
91
+ end
92
+ end
93
+
94
+ open(target_path, 'w') { |f| f.write(target.to_json) }
95
+ end
96
+
97
+ def parse_args(args)
98
+ parser = OptionParser.new do |p|
99
+ p.banner = "USAGE: #{$PROGRAM_NAME} [options] SOURCES ... TARGET"
100
+ end
101
+
102
+ parser.parse!(args)
103
+
104
+ raise Error, parser.banner unless args.size >= 1
105
+
106
+ args
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ # Cucumber Json Merge version module
3
+ module CucumberJsonMerge
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ # Cucumber Json Merge Module
3
+ module CucumberJsonMerge
4
+ autoload :App, 'cucumber_json_merge/app'
5
+ autoload :VERSION, 'cucumber_json_merge/version'
6
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber_json_merge
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-08 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: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: deep_merge
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
69
+ description: Tool to merge cucumber generated JSON files
70
+ email:
71
+ - voke.anighoro@gmail.com
72
+ executables:
73
+ - console
74
+ - cucumber_json_merge
75
+ - setup
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".rubocop.yml"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/cucumber_json_merge
88
+ - bin/setup
89
+ - cucumber_json_merge.gemspec
90
+ - lib/cucumber_json_merge.rb
91
+ - lib/cucumber_json_merge/app.rb
92
+ - lib/cucumber_json_merge/version.rb
93
+ homepage: https://github.com/ransom4real/cucumber_json_merge
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.8
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Tool to merge cucumber generated JSON files
117
+ test_files: []