1 #! /usr/bin/env ruby -S rspec
4 describe "the values function" do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 expect(Puppet::Parser::Functions.function("values")).to eq("function_values")
11 it "should raise a ParseError if there is less than 1 arguments" do
12 expect { scope.function_values([]) }.to( raise_error(Puppet::ParseError))
15 it "should return values from a hash" do
16 result = scope.function_values([{'a'=>'1','b'=>'2','c'=>'3'}])
17 # =~ is the RSpec::Matchers::MatchArray matcher.
18 # A.K.A. "array with same elements" (multiset) matching
19 expect(result).to match_array(%w{ 1 2 3 })
22 it "should return a multiset" do
23 result = scope.function_values([{'a'=>'1','b'=>'3','c'=>'3'}])
24 expect(result).to match_array(%w{ 1 3 3 })
25 expect(result).not_to match_array(%w{ 1 3 })
28 it "should raise a ParseError unless a Hash is provided" do
29 expect { scope.function_values([['a','b','c']]) }.to( raise_error(Puppet::ParseError))