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/suffix_spec.rb | 65 +++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 24 deletions(-) (limited to 'spec/functions/suffix_spec.rb') diff --git a/spec/functions/suffix_spec.rb b/spec/functions/suffix_spec.rb index c7783c6..b48a4eb 100755 --- a/spec/functions/suffix_spec.rb +++ b/spec/functions/suffix_spec.rb @@ -1,27 +1,44 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the suffix function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "raises a ParseError if there is less than 1 arguments" do - expect { scope.function_suffix([]) }.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_suffix([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_suffix([['first', 'second'], 42]) - }.to raise_error(Puppet::ParseError, /expected second argument to be a String/) - end - - it "returns a suffixed array" do - result = scope.function_suffix([['a','b','c'], 'p']) - expect(result).to(eq(['ap','bp','cp'])) - end +describe 'suffix' 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/) } + 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'], 'post').and_return(['onepost']) } + it { is_expected.to run.with_params(['one', 'two', 'three'], 'post').and_return(['onepost', 'twopost', 'threepost']) } + it { + pending("implementation of Hash functionality matching prefix") + is_expected.to run.with_params({}).and_return({}) + } + it { + pending("implementation of Hash functionality matching prefix") + is_expected.to run.with_params({ 'key1' => 'value1', 2 => 3}).and_return({ 'key1' => 'value1', '2' => 3 }) + } + it { + pending("implementation of Hash functionality matching prefix") + is_expected.to run.with_params({}, '').and_return({}) + } + it { + pending("implementation of Hash functionality matching prefix") + is_expected.to run.with_params({ 'key' => 'value' }, '').and_return({ 'key' => 'value' }) + } + it { + pending("implementation of Hash functionality matching prefix") + is_expected.to run.with_params({ 'key' => 'value' }, 'post').and_return({ 'keypost' => 'value' }) + } + it { + pending("implementation of Hash functionality matching prefix") + is_expected.to run \ + .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, 'pre') \ + .and_return({ 'key1post' => 'value1', 'key2post' => 'value2', 'key3post' => 'value3' }) + } end -- cgit v1.2.3 From 85ff2a28a83984c827985181d58c55ca8c524ed6 Mon Sep 17 00:00:00 2001 From: Reinhard Vicinus Date: Tue, 22 Mar 2016 15:06:31 +0100 Subject: improve suffix function to support the same feature set as prefix --- spec/functions/suffix_spec.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'spec/functions/suffix_spec.rb') diff --git a/spec/functions/suffix_spec.rb b/spec/functions/suffix_spec.rb index b48a4eb..efba4ab 100755 --- a/spec/functions/suffix_spec.rb +++ b/spec/functions/suffix_spec.rb @@ -16,29 +16,23 @@ describe 'suffix' do it { is_expected.to run.with_params(['one'], 'post').and_return(['onepost']) } it { is_expected.to run.with_params(['one', 'two', 'three'], 'post').and_return(['onepost', 'twopost', 'threepost']) } it { - pending("implementation of Hash functionality matching prefix") is_expected.to run.with_params({}).and_return({}) } it { - pending("implementation of Hash functionality matching prefix") is_expected.to run.with_params({ 'key1' => 'value1', 2 => 3}).and_return({ 'key1' => 'value1', '2' => 3 }) } it { - pending("implementation of Hash functionality matching prefix") is_expected.to run.with_params({}, '').and_return({}) } it { - pending("implementation of Hash functionality matching prefix") is_expected.to run.with_params({ 'key' => 'value' }, '').and_return({ 'key' => 'value' }) } it { - pending("implementation of Hash functionality matching prefix") is_expected.to run.with_params({ 'key' => 'value' }, 'post').and_return({ 'keypost' => 'value' }) } it { - pending("implementation of Hash functionality matching prefix") is_expected.to run \ - .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, 'pre') \ + .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, 'post') \ .and_return({ 'key1post' => 'value1', 'key2post' => 'value2', 'key3post' => 'value3' }) } end -- cgit v1.2.3