From 0236cd51bc2724b4ac68b91dda01d1b58b572df8 Mon Sep 17 00:00:00 2001 From: Stefan Goethals Date: Wed, 4 Jun 2014 06:12:22 -0700 Subject: Add support for hashes in the prefix function Signed-off-by: Julien Pivotto --- spec/functions/prefix_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spec/functions/prefix_spec.rb') diff --git a/spec/functions/prefix_spec.rb b/spec/functions/prefix_spec.rb index 34cac53..aec8a7d 100755 --- a/spec/functions/prefix_spec.rb +++ b/spec/functions/prefix_spec.rb @@ -25,4 +25,9 @@ describe "the prefix function" do result = scope.function_prefix([['a','b','c'], 'p']) expect(result).to(eq(['pa','pb','pc'])) end + + it "returns a prefixed hash" do + result = scope.function_prefix([{'a' => 'b','b' => 'c','c' => 'd'}, 'p']) + expect(result).to(eq({'pa'=>'b','pb'=>'c','pc'=>'d'})) + end end -- cgit v1.2.3 From f3e79ddcd56a221c7799b35efde7e9803a5c7923 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Mon, 1 Jun 2015 12:21:59 +0100 Subject: Convert tests to use plain rspec-puppet Tests in the new style produces the following documentation output: abs should not eq nil should run abs() and raise an Puppet::ParseError should run abs(-34) and return 34 should run abs("-34") and return 34 should run abs(34) and return 34 should run abs("34") and return 34 --- spec/functions/prefix_spec.rb | 55 ++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 30 deletions(-) (limited to 'spec/functions/prefix_spec.rb') diff --git a/spec/functions/prefix_spec.rb b/spec/functions/prefix_spec.rb index aec8a7d..3761022 100755 --- a/spec/functions/prefix_spec.rb +++ b/spec/functions/prefix_spec.rb @@ -1,33 +1,28 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the prefix function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "raises a ParseError if there is less than 1 arguments" do - expect { scope.function_prefix([]) }.to raise_error(Puppet::ParseError, /number of arguments/) - end - - it "raises an error if the first argument is not an array" do - expect { - scope.function_prefix([Object.new]) - }.to raise_error(Puppet::ParseError, /expected first argument to be an Array/) - end - - - it "raises an error if the second argument is not a string" do - expect { - scope.function_prefix([['first', 'second'], 42]) - }.to raise_error(Puppet::ParseError, /expected second argument to be a String/) - end - - it "returns a prefixed array" do - result = scope.function_prefix([['a','b','c'], 'p']) - expect(result).to(eq(['pa','pb','pc'])) - end - - it "returns a prefixed hash" do - result = scope.function_prefix([{'a' => 'b','b' => 'c','c' => 'd'}, 'p']) - expect(result).to(eq({'pa'=>'b','pb'=>'c','pc'=>'d'})) - end +describe 'prefix' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the second.") + is_expected.to run.with_params([], 'a', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, /expected first argument to be an Array or a Hash/) } + it { is_expected.to run.with_params([], 2).and_raise_error(Puppet::ParseError, /expected second argument to be a String/) } + it { is_expected.to run.with_params([]).and_return([]) } + it { is_expected.to run.with_params(['one', 2]).and_return(['one', '2']) } + it { is_expected.to run.with_params([], '').and_return([]) } + it { is_expected.to run.with_params([''], '').and_return(['']) } + it { is_expected.to run.with_params(['one'], 'pre').and_return(['preone']) } + it { is_expected.to run.with_params(['one', 'two', 'three'], 'pre').and_return(['preone', 'pretwo', 'prethree']) } + it { is_expected.to run.with_params({}).and_return({}) } + it { is_expected.to run.with_params({ 'key1' => 'value1', 2 => 3}).and_return({ 'key1' => 'value1', '2' => 3 }) } + it { is_expected.to run.with_params({}, '').and_return({}) } + it { is_expected.to run.with_params({ 'key' => 'value' }, '').and_return({ 'key' => 'value' }) } + it { is_expected.to run.with_params({ 'key' => 'value' }, 'pre').and_return({ 'prekey' => 'value' }) } + it { + is_expected.to run \ + .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, 'pre') \ + .and_return({ 'prekey1' => 'value1', 'prekey2' => 'value2', 'prekey3' => 'value3' }) + } end -- cgit v1.2.3