summaryrefslogtreecommitdiff
path: root/spec/unit/parameter/boolean_spec.rb
blob: 505bc561fb0ad0d556a5ac52646d40793b6b6308 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#! /usr/bin/env ruby
require 'spec_helper'
require 'puppet'
require 'puppet/parameter/boolean'

describe Puppet::Parameter::Boolean do
  let (:resource) { mock('resource') }
  describe "after initvars" do
    before { described_class.initvars }
    it "should have the correct value_collection" do
      described_class.value_collection.values.sort.should ==
          [:true, :false, :yes, :no].sort
    end
  end

  describe "instances" do
    subject { described_class.new(:resource => resource) }

    [ true, :true, 'true', :yes, 'yes', 'TrUe', 'yEs' ].each do |arg|
      it "should munge #{arg.inspect} as true" do
        subject.munge(arg).should == true
      end
    end
    [ false, :false, 'false', :no, 'no', 'FaLSE', 'nO' ].each do |arg|
      it "should munge #{arg.inspect} as false" do
        subject.munge(arg).should == false
      end
    end
    [ nil, :undef, 'undef', '0', 0, '1', 1, 9284 ].each do |arg|
      it "should fail to munge #{arg.inspect}" do
        expect { subject.munge(arg) }.to raise_error Puppet::Error
      end
    end
  end
end