Skip to content

Instantly share code, notes, and snippets.

@Donavan
Created November 28, 2018 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Donavan/024f8369bb941409f301005a837f662f to your computer and use it in GitHub Desktop.
Save Donavan/024f8369bb941409f301005a837f662f to your computer and use it in GitHub Desktop.
Merge cucumber json
#!/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