1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper_acceptance'
4 describe 'num2bool function' do
6 it 'bools positive numbers and numeric strings as true' do
14 notice(inline_template('a is <%= @ao.inspect %>'))
15 notice(inline_template('b is <%= @bo.inspect %>'))
16 notice(inline_template('c is <%= @co.inspect %>'))
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/)
25 it 'bools negative numbers as false' do
33 notice(inline_template('a is <%= @ao.inspect %>'))
34 notice(inline_template('b is <%= @bo.inspect %>'))
35 notice(inline_template('c is <%= @co.inspect %>'))
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/)
46 it 'fails on words' do
50 notice(inline_template('a is <%= @ao.inspect %>'))
52 expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/not look like a number/)
55 it 'fails on numberwords' do
59 notice(inline_template('b is <%= @bo.inspect %>'))
61 expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/not look like a number/)
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?"
71 notice(inline_template('c is <%= @co.inspect %>'))
73 expect(apply_manifest(ppc :expect_failures => true).stderr).to match(/Unable to parse/)