2012-07-20 00:27:52 +02:00
|
|
|
#! /usr/bin/env ruby -S rspec
|
2011-06-29 22:21:55 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe "the values function" do
|
2012-07-23 17:28:06 +02:00
|
|
|
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
2011-06-29 22:21:55 +02:00
|
|
|
|
|
|
|
it "should exist" do
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(Puppet::Parser::Functions.function("values")).to eq("function_values")
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should raise a ParseError if there is less than 1 arguments" do
|
2014-06-04 20:38:37 +02:00
|
|
|
expect { scope.function_values([]) }.to( raise_error(Puppet::ParseError))
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|
|
|
|
|
2011-07-24 01:39:17 +02:00
|
|
|
it "should return values from a hash" do
|
2012-01-12 02:39:15 +01:00
|
|
|
result = scope.function_values([{'a'=>'1','b'=>'2','c'=>'3'}])
|
|
|
|
# =~ is the RSpec::Matchers::MatchArray matcher.
|
|
|
|
# A.K.A. "array with same elements" (multiset) matching
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to match_array(%w{ 1 2 3 })
|
2011-07-24 01:39:17 +02:00
|
|
|
end
|
|
|
|
|
2012-01-12 02:39:15 +01:00
|
|
|
it "should return a multiset" do
|
|
|
|
result = scope.function_values([{'a'=>'1','b'=>'3','c'=>'3'}])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to match_array(%w{ 1 3 3 })
|
|
|
|
expect(result).not_to match_array(%w{ 1 3 })
|
2011-07-29 23:18:56 +02:00
|
|
|
end
|
|
|
|
|
2012-01-12 02:39:15 +01:00
|
|
|
it "should raise a ParseError unless a Hash is provided" do
|
2014-06-04 20:38:37 +02:00
|
|
|
expect { scope.function_values([['a','b','c']]) }.to( raise_error(Puppet::ParseError))
|
2012-01-12 02:39:15 +01:00
|
|
|
end
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|