1 require 'spec_helper_acceptance'
3 describe 'num2bool function' do
12 notice(inline_template('a is <%= @ao.inspect %>'))
13 notice(inline_template('b is <%= @bo.inspect %>'))
14 notice(inline_template('c is <%= @co.inspect %>'))
16 regex_array_true = [%r{a is true}, %r{b is true}, %r{c is true}]
17 it 'bools positive numbers and numeric strings as true' do
18 apply_manifest(pp1, :catch_failures => true) do |r|
19 regex_array_true.each do |i|
20 expect(r.stdout).to match(i)
32 notice(inline_template('a is <%= @ao.inspect %>'))
33 notice(inline_template('b is <%= @bo.inspect %>'))
34 notice(inline_template('c is <%= @co.inspect %>'))
36 regex_array_false = [%r{a is false}, %r{b is false}, %r{c is false}]
37 it 'bools negative numbers as false' do
38 apply_manifest(pp2, :catch_failures => true) do |r|
39 regex_array_false.each do |i|
40 expect(r.stdout).to match(i)
50 notice(inline_template('a is <%= @ao.inspect %>'))
52 it 'fails on words' do
53 expect(apply_manifest(pp3, :expect_failures => true).stderr).to match(%r{not look like a number})
59 notice(inline_template('b is <%= @bo.inspect %>'))
61 it 'fails on numberwords' do
62 expect(apply_manifest(pp4, :expect_failures => true).stderr).to match(%r{not look like a number})
65 pp5 = <<-DOC # rubocop:disable Lint/UselessAssignment
68 notice(inline_template('c is <%= @co.inspect %>'))
70 it 'fails on non-numeric/strings' do
71 pending "The function will call .to_s.to_i on anything not a Numeric or
72 String, and results in 0. Is this intended?"
73 expect(apply_manifest(pp5(:expect_failures => true)).stderr).to match(%r{Unable to parse})