X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Fspec%2Facceptance%2Fnum2bool_spec.rb;h=d95cb934de2d59859fe8ab5dcaa06bec7436efb7;hb=6f656bd4265e3dab13b9af2bf96e9044322e9d8f;hp=1d99ba02514daf5d5342d29502f3630663ec740f;hpb=ad88f67c13ae0f1a08936dad643f1e3509ab5f40;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/spec/acceptance/num2bool_spec.rb b/3rdparty/modules/stdlib/spec/acceptance/num2bool_spec.rb old mode 100755 new mode 100644 index 1d99ba025..d95cb934d --- a/3rdparty/modules/stdlib/spec/acceptance/num2bool_spec.rb +++ b/3rdparty/modules/stdlib/spec/acceptance/num2bool_spec.rb @@ -1,10 +1,8 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'num2bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do +describe 'num2bool function' do describe 'success' do - it 'bools positive numbers and numeric strings as true' do - pp = <<-EOS + pp1 = <<-DOC $a = 1 $b = "1" $c = "50" @@ -14,16 +12,17 @@ describe 'num2bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('op notice(inline_template('a is <%= @ao.inspect %>')) notice(inline_template('b is <%= @bo.inspect %>')) notice(inline_template('c is <%= @co.inspect %>')) - EOS - - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/a is true/) - expect(r.stdout).to match(/b is true/) - expect(r.stdout).to match(/c is true/) + DOC + regex_array_true = [%r{a is true}, %r{b is true}, %r{c is true}] + it 'bools positive numbers and numeric strings as true' do + apply_manifest(pp1, :catch_failures => true) do |r| + regex_array_true.each do |i| + expect(r.stdout).to match(i) + end end end - it 'bools negative numbers as false' do - pp = <<-EOS + + pp2 = <<-DOC $a = 0 $b = -0.1 $c = ["-50","1"] @@ -33,44 +32,45 @@ describe 'num2bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('op notice(inline_template('a is <%= @ao.inspect %>')) notice(inline_template('b is <%= @bo.inspect %>')) notice(inline_template('c is <%= @co.inspect %>')) - EOS - - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/a is false/) - expect(r.stdout).to match(/b is false/) - expect(r.stdout).to match(/c is false/) + DOC + regex_array_false = [%r{a is false}, %r{b is false}, %r{c is false}] + it 'bools negative numbers as false' do + apply_manifest(pp2, :catch_failures => true) do |r| + regex_array_false.each do |i| + expect(r.stdout).to match(i) + end end end end + describe 'failure' do - it 'fails on words' do - pp = <<-EOS + pp3 = <<-DOC $a = "a" $ao = num2bool($a) notice(inline_template('a is <%= @ao.inspect %>')) - EOS - expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/not look like a number/) + DOC + it 'fails on words' do + expect(apply_manifest(pp3, :expect_failures => true).stderr).to match(%r{not look like a number}) end - it 'fails on numberwords' do - pp = <<-EOS + pp4 = <<-DOC $b = "1b" $bo = num2bool($b) notice(inline_template('b is <%= @bo.inspect %>')) - EOS - expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/not look like a number/) - + DOC + it 'fails on numberwords' do + expect(apply_manifest(pp4, :expect_failures => true).stderr).to match(%r{not look like a number}) end - it 'fails on non-numeric/strings' do - pending "The function will call .to_s.to_i on anything not a Numeric or - String, and results in 0. Is this intended?" - pp = <<-EOS + pp5 = <<-DOC # rubocop:disable Lint/UselessAssignment $c = {"c" => "-50"} $co = num2bool($c) notice(inline_template('c is <%= @co.inspect %>')) - EOS - expect(apply_manifest(ppc :expect_failures => true).stderr).to match(/Unable to parse/) + DOC + it 'fails on non-numeric/strings' do + pending "The function will call .to_s.to_i on anything not a Numeric or + String, and results in 0. Is this intended?" + expect(apply_manifest(pp5(:expect_failures => true)).stderr).to match(%r{Unable to parse}) end end end