blob: aeef25af6b82665bce65b31ecf7d19a159e47660 (
plain)
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
|
require 'spec_helper'
describe Hashie::Extensions::Parsers::YamlErbParser do
describe '.perform' do
context 'a file' do
let(:config) do
<<-CONFIG
---
foo: verbatim
bar: <%= "erb" %>
baz: "<%= __FILE__ %>"
CONFIG
end
let(:path) { 'template.yml' }
subject { described_class.new(path).perform }
before do
expect(File).to receive(:read).with(path).and_return(config)
end
it { is_expected.to be_a(Hash) }
it 'parses YAML after interpolating ERB' do
expect(subject['foo']).to eq 'verbatim'
expect(subject['bar']).to eq 'erb'
expect(subject['baz']).to eq path
end
end
context 'Pathname' do
let(:tempfile) do
file = Tempfile.new(['foo', '.yml'])
file.write("---\nfoo: hello\n")
file.rewind
file
end
subject { described_class.new(Pathname(tempfile.path)) }
it '"#perform" can be done in case of path is a Pathname object.' do
expect(subject.perform).to eq 'foo' => 'hello'
end
end
end
end
|