From 96e43e69d8496926ad4951534e75b204bb279f22 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Thu, 8 May 2014 10:47:24 -0700 Subject: Move unit tests to spec/functions rspec-puppet matchers are defined for tests which exist in spec/functions, but the function unit tests lived in spec/unit/puppet/parser/functions. This moves them to the correct place for using rspec-puppet --- spec/functions/concat_spec.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 spec/functions/concat_spec.rb (limited to 'spec/functions/concat_spec.rb') diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb new file mode 100755 index 0000000..6e67620 --- /dev/null +++ b/spec/functions/concat_spec.rb @@ -0,0 +1,30 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the concat function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should raise a ParseError if the client does not provide two arguments" do + lambda { scope.function_concat([]) }.should(raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if the first parameter is not an array" do + lambda { scope.function_concat([1, []])}.should(raise_error(Puppet::ParseError)) + end + + it "should be able to concat an array" do + result = scope.function_concat([['1','2','3'],['4','5','6']]) + result.should(eq(['1','2','3','4','5','6'])) + end + + it "should be able to concat a primitive to an array" do + result = scope.function_concat([['1','2','3'],'4']) + result.should(eq(['1','2','3','4'])) + end + + it "should not accidentally flatten nested arrays" do + result = scope.function_concat([['1','2','3'],[['4','5'],'6']]) + result.should(eq(['1','2','3',['4','5'],'6'])) + end + +end -- cgit v1.2.3 From 6287a200af558d277f83b919e8409f6c798eef39 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 4 Jun 2014 14:38:37 -0400 Subject: Convert specs to RSpec 2.99.0 syntax with Transpec This conversion is done by Transpec 2.2.1 with the following command: transpec spec/functions * 345 conversions from: obj.should to: expect(obj).to * 122 conversions from: == expected to: eq(expected) * 85 conversions from: lambda { }.should to: expect { }.to * 22 conversions from: be_true to: be_truthy * 16 conversions from: be_false to: be_falsey * 11 conversions from: pending to: skip * 9 conversions from: it { should ... } to: it { is_expected.to ... } * 5 conversions from: =~ [1, 2] to: match_array([1, 2]) * 2 conversions from: =~ /pattern/ to: match(/pattern/) * 2 conversions from: obj.should_not to: expect(obj).not_to For more details: https://github.com/yujinakayama/transpec#supported-conversions --- spec/functions/concat_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/functions/concat_spec.rb') diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb index 6e67620..b853b4c 100755 --- a/spec/functions/concat_spec.rb +++ b/spec/functions/concat_spec.rb @@ -5,26 +5,26 @@ describe "the concat function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should raise a ParseError if the client does not provide two arguments" do - lambda { scope.function_concat([]) }.should(raise_error(Puppet::ParseError)) + expect { scope.function_concat([]) }.to(raise_error(Puppet::ParseError)) end it "should raise a ParseError if the first parameter is not an array" do - lambda { scope.function_concat([1, []])}.should(raise_error(Puppet::ParseError)) + expect { scope.function_concat([1, []])}.to(raise_error(Puppet::ParseError)) end it "should be able to concat an array" do result = scope.function_concat([['1','2','3'],['4','5','6']]) - result.should(eq(['1','2','3','4','5','6'])) + expect(result).to(eq(['1','2','3','4','5','6'])) end it "should be able to concat a primitive to an array" do result = scope.function_concat([['1','2','3'],'4']) - result.should(eq(['1','2','3','4'])) + expect(result).to(eq(['1','2','3','4'])) end it "should not accidentally flatten nested arrays" do result = scope.function_concat([['1','2','3'],[['4','5'],'6']]) - result.should(eq(['1','2','3',['4','5'],'6'])) + expect(result).to(eq(['1','2','3',['4','5'],'6'])) end end -- cgit v1.2.3 From a6ad0af08e408adbb4b25684b18feb8aee12cf3e Mon Sep 17 00:00:00 2001 From: Spencer Krum Date: Tue, 19 Nov 2013 20:11:08 -0800 Subject: Introduce test for array destruction It was discovered that the concat array modifies the arrays passed to it as an argument as a side effect. This test will ensure that doesn't happen again. --- spec/functions/concat_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spec/functions/concat_spec.rb') diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb index b853b4c..49cb2ad 100755 --- a/spec/functions/concat_spec.rb +++ b/spec/functions/concat_spec.rb @@ -27,4 +27,9 @@ describe "the concat function" do expect(result).to(eq(['1','2','3',['4','5'],'6'])) end + it "should leave the original array intact" do + array_original = ['1','2','3'] + result = scope.function_concat([array_original,['4','5','6']]) + array_original.should(eq(['1','2','3'])) + end end -- cgit v1.2.3 From ed192a04648db7786d072bef23ed72849115d9de Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Thu, 4 Dec 2014 14:12:55 +0000 Subject: (MODULES-444) Add specs for new behaviour `concat` can now take multiple arguments --- spec/functions/concat_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec/functions/concat_spec.rb') diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb index 49cb2ad..4a18cd9 100755 --- a/spec/functions/concat_spec.rb +++ b/spec/functions/concat_spec.rb @@ -32,4 +32,14 @@ describe "the concat function" do result = scope.function_concat([array_original,['4','5','6']]) array_original.should(eq(['1','2','3'])) end + + it "should be able to concat multiple arrays" do + result = scope.function_concat([['1','2','3'],['4','5','6'],['7','8','9']]) + expect(result).to(eq(['1','2','3','4','5','6','7','8','9'])) + end + + it "should be able to concat mix of primitives and arrays to a final array" do + result = scope.function_concat([['1','2','3'],'4',['5','6','7']]) + expect(result).to(eq(['1','2','3','4','5','6','7'])) + end end -- cgit v1.2.3 From 7a1c4a6d9e4123a59fa85be18bd1b86ed5539b56 Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Thu, 4 Dec 2014 14:27:38 +0000 Subject: (MODULES-444) Change test to > 2 arguments Also add extra test for just 1 argument --- spec/functions/concat_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spec/functions/concat_spec.rb') diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb index 4a18cd9..d443c4b 100755 --- a/spec/functions/concat_spec.rb +++ b/spec/functions/concat_spec.rb @@ -4,8 +4,9 @@ require 'spec_helper' describe "the concat function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - it "should raise a ParseError if the client does not provide two arguments" do + it "should raise a ParseError if the client does not provide at least two arguments" do expect { scope.function_concat([]) }.to(raise_error(Puppet::ParseError)) + expect { scope.function_concat([[1]]) }.to(raise_error(Puppet::ParseError)) end it "should raise a ParseError if the first parameter is not an array" do -- cgit v1.2.3 From 368c97f08046696d453afca6e1f8001b5bfc88a5 Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Thu, 4 Dec 2014 14:27:55 +0000 Subject: (MODULES-444) - Check for accepting > 2 args --- spec/functions/concat_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/functions/concat_spec.rb') diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb index d443c4b..49fa6bb 100755 --- a/spec/functions/concat_spec.rb +++ b/spec/functions/concat_spec.rb @@ -13,6 +13,10 @@ describe "the concat function" do expect { scope.function_concat([1, []])}.to(raise_error(Puppet::ParseError)) end + it "should not raise a ParseError if the client provides more than two arguments" do + expect { scope.function_concat([[1],[2],[3]]) }.not_to raise_error + end + it "should be able to concat an array" do result = scope.function_concat([['1','2','3'],['4','5','6']]) expect(result).to(eq(['1','2','3','4','5','6'])) -- cgit v1.2.3