blob: aafcfd43215fe0912df2a48029f66b15db3fd5bb (
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
47
48
49
50
51
52
53
54
55
56
57
|
require 'spec_helper'
require 'safe_yaml/store'
describe SafeYAML::Store do
let(:file) { 'spec/store.yaml' }
let(:content) { "--- \nfoo: 42\n:bar: \"party\"\n" }
before do
# Rewrite file on every test, as its contents are potentially modified by
# SafeYAML::Store#transaction
File.open(file, 'w') { |f| f.write(content) }
end
def expect_safe_load(options = {})
load_args = [content, options]
load_args.insert(1, nil) if SafeYAML::YAML_ENGINE == 'psych'
expect(SafeYAML).to receive(:load).with(*load_args).and_call_original
expect(YAML).not_to receive(:load)
end
let(:init_args) { [file] }
subject { described_class.new(*init_args) }
it 'should be a YAML::Store' do
expect(subject).to be_a(YAML::Store)
end
it 'should be a SafeYAML::Store' do
expect(subject).to be_a(SafeYAML::Store)
end
it 'should use SafeYAML.load instead of YAML.load' do
expect_safe_load
expect(subject.transaction { subject['foo'] }).to eq(42)
end
it 'preserves default SafeYAML behavior' do
expect(subject.transaction { subject[:bar] }).to eq(nil)
expect(subject.transaction { subject[':bar'] }).to eq('party')
end
describe 'with options' do
let(:init_args) { super().insert(2, :deserialize_symbols => true) }
it 'should accept options for SafeYAML.load' do
expect_safe_load(:deserialize_symbols => true)
expect(subject.transaction { subject[:bar] }).to eq('party')
end
end
end
|