File: hash_spec.rb

package info (click to toggle)
ruby-rspec-puppet 4.0.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,444 kB
  • sloc: ruby: 6,377; makefile: 6
file content (68 lines) | stat: -rw-r--r-- 1,502 bytes parent folder | download
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true

require 'spec_helper'

describe 'structured_data' do
  describe 'with a single level hash of strings' do
    let(:params) do
      { 'data' => { 'foo' => 'bar', 'baz' => 'quux' } }
    end

    it {
      expect(subject).to contain_structured_data__def('thing').with(
        { 'data' => { 'foo' => 'bar', 'baz' => 'quux' } }
      )
    }
  end

  describe 'with integers as keys' do
    let(:params) do
      { 'data' => { 1 => 'uno', 2 => 'dos' } }
    end

    it {
      expect(subject).to contain_structured_data__def('thing').with(
        { 'data' => { 1 => 'uno', 2 => 'dos' } }
      )
    }
  end

  describe 'with integers as values' do
    let(:params) do
      { 'data' => { 'first' => 1, 'second' => 2 } }
    end

    it {
      expect(subject).to contain_structured_data__def('thing').with(
        { 'data' => { 'first' => 1, 'second' => 2 } }
      )
    }
  end

  describe 'with nested hashes' do
    # the key "sec.ond" needs quoting, otherwise it would be a syntax error in the manifest
    let(:params) do
      { 'data' => {
        'first' => 1,
        'sec.ond' => 2,
        'third' => {
          'alpha' => 'a',
          'beta' => 'b'
        }
      } }
    end

    it {
      expect(subject).to contain_structured_data__def('thing').with(
        { 'data' => {
          'first' => 1,
          'sec.ond' => 2,
          'third' => {
            'alpha' => 'a',
            'beta' => 'b'
          }
        } }
      )
    }
  end
end