08d21b037067251150c01dda8bede003ef1d27a8
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / values_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe "the values function" do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
7   it "should exist" do
8     expect(Puppet::Parser::Functions.function("values")).to eq("function_values")
9   end
10
11   it "should raise a ParseError if there is less than 1 arguments" do
12     expect { scope.function_values([]) }.to( raise_error(Puppet::ParseError))
13   end
14
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 })
20   end
21
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 })
26   end
27
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))
30   end
31 end