File: encoding_spec.rb

package info (click to toggle)
ruby-roxml 3.3.1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 824 kB
  • ctags: 557
  • sloc: ruby: 4,066; xml: 1,013; makefile: 5
file content (53 lines) | stat: -rw-r--r-- 1,743 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# encoding: utf-8
require 'spec_helper'

describe ROXML, "encoding" do
  class TestResult
    include ROXML
    xml_accessor :message
  end
  
  context "when provided non-latin characters" do
    it "should output those characters as input via methods" do
      res = TestResult.new
      res.message = "sadfk одловыа jjklsd " #random russian  and english charecters
      doc = ROXML::XML::Document.new
      doc.root = res.to_xml
      if defined?(Nokogiri)
        doc.at('message').inner_text
      else
        doc.find_first('message').inner_xml
      end.should == "sadfk одловыа jjklsd "
    end
  
    it "should output those characters as input via xml" do
      res = TestResult.from_xml("<test_result><message>sadfk одловыа jjklsd </message></test_result>")
      doc = ROXML::XML::Document.new
      doc.root = res.to_xml
      if defined?(Nokogiri)
        doc.at('message').inner_text
      else
        doc.find_first('message').inner_xml
      end.should == "sadfk одловыа jjklsd "
    end
  
    it "should allow override via the document" do
      res = TestResult.from_xml("<test_result><message>sadfk одловыа jjklsd </message></test_result>")
      if defined?(Nokogiri)
        xml = res.to_xml
        doc = xml.document
        doc.root = xml
        doc.encoding = 'ISO-8859-1'
        doc.to_s.should include('ISO-8859-1')
        doc.at('message').inner_text
      else
        doc = LibXML::XML::Document.new
        doc.encoding = LibXML::XML::Encoding::ASCII
        doc.root = res.to_xml
        pending "Libxml bug"
        doc.to_s.should include('ISO-8859-1')
        doc.find_first('message').inner_xml
      end.should == "sadfk одловыа jjklsd "
    end
  end
end