summaryrefslogtreecommitdiff
path: root/spec/functions/union_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/functions/union_spec.rb')
-rwxr-xr-xspec/functions/union_spec.rb32
1 files changed, 18 insertions, 14 deletions
diff --git a/spec/functions/union_spec.rb b/spec/functions/union_spec.rb
index 706f4cb..970e1fe 100755
--- a/spec/functions/union_spec.rb
+++ b/spec/functions/union_spec.rb
@@ -1,19 +1,23 @@
-#! /usr/bin/env ruby -S rspec
require 'spec_helper'
-describe "the union function" do
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
-
- it "should exist" do
- expect(Puppet::Parser::Functions.function("union")).to eq("function_union")
- end
-
- it "should raise a ParseError if there are fewer than 2 arguments" do
- expect { scope.function_union([]) }.to( raise_error(Puppet::ParseError) )
+describe 'union' do
+ describe 'argument checking' 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 { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
+ it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
+ it { is_expected.to run.with_params('one', []).and_raise_error(Puppet::ParseError, /Requires 2 arrays/) }
+ it { is_expected.to run.with_params([], 'two').and_raise_error(Puppet::ParseError, /Requires 2 arrays/) }
+ it { is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError, /Requires 2 arrays/) }
end
- it "should join two arrays together" do
- result = scope.function_union([["a","b","c"],["b","c","d"]])
- expect(result).to(eq(["a","b","c","d"]))
- end
+ it { is_expected.to run.with_params([], []).and_return([]) }
+ it { is_expected.to run.with_params([], ['one']).and_return(['one']) }
+ it { is_expected.to run.with_params(['one'], []).and_return(['one']) }
+ it { is_expected.to run.with_params(['one'], ['one']).and_return(['one']) }
+ it { is_expected.to run.with_params(['one'], ['two']).and_return(['one', 'two']) }
+ it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'three']).and_return(['one', 'two', 'three']) }
+ it { is_expected.to run.with_params(['one', 'two', 'two', 'three'], ['two', 'three']).and_return(['one', 'two', 'three']) }
+ it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'two', 'three']).and_return(['one', 'two', 'three']) }
+ it 'should not confuse types' do is_expected.to run.with_params(['1', '2', '3'], [1, 2]).and_return(['1', '2', '3', 1, 2]) end
end