spec/support/incompatibilities_generator.rb in faml-0.3.3 vs spec/support/incompatibilities_generator.rb in faml-0.3.4

- old
+ new

@@ -70,19 +70,19 @@ def render_haml(template, options) obj = Object.new Haml::Engine.new(template, { ugly: true, escape_html: true }.merge(options)).def_method(obj, :haml) obj.haml - rescue => e + rescue StandardError, SyntaxError => e e end def render_hamlit(template, options) obj = Object.new obj.instance_eval "def hamlit; #{Hamlit::Engine.new(options).call(template)}; end" obj.hamlit - rescue => e + rescue StandardError, SyntaxError => e e end def render_difference(file, path, record) spec_path = Pathname.new(record.spec_path).relative_path_from(path.parent).to_s @@ -108,11 +108,11 @@ def render_grouped_difference(file, grouped_results) grouped_results.each do |title, result| file.write <<"EOS" ## #{render_section(title, result)} ```html -#{result} +#{render_body(result)} ``` EOS end end @@ -120,9 +120,25 @@ def render_section(title, result) if result.is_a?(Exception) "#{title} (Error)" else title + end + end + + def render_body(result) + if result.is_a?(Exception) + result + else + result.gsub(/[[:cntrl:]]/) do |m| + n = m[0].ord + if n == 0x0a + # Print NL character as is + m[0] + else + "<0x#{sprintf('%02X', n)}>" + end + end end end def markdown_path(markdown_root, spec_path) markdown_root.join(spec_path).sub_ext('.md')