diff --git a/lib/onceover/controlrepo.rb b/lib/onceover/controlrepo.rb index 4c752a20..6071faf0 100644 --- a/lib/onceover/controlrepo.rb +++ b/lib/onceover/controlrepo.rb @@ -104,7 +104,7 @@ def initialize(opts = {}) @onceover_yaml = ENV['ONCEOVER_YAML'] || opts[:onceover_yaml] || File.expand_path("#{@root}/spec/onceover.yaml") - if File.exists?(@onceover_yaml) && _data = YAML.load_file(@onceover_yaml) + if File.exist?(@onceover_yaml) && _data = YAML.load_file(@onceover_yaml) opts.merge!(_data.fetch('opts',{})||{}) end opts.fetch(:facts_dir,'').sub!(%r{^[^/.].+} ){|path| File.expand_path(path, @root)} @@ -475,7 +475,7 @@ def self.init(repo) # Add .onceover to Gitignore gitignore_path = File.expand_path('.gitignore', repo.root) - if File.exists? gitignore_path + if File.exist? gitignore_path gitignore_content = (File.open(gitignore_path, 'r') {|f| f.read }).split("\n") message = "#{'changed'.green}" else @@ -567,7 +567,7 @@ def self.evaluate_template(template_name, bind) def self.init_write_file(contents, out_file) create_dirs_and_log(File.dirname(out_file)) - if File.exists?(out_file) + if File.exist?(out_file) puts "#{'skipped'.yellow} #{Pathname.new(out_file).relative_path_from(Pathname.new(Dir.pwd)).to_s} #{'(exists)'.yellow}" else File.open(out_file,'w') {|f| f.write(contents)} diff --git a/lib/onceover/rspec/formatters.rb b/lib/onceover/rspec/formatters.rb index ad852179..29c7ae37 100644 --- a/lib/onceover/rspec/formatters.rb +++ b/lib/onceover/rspec/formatters.rb @@ -59,7 +59,7 @@ def dump_failures notification # Put some spacing before the results @output << "\n\n\n" - failures.each do |_name, role| + failures.each do |name, errors| @output << Onceover::Controlrepo.evaluate_template('error_summary.yaml.erb', binding) end @@ -74,20 +74,34 @@ def extract_failures notification # Further group by error grouped.each do |role, failures| - grouped[role] = failures.uniq { |f| f.metadata[:execution_result].exception.to_s } + grouped[role] = failures.group_by { |f| f.metadata[:execution_result].exception.to_s } end # Extract the errors and remove all RSpec objects grouped.each do |role, failures| - grouped[role] = { - name: role, - errors: failures.map { |f| parse_errors(f.metadata[:execution_result].exception.to_s)}.flatten, - } + grouped[role] = failures.map { |_description, fails| extract_failure_data(fails)}.flatten end grouped end + # Extaracts data out of RSpec failres + def extract_failure_data(fails) + # The only difference between these failures should be the factsets that it + # failed on. Extract that list then just use the first failure for the rest + # of the data as it should be the same + metadata = fails[0].metadata + raw_error = metadata[:execution_result].exception.to_s + factsets = fails.map { |f| f.metadata[:example_group][:description].gsub('using fact set ','') } + results = parse_errors(raw_error) + # Add the details of the factsets tio each result + results.map do |r| + r[:factsets] = factsets + r + end + end + + # Parses information out of a string error def parse_errors(raw_error) # Check if the error is a compilation error match = COMPILATION_ERROR.match(raw_error) @@ -247,9 +261,9 @@ def output_results(directory) files = Dir["#{directory}/*.yaml"] # Merge data - errors = files.reduce({}) do |errs, file| + roles = files.reduce({}) do |errs, file| # Read all files and merge them - errs.merge(YAML.load(File.read(file))) # rubocop:disable Security/YAMLLoad + errs.merge(YAML.load(File.read(file))) {|key, oldval, newval| [oldval, newval].flatten }# rubocop:disable Security/YAMLLoad end # Delete files from the disk @@ -258,7 +272,7 @@ def output_results(directory) @output << "\n\n\n" # Output errors - errors.each do |_name, role| + roles.each do |name, errors| @output << Onceover::Controlrepo.evaluate_template('error_summary.yaml.erb', binding) end @output << "\n" diff --git a/templates/error_summary.yaml.erb b/templates/error_summary.yaml.erb index 353d60d5..e05fd4d8 100644 --- a/templates/error_summary.yaml.erb +++ b/templates/error_summary.yaml.erb @@ -1,6 +1,6 @@ -<%= bold(role[:name]) %>: <%= red('failed') %> +<%= bold(name) %>: <%= red('failed') %> errors: -<% role[:errors].each do |error| -%> +<% errors.each do |error| -%> <%= red(error[:text]) %> <% if error[:file] -%> file: <%= bold(error[:file]) %> @@ -11,4 +11,7 @@ <% if error[:column] -%> column: <%= bold(error[:column]) %> <% end -%> +<% if error[:factsets] -%> + factsets: <%= bold(error[:factsets].join(', ')) %> +<% end -%> <% end -%>