diff --git a/lib/simplecov-cobertura.rb b/lib/simplecov-cobertura.rb index 40870c2..59a6cfe 100644 --- a/lib/simplecov-cobertura.rb +++ b/lib/simplecov-cobertura.rb @@ -49,6 +49,7 @@ def result_to_xml(result) end groups.map do |name, files| + next if files.empty? packages.add_element(package = REXML::Element.new('package')) set_package_attributes(package, name, files) diff --git a/test/simplecov-cobertura_test.rb b/test/simplecov-cobertura_test.rb index 4b99643..d9a1456 100644 --- a/test/simplecov-cobertura_test.rb +++ b/test/simplecov-cobertura_test.rb @@ -8,7 +8,13 @@ class CoberturaFormatterTest < Test::Unit::TestCase def setup - @result = SimpleCov::Result.new({ "#{__FILE__}" => [1,2] }) + coverage_data = + if Gem.loaded_specs['simplecov'].version >= Gem::Version.new('0.18') + { lines: [1, 2] } + else + [1, 2] + end + @result = SimpleCov::Result.new({ __FILE__ => coverage_data }) @formatter = SimpleCov::Formatter::CoberturaFormatter.new end @@ -136,6 +142,7 @@ def test_groups end def test_supports_root_project_path + pend 'Creating files at `/` is not permitted in CI' old_root = SimpleCov.root SimpleCov.root('/') expected_base = old_root[1..-1] # Remove leading "/"