ApprovalTests.Ruby
ApprovalTests.Ruby copied to clipboard
Differences in JRuby and MRI HTML output
Similar to issue #84 there are also differences in the HTML output between JRuby and MRI.
Example:
describe "a html response" do
let(:test_html) do
<<-TEST
<!doctype html>
<head>
<title>Test Title</title>
<meta charset="utf-8"/>
</head>
<body>
<h1>Test Page</h1>
</body>
</html>
TEST
end
it "a test" do
verify do
test_html
end
end
end
MRI Output
MRI: 2.5.3
Approvals: 0.0.24
Nokogiri: 1.10.1
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Test Title</title>
<meta charset="utf-8" />
</head>
<body>
<h1>Test Page</h1>
</body>
</html>
JRuby Output
JRuby: 9.2.5.0
Approvals: 0.0.24
Nokogiri: 1.10.1-java
<!DOCTYPE html >
<html>
<head>
<title>Test Title</title>
<meta charset="utf-8" />
</head>
<body>
<h1>Test Page</h1>
</body>
</html>
Workaround
A workaround is to use the format: :txt
options, which produces the same (unchanged) output for both Ruby versions.
<!doctype html>
<head>
<title>Test Title</title>
<meta charset="utf-8"/>
</head>
<body>
<h1>Test Page</h1>
</body>
</html>
As far as I can tell, the issue is related to this line of code (https://github.com/kytrinyx/approvals/blob/master/lib/approvals/writers/html_writer.rb#L10), where Nokogiri
produces a different output for each of the two Ruby versions.