File: multi_xml_spec.rb

package info (click to toggle)
ruby-multi-xml 0.6.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 216 kB
  • sloc: ruby: 1,231; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,449 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
require 'helper'
require 'parser_shared_example'

class MockDecoder
  def self.parse; end
end

describe 'MultiXml' do
  context 'Parsers' do
    it 'picks a default parser' do
      expect(MultiXml.parser).to be_kind_of(Module)
      expect(MultiXml.parser).to respond_to(:parse)
    end

    it 'defaults to the best available gem' do
      # Clear cache variable possibly set by previous tests
      MultiXml.send(:remove_instance_variable, :@parser) if MultiXml.instance_variable_defined?(:@parser)
      if jruby?
        # Ox and Libxml are not not currently available on JRuby, so Nokogiri is the best available gem
        expect(MultiXml.parser.name).to eq('MultiXml::Parsers::Nokogiri')
      else
        expect(MultiXml.parser.name).to eq('MultiXml::Parsers::Ox')
      end
    end

    it 'is settable via a symbol' do
      MultiXml.parser = :rexml
      expect(MultiXml.parser.name).to eq('MultiXml::Parsers::Rexml')
    end

    it 'is settable via a class' do
      MultiXml.parser = MockDecoder
      expect(MultiXml.parser.name).to eq('MockDecoder')
    end
  end

  [%w(LibXML libxml),
   %w(REXML rexml/document),
   %w(Nokogiri nokogiri),
   %w(Ox ox),
   %w(Oga oga)].each do |parser|
    begin
      require parser.last
      context "#{parser.first} parser" do
        it_behaves_like 'a parser', parser.first
      end
    rescue LoadError
      puts "Tests not run for #{parser.first} due to a LoadError"
    end
  end
end