]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/acceptance/num2bool_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / acceptance / num2bool_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper_acceptance'
3
4 describe 'num2bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
5   describe 'success' do
6     it 'bools positive numbers and numeric strings as true' do
7       pp = <<-EOS
8       $a = 1
9       $b = "1"
10       $c = "50"
11       $ao = num2bool($a)
12       $bo = num2bool($b)
13       $co = num2bool($c)
14       notice(inline_template('a is <%= @ao.inspect %>'))
15       notice(inline_template('b is <%= @bo.inspect %>'))
16       notice(inline_template('c is <%= @co.inspect %>'))
17       EOS
18
19       apply_manifest(pp, :catch_failures => true) do |r|
20         expect(r.stdout).to match(/a is true/)
21         expect(r.stdout).to match(/b is true/)
22         expect(r.stdout).to match(/c is true/)
23       end
24     end
25     it 'bools negative numbers as false' do
26       pp = <<-EOS
27       $a = 0
28       $b = -0.1
29       $c = ["-50","1"]
30       $ao = num2bool($a)
31       $bo = num2bool($b)
32       $co = num2bool($c)
33       notice(inline_template('a is <%= @ao.inspect %>'))
34       notice(inline_template('b is <%= @bo.inspect %>'))
35       notice(inline_template('c is <%= @co.inspect %>'))
36       EOS
37
38       apply_manifest(pp, :catch_failures => true) do |r|
39         expect(r.stdout).to match(/a is false/)
40         expect(r.stdout).to match(/b is false/)
41         expect(r.stdout).to match(/c is false/)
42       end
43     end
44   end
45   describe 'failure' do
46     it 'fails on words' do
47       pp = <<-EOS
48       $a = "a"
49       $ao = num2bool($a)
50       notice(inline_template('a is <%= @ao.inspect %>'))
51       EOS
52       expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/not look like a number/)
53     end
54
55     it 'fails on numberwords' do
56       pp = <<-EOS
57       $b = "1b"
58       $bo = num2bool($b)
59       notice(inline_template('b is <%= @bo.inspect %>'))
60       EOS
61       expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/not look like a number/)
62
63     end
64
65     it 'fails on non-numeric/strings' do
66       pending "The function will call .to_s.to_i on anything not a Numeric or
67       String, and results in 0. Is this intended?"
68       pp = <<-EOS
69       $c = {"c" => "-50"}
70       $co = num2bool($c)
71       notice(inline_template('c is <%= @co.inspect %>'))
72       EOS
73       expect(apply_manifest(ppc :expect_failures => true).stderr).to match(/Unable to parse/)
74     end
75   end
76 end