Created
November 28, 2018 18:32
-
-
Save Donavan/024f8369bb941409f301005a837f662f to your computer and use it in GitHub Desktop.
Merge cucumber json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
require 'json' | |
require 'yaml' | |
require 'pry' | |
def remove_backgrounds(features) | |
features.each do |feature| | |
scenarios = feature['elements'] | |
scenarios.each_with_index do |scen, i| | |
next unless scen['type'] == 'background' | |
next_scen = scenarios[i + 1] | |
next_scen['steps'] = scen['steps'].concat(next_scen['steps']) | |
end | |
scenarios.delete_if { |s| s['type'] == 'background' } | |
end | |
features | |
end | |
def remove_dups(features) | |
features.each do |feature| | |
feature['elements'].reverse!.uniq! { |s| s['name'] } | |
feature['elements'].reverse! | |
end | |
features | |
end | |
files = Dir.glob(ARGV[0].delete('\\')) | |
data = [] | |
files.each { |f| data.concat(JSON.parse(File.read(f))) } | |
data = remove_dups(remove_backgrounds(data)) | |
outfile = ARGV[1] || 'out.json' | |
File.open(outfile, 'wb') { |f| f.write(JSON.dump(data)) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment