File: iniparse_spec.rb

package info (click to toggle)
ruby-iniparse 1.4.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 472 kB
  • sloc: ruby: 2,409; makefile: 3
file content (63 lines) | stat: -rw-r--r-- 1,485 bytes parent folder | download | duplicates (3)
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
54
55
56
57
58
59
60
61
62
63
require 'spec_helper'


describe "IniParse" do
  describe '.parse' do
    context 'with a line ending in a backslash' do
      let(:ini) do
        <<-'INI'.gsub(/^\s*/, '')
          [a]
          opt = 1 \
          other = 2
        INI
      end

      let(:doc) { IniParse.parse(ini) }

      it 'recognises the line continuation' do
        expect(doc.to_s).to eq("[a]\nopt = 1 other = 2\n")
      end

      it 'has one option' do
        expect(doc['a'].to_a.length).to eq(1)
      end
    end

    context 'with a line ending in a double-backslash' do
      let(:ini) do
        <<-'INI'.gsub(/^\s*/, '')
          [a]
          opt = 1 \\
          other = 2
        INI
      end

      let(:doc) { IniParse.parse(ini) }

      it 'does not see a line continuation' do
        expect(doc.to_s).to eq(ini)
      end

      it 'has one option' do
        expect(doc['a'].to_a.length).to eq(2)
      end
    end
  end

  describe '.open' do
    before(:each) { allow(File).to receive(:read).and_return('[section]') }

    it 'should return an IniParse::Document' do
      expect(IniParse.open('/my/path.ini')).to be_kind_of(IniParse::Document)
    end

    it 'should set the path on the returned Document' do
      expect(IniParse.open('/my/path.ini').path).to eq('/my/path.ini')
    end

    it 'should read the file at the given path' do
      expect(File).to receive(:read).with('/my/path.ini').and_return('[section]')
      IniParse.open('/my/path.ini')
    end
  end
end