File: round_spec.rb

package info (click to toggle)
puppet-agent 7.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 19,092 kB
  • sloc: ruby: 245,074; sh: 456; makefile: 38; xml: 33
file content (41 lines) | stat: -rw-r--r-- 1,044 bytes parent folder | download | duplicates (2)
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
36
37
38
39
40
41
require 'spec_helper'

require 'puppet_spec/compiler'
require 'matchers/resource'

describe 'the round function' do
  include PuppetSpec::Compiler
  include Matchers::Resource

  context 'for an integer' do
    [ 0, 1, -1].each do |x|
      it "called as round(#{x}) results in the same value" do
        expect(compile_to_catalog("notify { String( round(#{x}) == #{x}): }")).to have_resource("Notify[true]")
      end
    end
  end

  context 'for a float' do
    {
      0.0 => 0,
      1.1 => 1,
      -1.1 => -1,
      2.9 => 3,
      2.1 => 2,
      2.49 => 2,
      2.50 => 3,
      -2.9 => -3,
    }.each_pair do |x, expected|
      it "called as round(#{x}) results in #{expected}" do
        expect(compile_to_catalog("notify { String( round(#{x}) == #{expected}): }")).to have_resource("Notify[true]")
      end
    end
  end

  [[1,2,3], {'a' => 10}, '"42"'].each do |x|
    it "errors for a value of class #{x.class}" do
      expect{ compile_to_catalog("round(#{x})") }.to raise_error(/expects a Numeric value/)
    end
  end

end