diff --git a/lib/kubetruth/template.rb b/lib/kubetruth/template.rb index 51d66e8..a5f73ae 100644 --- a/lib/kubetruth/template.rb +++ b/lib/kubetruth/template.rb @@ -103,9 +103,11 @@ def stringify(str) str.to_s.to_json end - def to_yaml(str, no_header=false) + def to_yaml(str, options = {}) + options = {} unless options.is_a?(Hash) + p options result = str.to_yaml - result = result[4..-1] if no_header + result = result[4..-1] if options['no_header'] result end diff --git a/spec/kubetruth/template_spec.rb b/spec/kubetruth/template_spec.rb index 8d87cbe..4892426 100644 --- a/spec/kubetruth/template_spec.rb +++ b/spec/kubetruth/template_spec.rb @@ -128,11 +128,17 @@ module Kubetruth it "produces a yaml string" do expect(to_yaml([1, 2])).to eq("---\n- 1\n- 2\n") + # also check how liquid handles named parameters + expect(described_class.new("{{ var | to_yaml }}").render(var: [1, 2])).to eq("---\n- 1\n- 2\n") end it "produces header free yaml" do - expect(to_yaml([1, 2], true)).to eq("- 1\n- 2\n") - expect(to_yaml({"foo" => "bar"}, true)).to eq("foo: bar\n") + expect(to_yaml([1, 2], "no_header" => false)).to eq("---\n- 1\n- 2\n") + expect(to_yaml([1, 2], "no_header" => true)).to eq("- 1\n- 2\n") + expect(to_yaml({"foo" => "bar"}, "no_header" => true)).to eq("foo: bar\n") + # also verify that liquid handles named parameters + expect(described_class.new("{{ var | to_yaml: no_header: true}}").render(var: [1, 2])).to eq("- 1\n- 2\n") + expect(described_class.new("{{ var | to_yaml: no_header: false}}").render(var: [1, 2])).to eq("---\n- 1\n- 2\n") end end