lib/junit/plugin.rb in danger-junit-0.7.3 vs lib/junit/plugin.rb in danger-junit-0.7.4

- old
+ new

@@ -84,11 +84,11 @@ # Parses an XML file, which fills all the attributes, # will `raise` for errors # @return [void] def parse(file) require 'ox' - raise "No Junit file was found at #{file}" unless File.exist? file + raise "No JUnit file was found at #{file}" unless File.exist? file xml_string = File.read(file) @doc = Ox.parse(xml_string) suite_root = @doc.nodes.first.value == 'testsuites' ? @doc.nodes.first : @doc @@ -132,9 +132,17 @@ unless failures.empty? && errors.empty? fail('Tests have failed, see below for more information.', sticky: false) message = "### Tests: \n\n" tests = (failures + errors) + + # check the provided headers are available + unless headers.nil? + attributtesKey = tests.first.attributes.keys + not_available_headers = headers.select { |header| not attributtesKey.include?(header) } + raise "Some of headers provided aren't available in the JUnit report (#{not_available_headers})" unless not_available_headers.empty? + end + keys = headers || tests.first.attributes.keys attributes = keys.map(&:to_s).map(&:capitalize) # Create the headers message << attributes.join(' | ') + "|\n"