Update stdlib
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / union_spec.rb
index 706f4cb..3f36f24 100755 (executable)
@@ -1,19 +1,25 @@
-#! /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', []).and_raise_error(Puppet::ParseError, /Every parameter must be an array/) }
+    it { is_expected.to run.with_params([], 'two').and_raise_error(Puppet::ParseError, /Every parameter must be an array/) }
+    it { is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError, /Every parameter must be an array/) }
   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 { is_expected.to run.with_params(['one', 'two'], ['two', 'three'], ['one', 'three']).and_return(['one', 'two', 'three']) }
+  it { is_expected.to run.with_params(['one', 'two'], ['three', 'four'], ['one', 'two', 'three'], ['four']).and_return(['one', 'two', 'three', 'four']) }
+  it { is_expected.to run.with_params(['ốńə', 'ţשׂợ'], ['ŧĥяếệ', 'ƒởųŗ'], ['ốńə', 'ţשׂợ', 'ŧĥяếệ'], ['ƒởųŗ']).and_return(['ốńə', 'ţשׂợ', 'ŧĥяếệ', 'ƒởųŗ']) }
+  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