spec/lib/formats/yaml_spec.rb in hieracles-0.2.0 vs spec/lib/formats/yaml_spec.rb in hieracles-0.2.1
- old
+ new
@@ -15,10 +15,23 @@
)
}
it { expect(yaml_format.info nil).to eq expected }
end
+ describe ".facts" do
+ let(:expected) {"---\nNode: fqdn\nFarm: farm\n"}
+ before {
+ allow(node).to receive(:facts).and_return(
+ {
+ 'Node' => 'fqdn',
+ 'Farm' => 'farm'
+ }
+ )
+ }
+ it { expect(yaml_format.facts nil).to eq expected }
+ end
+
describe ".files" do
let(:expected) { "---\n- path1\n- path2\n" }
before {
allow(node).to receive(:files).and_return(['path1', 'path2'])
}
@@ -45,65 +58,125 @@
}
it { expect(yaml_format.modules nil).to eq expected }
end
describe ".params" do
- let(:expected) {
- "---\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'
+ context "with args" do
+ let(:expected) {
+ "---\n" +
+ "params: \n" +
+ " this: \n" +
+ " var: value1 # some/file"
+ }
+ before {
+ allow(node).to receive(:params).with(true).and_return(
+ {
+ 'params.this.var' => [{
+ file: 'some/file',
+ value: 'value1'
+ }]
+ }
+ )
+ allow(node).to receive(:params_tree).with(true).and_return(
+ {
+ 'params' => {
+ 'this' => {
+ 'var' => 'value1'
+ }
}
}
- }
- )
- }
- it { expect(yaml_format.params nil).to eq expected }
+ )
+ }
+ it { expect(yaml_format.params ['some', 'things']).to eq expected }
+ end
+ context "without args" do
+ let(:expected) {
+ "---\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'
+ }
+ }
+ }
+ )
+ }
+ it { expect(yaml_format.params nil).to eq expected }
+ end
end
describe ".allparams" do
- let(:expected) {
- "---\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'
+ context 'with args' do
+ let(:expected) {
+ "---\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'
+ }
}
}
- }
- )
- }
- it { expect(yaml_format.allparams nil).to eq expected }
+ )
+ }
+ it { expect(yaml_format.allparams nil).to eq expected }
+ end
+ context 'without args' do
+ let(:expected) {
+ "---\n"+
+ "params: \n" +
+ " this: \n" +
+ " var: value1 # some/file"
+ }
+ before {
+ allow(node).to receive(:params).with(false).and_return(
+ {
+ 'params.this.var' => [{
+ file: 'some/file',
+ value: 'value1'
+ }]
+ }
+ )
+ allow(node).to receive(:params_tree).with(false).and_return(
+ {
+ 'params' => {
+ 'this' => {
+ 'var' => 'value1'
+ }
+ }
+ }
+ )
+ }
+ it { expect(yaml_format.allparams ['some', 'things']).to eq expected }
+ end
end
describe '.mergetree' do
context "with a simple string key-value" do
let(:params) {
@@ -134,9 +207,26 @@
let(:input) {
{ 'key' => true }
}
let(:expected) {
"\nkey: true # what/file"
+ }
+ it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
+ end
+ context "with various null type of key-values (nil)" do
+ let(:params) {
+ {
+ 'key' => [{
+ file: 'what/file',
+ value: nil
+ }]
+ }
+ }
+ let(:input) {
+ { 'key' => nil }
+ }
+ let(:expected) {
+ "\nkey: # what/file"
}
it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
end
context "with various boolean type of key-values (false)" do
let(:params) {