1 #! /usr/bin/env ruby -S rspec
4 describe "the bool2httpd function" do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 expect(Puppet::Parser::Functions.function("bool2httpd")).to eq("function_bool2httpd")
11 it "should raise a ParseError if there is less than 1 arguments" do
12 expect { scope.function_bool2httpd([]) }.to( raise_error(Puppet::ParseError))
15 it "should convert true to 'On'" do
16 result = scope.function_bool2httpd([true])
17 expect(result).to(eq('On'))
20 it "should convert true to a string" do
21 result = scope.function_bool2httpd([true])
22 expect(result.class).to(eq(String))
25 it "should convert false to 'Off'" do
26 result = scope.function_bool2httpd([false])
27 expect(result).to(eq('Off'))
30 it "should convert false to a string" do
31 result = scope.function_bool2httpd([false])
32 expect(result.class).to(eq(String))
35 it "should accept (and return) any string" do
36 result = scope.function_bool2httpd(["mail"])
37 expect(result).to(eq('mail'))
40 it "should accept a nil value (and return Off)" do
41 result = scope.function_bool2httpd([nil])
42 expect(result).to(eq('Off'))
45 it "should accept an undef value (and return 'Off')" do
46 result = scope.function_bool2httpd([:undef])
47 expect(result).to(eq('Off'))
50 it "should return a default value on non-matches" do
51 result = scope.function_bool2httpd(['foo'])
52 expect(result).to(eq('foo'))