spec/cfndsl_spec.rb in cfndsl-0.11.4 vs spec/cfndsl_spec.rb in cfndsl-0.11.5
- old
+ new
@@ -173,9 +173,31 @@
func = subject.FnNot('foo')
expect(func.to_json).to eq('{"Fn::Not":["foo"]}')
end
end
+ context 'FnSub', 'String' do
+ it 'formats correctly' do
+ func = subject.FnSub('http://aws.${AWS::Region}.com')
+ expect(func.to_json).to eq('{"Fn::Sub":"http://aws.${AWS::Region}.com"}')
+ end
+
+ it 'raises an error if not given a string' do
+ expect { subject.FnSub(1234) }.to raise_error(ArgumentError)
+ end
+ end
+
+ context 'FnSub', 'Hash' do
+ it 'formats correctly' do
+ func = subject.FnSub('http://aws.${domain}.com', domain: 'foo')
+ expect(func.to_json).to eq('{"Fn::Sub":["http://aws.${domain}.com",{"domain":"foo"}]}')
+ end
+
+ it 'raises an error if not given a second argument that is not a Hash' do
+ expect { subject.FnSub('abc', 123) }.to raise_error(ArgumentError)
+ end
+ end
+
context 'FnFormat', 'String' do
it 'formats correctly' do
func = subject.FnFormat('abc%0def%1ghi%%x', 'A', 'B')
expect(func.to_json).to eq('{"Fn::Join":["",["abc","A","def","B","ghi","%","x"]]}')
end