sj26 / rspec_junit_formatter

RSpec results that your CI can read
http://rubygems.org/gems/rspec_junit_formatter
MIT License
302 stars 122 forks source link

Provide some way to set the "hostname" attribute #42

Closed mcallaway closed 8 years ago

mcallaway commented 8 years ago

The current JUnit schema here:

https://github.com/windyroad/JUnit-Schema/blob/master/JUnit.xsd

provides for an attribute "hostname", "Host on which the tests were executed. 'localhost' should be used if the hostname cannot be determined."

It would be nice to be able to set this in some way. I'm using this module with Serverspec, and can get this feature with the following patch:

> diff -u rspec_junit_formatter.rb.orig rspec_junit_formatter.rb
--- rspec_junit_formatter.rb.orig       2016-08-23 12:14:52.000000000 -0500
+++ rspec_junit_formatter.rb    2016-08-23 12:14:46.000000000 -0500
@@ -52,7 +52,7 @@
   end

   def xml_dump_example(example, &block)
-    xml.testcase classname: classname_for(example), name: description_for(example), file: example_group_file_path_for(example), time: "%.6f" % duration_for(example), &block
+    xml.testcase classname: classname_for(example), hostname: ENV['TARGET_HOST'], name: description_for(example), file: example_group_file_path_for(example), time: "%.6f" % duration_for(example), &block
   end
 end

The use of an environment variable in this way is probably too naive. But it demonstrates the idea.

mcallaway commented 8 years ago

Turns out this hostname is not the one Jenkins cares about. Jenkins will only display "classname", so to make hostname visible in test results, I had to use "sed" to edit the XML results to prepend hostname on the classname. This is a shortcoming in Jenkins, in my view, not this formatter. I'm closing this issue.