spec/lib/formats/yaml_spec.rb in hieracles-0.0.1 vs spec/lib/formats/yaml_spec.rb in hieracles-0.0.2
- old
+ new
@@ -55,15 +55,23 @@
end
describe ".params" do
let(:expected) {
"---\n"+
- "params:\n" +
- " this:\n" +
- " var: value1\n"
+ "params: \n" +
+ " this: \n" +
+ " var: value1 # some/file"
}
before {
+ allow(node).to receive(:params).and_return(
+ {
+ 'params.this.var' => [{
+ file: 'some/file',
+ value: 'value1'
+ }]
+ }
+ )
allow(node).to receive(:params_tree).and_return(
{
'params' => {
'this' => {
'var' => 'value1'
@@ -74,7 +82,145 @@
}
it "outputs proper text" do
expect(yaml_format.params nil).to eq expected
end
end
-
+
+ describe '.mergetree' do
+ context "with a simple string key-value" do
+ let(:params) {
+ {
+ 'key' => [{
+ file: 'what/file',
+ value: 'value'
+ }]
+ }
+ }
+ let(:input) {
+ { 'key' => 'value' }
+ }
+ let(:expected) {
+ "\nkey: value # what/file"
+ }
+ it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
+ end
+ context "with a simple array key-value" do
+ let(:params) {
+ {
+ 'key' => [{
+ file: 'what/file',
+ value: ['value1', 'value2']
+ }]
+ }
+ }
+ let(:input) {
+ { 'key' => ['value1', 'value2'] }
+ }
+ let(:expected) {
+ "\nkey: \n # what/file\n - value1\n - value2"
+ }
+ it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
+ end
+ context "with a 2-levels string key-value" do
+ let(:params) {
+ {
+ 'key.sublevel' => [{
+ file: 'what/file',
+ value: 'value'
+ }]
+ }
+ }
+ let(:input) {
+ {
+ 'key' => {
+ 'sublevel' => 'value'
+ }
+ }
+ }
+ let(:expected) {
+ "\nkey: \n sublevel: value # what/file"
+ }
+ it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
+ end
+ context "with 2 2-levels string key-value" do
+ let(:params) {
+ {
+ 'key.sublevel' => [{
+ file: 'what/file',
+ value: 'value'
+ }],
+ 'key.sublevel2' => [{
+ file: 'what/file2',
+ value: 'value2'
+ }]
+ }
+ }
+ let(:input) {
+ {
+ 'key' => {
+ 'sublevel' => 'value',
+ 'sublevel2' => 'value2'
+ }
+ }
+ }
+ let(:expected) {
+ "\nkey: \n sublevel: value # what/file\n sublevel2: value2 # what/file2"
+ }
+ it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
+ end
+ context "with a 3-levels string key-value" do
+ let(:params) {
+ {
+ 'key.sublevel.subsublevel' => [{
+ file: 'what/file',
+ value: 'value'
+ }]
+ }
+ }
+ let(:input) {
+ {
+ 'key' => {
+ 'sublevel' => {
+ 'subsublevel' => 'value'
+ }
+ }
+ }
+ }
+ let(:expected) {
+ "\nkey: \n sublevel: \n subsublevel: value # what/file"
+ }
+ it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
+ end
+ context "with a 3-levels double string key-value" do
+ let(:params) {
+ {
+ 'key.sublevel.subsublevel' => [{
+ file: 'what/file',
+ value: 'value'
+ }],
+ 'key2.sublevel' => [{
+ file: 'what/file2',
+ value: 'value'
+ }]
+ }
+ }
+ let(:input) {
+ {
+ 'key' => {
+ 'sublevel' => {
+ 'subsublevel' => 'value'
+ }
+ },
+ 'key2' => {
+ 'sublevel' => 'value'
+ }
+ }
+ }
+ let(:expected) {
+ "\nkey: \n sublevel: \n subsublevel: value # what/file" +
+ "\nkey2: \n sublevel: value # what/file2"
+ }
+ it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
+ end
+ end
+
end