]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/upcase_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / upcase_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe "the upcase function" do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
7   it "should exist" do
8     expect(Puppet::Parser::Functions.function("upcase")).to eq("function_upcase")
9   end
10
11   it "should raise a ParseError if there is less than 1 arguments" do
12     expect { scope.function_upcase([]) }.to(raise_error(Puppet::ParseError))
13   end
14
15   it "should upcase a string" do
16     result = scope.function_upcase(["abc"])
17     expect(result).to(eq('ABC'))
18   end
19
20   it "should do nothing if a string is already upcase" do
21     result = scope.function_upcase(["ABC"])
22     expect(result).to(eq('ABC'))
23   end
24
25   it "should accept objects which extend String" do
26     class AlsoString < String
27     end
28
29     value = AlsoString.new('abc')
30     result = scope.function_upcase([value])
31     result.should(eq('ABC'))
32   end
33
34   it 'should accept hashes and return uppercase' do
35     expect(
36         scope.function_upcase([{'test' => %w(this that and other thing)}])
37     ).to eq({'TEST' => %w(THIS THAT AND OTHER THING)})
38   end
39
40   if :test.respond_to?(:upcase)
41     it 'should accept hashes of symbols' do
42       expect(
43           scope.function_upcase([{:test => [:this, :that, :other]}])
44       ).to eq({:TEST => [:THIS, :THAT, :OTHER]})
45     end
46     it 'should return upcase symbol' do
47       expect(
48           scope.function_upcase([:test])
49       ).to eq(:TEST)
50     end
51     it 'should return mixed objects in upcease' do
52       expect(
53           scope.function_upcase([[:test, 'woot']])
54       ).to eq([:TEST, 'WOOT'])
55
56     end
57   end
58 end