Skip to content

Commit

Permalink
Merge pull request #12 from crevete/xml_encoding_fix
Browse files Browse the repository at this point in the history
Enforce XML document encoding to UTF-8
  • Loading branch information
aespinosa authored Mar 21, 2024
2 parents 3358a4c + c293e07 commit c3eed68
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/minitest/junit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def record(result)
end

def report
doc = Ox::Document.new(:version => '1.0')
doc = Ox::Document.new(version: '1.0', encoding: 'UTF-8')
instruct = Ox::Instruct.new(:xml)
instruct[:version] = '1.0'
instruct[:encoding] = 'UTF-8'
Expand Down Expand Up @@ -89,10 +89,6 @@ def working_directory
@working_directory ||= Dir.getwd
end

def failure_message(result)
"#{result.klass}##{result.name}: #{result.failure}"
end

def relative_to_cwd(path)
path.sub(working_directory, '.')
end
Expand Down
12 changes: 12 additions & 0 deletions test/reporter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ def test_no_tests_generates_an_empty_suite
)
end

# NOTE: This test will generate a temp file: "test/tmp/report.xml"
def test_encoding
# Enforce File.external_encoding to UTF-8 to ensure that ASCII character will be correctly converted to UTF-8
file = File.new('test/tmp/report.xml', 'w:UTF-8')
reporter = Minitest::Junit::Reporter.new file, { hostname: '‹foo›' }
reporter.start
reporter.report
file.close

assert_match(/hostname="‹foo›"/, File.new('test/tmp/report.xml', 'r:UTF-8').read)
end

def test_formats_each_successful_result_with_a_formatter
reporter = create_reporter

Expand Down
Empty file added test/tmp/.keep
Empty file.

0 comments on commit c3eed68

Please sign in to comment.