|
10 | 10 | describe 'using `puppet resource`' do |
11 | 11 | it 'is returns the values correctly' do |
12 | 12 | stdout_str, status = Open3.capture2e("puppet resource #{common_args} composite_namevar") |
13 | | - expect(stdout_str.strip).to match(/^composite_namevar/) |
14 | | - expect(stdout_str.strip).to match(/Looking for nil/) |
| 13 | + expect(stdout_str.strip).to match %r{^composite_namevar} |
| 14 | + expect(stdout_str.strip).to match %r{Looking for \[\]} |
15 | 15 | expect(status).to eq 0 |
16 | 16 | end |
17 | | - |
18 | 17 | it 'returns the required resource correctly' do |
19 | 18 | stdout_str, status = Open3.capture2e("puppet resource #{common_args} composite_namevar php-yum") |
20 | | - expect(stdout_str.strip).to match(/^composite_namevar \{ 'php-yum'/) |
21 | | - expect(stdout_str.strip).to match(/ensure\s*=> 'present'/) |
22 | | - expect(stdout_str.strip).to match(/package\s*=> 'php'/) |
23 | | - expect(stdout_str.strip).to match(/manager\s*=> 'yum'/) |
24 | | - expect(stdout_str.strip).to match(/Looking for nil/) |
| 19 | + expect(stdout_str.strip).to match %r{^composite_namevar \{ \'php-yum\'} |
| 20 | + expect(stdout_str.strip).to match %r{ensure\s*=> \'present\'} |
| 21 | + expect(stdout_str.strip).to match %r{package\s*=> \'php\'} |
| 22 | + expect(stdout_str.strip).to match %r{manager\s*=> \'yum\'} |
| 23 | + expect(stdout_str.strip).to match %r{Looking for \[\]} |
25 | 24 | expect(status.exitstatus).to eq 0 |
26 | 25 | end |
27 | | - |
28 | 26 | it 'throws error if title is not a matching title_pattern' do |
29 | 27 | stdout_str, status = Open3.capture2e("puppet resource #{common_args} composite_namevar php123 package=php manager=yum") |
30 | | - expect(stdout_str.strip).to match(/No set of title patterns matched the title "php123"/) |
31 | | - expect(stdout_str.strip).not_to match(/Looking for/) |
| 28 | + expect(stdout_str.strip).to match %r{No set of title patterns matched the title "php123"} |
| 29 | + expect(stdout_str.strip).not_to match %r{Looking for} |
32 | 30 | expect(status.exitstatus).to eq 1 |
33 | 31 | end |
34 | | - |
35 | 32 | it 'returns the match if alternative title_pattern matches' do |
36 | 33 | stdout_str, status = Open3.capture2e("puppet resource #{common_args} composite_namevar php/gem") |
37 | | - expect(stdout_str.strip).to match %r{^composite_namevar \{ 'php/gem'} |
38 | | - expect(stdout_str.strip).to match(/ensure\s*=> 'present'/) |
39 | | - # "Looking for" will return nil as puppet resource will have already fetched |
40 | | - # the resource in instances(): |
41 | | - expect(stdout_str.strip).to match(/Looking for nil/) |
| 34 | + expect(stdout_str.strip).to match %r{^composite_namevar \{ \'php/gem\'} |
| 35 | + expect(stdout_str.strip).to match %r{ensure\s*=> \'present\'} |
| 36 | + expect(stdout_str.strip).to match %r{Looking for \[\{:package=>"php", :manager=>"gem"\}\]} |
42 | 37 | expect(status.exitstatus).to eq 0 |
43 | 38 | end |
44 | | - |
45 | 39 | it 'properly identifies an absent resource if only the title is provided' do |
46 | 40 | stdout_str, status = Open3.capture2e("puppet resource #{common_args} composite_namevar php-wibble") |
47 | | - expect(stdout_str.strip).to match(/^composite_namevar \{ 'php-wibble'/) |
48 | | - expect(stdout_str.strip).to match(/ensure\s*=> 'absent'/) |
49 | | - expect(stdout_str.strip).to match(/Looking for \[\{:package=>"php", :manager=>"wibble"\}\]/) |
| 41 | + expect(stdout_str.strip).to match %r{^composite_namevar \{ \'php-wibble\'} |
| 42 | + expect(stdout_str.strip).to match %r{ensure\s*=> \'absent\'} |
| 43 | + expect(stdout_str.strip).to match %r{Looking for \[\{:package=>"php", :manager=>"wibble"\}\]} |
50 | 44 | expect(status.exitstatus).to eq 0 |
51 | 45 | end |
52 | | - |
53 | 46 | it 'creates a previously absent resource' do |
54 | 47 | stdout_str, status = Open3.capture2e("puppet resource #{common_args} composite_namevar php-wibble ensure='present'") |
55 | | - expect(stdout_str.strip).to match(/^composite_namevar \{ 'php-wibble'/) |
56 | | - expect(stdout_str.strip).to match(/ensure\s*=> 'present'/) |
57 | | - expect(stdout_str.strip).to match(/package\s*=> 'php'/) |
58 | | - expect(stdout_str.strip).to match(/manager\s*=> 'wibble'/) |
59 | | - expect(stdout_str.strip).to match(/Looking for \[\{:package=>"php", :manager=>"wibble"\}\]/) |
| 48 | + expect(stdout_str.strip).to match %r{^composite_namevar \{ \'php-wibble\'} |
| 49 | + expect(stdout_str.strip).to match %r{ensure\s*=> \'present\'} |
| 50 | + expect(stdout_str.strip).to match %r{package\s*=> \'php\'} |
| 51 | + expect(stdout_str.strip).to match %r{manager\s*=> \'wibble\'} |
| 52 | + expect(stdout_str.strip).to match %r{Looking for \[\{:package=>"php", :manager=>"wibble"\}\]} |
60 | 53 | expect(status.exitstatus).to eq 0 |
61 | 54 | end |
62 | | - |
63 | | - it 'removes an existing resource' do |
| 55 | + it 'will remove an existing resource' do |
64 | 56 | stdout_str, status = Open3.capture2e("puppet resource #{common_args} composite_namevar php-gem ensure=absent") |
65 | | - expect(stdout_str.strip).to match(/^composite_namevar \{ 'php-gem'/) |
66 | | - expect(stdout_str.strip).to match(/package\s*=> 'php'/) |
67 | | - expect(stdout_str.strip).to match(/manager\s*=> 'gem'/) |
68 | | - expect(stdout_str.strip).to match(/ensure\s*=> 'absent'/) |
69 | | - expect(stdout_str.strip).to match(/Looking for \[\{:package=>"php", :manager=>"gem"\}\]/) |
| 57 | + expect(stdout_str.strip).to match %r{^composite_namevar \{ \'php-gem\'} |
| 58 | + expect(stdout_str.strip).to match %r{package\s*=> \'php\'} |
| 59 | + expect(stdout_str.strip).to match %r{manager\s*=> \'gem\'} |
| 60 | + expect(stdout_str.strip).to match %r{ensure\s*=> \'absent\'} |
| 61 | + expect(stdout_str.strip).to match %r{Looking for \[\{:package=>"php", :manager=>"gem"\}\]} |
70 | 62 | expect(status.exitstatus).to eq 0 |
71 | 63 | end |
72 | 64 | end |
73 | 65 |
|
74 | 66 | describe 'using `puppet apply`' do |
75 | | - let(:common_args) { "#{super()} --detailed-exitcodes" } |
| 67 | + let(:common_args) { super() + ' --detailed-exitcodes' } |
76 | 68 |
|
77 | 69 | # run Open3.capture2e only once to get both output, and exitcode |
78 | 70 | # rubocop:disable RSpec/InstanceVariable |
79 | | - before do |
| 71 | + before(:each) do |
80 | 72 | Tempfile.create('acceptance') do |f| |
81 | 73 | f.write(manifest) |
82 | 74 | f.close |
|
88 | 80 | context 'when managing a present instance' do |
89 | 81 | let(:manifest) { 'composite_namevar { php-gem: }' } |
90 | 82 |
|
91 | | - it { expect(@stdout_str).to match(/Current State: \{:title=>"php-gem", :package=>"php", :manager=>"gem", :ensure=>"present", :value=>"b"\}/) } |
92 | | - it { expect(@stdout_str).to match(/Looking for \[\{:package=>"php", :manager=>"gem"\}\]/) } |
| 83 | + it { expect(@stdout_str).to match %r{Current State: \{:title=>"php-gem", :package=>"php", :manager=>"gem", :ensure=>"present", :value=>"b"\}} } |
| 84 | + it { expect(@stdout_str).to match %r{Looking for \[\{:package=>"php", :manager=>"gem"\}\]} } |
93 | 85 | it { expect(@status.exitstatus).to eq 0 } |
94 | 86 | end |
95 | 87 |
|
96 | 88 | context 'when managing an absent instance' do |
97 | 89 | let(:manifest) { 'composite_namevar { php-wibble: ensure=>\'absent\' }' } |
98 | 90 |
|
99 | | - it { expect(@stdout_str).to match(/Composite_namevar\[php-wibble\]: Nothing to manage: no ensure and the resource doesn't exist/) } |
100 | | - it { expect(@stdout_str).to match(/Looking for \[\{:package=>"php", :manager=>"wibble"\}\]/) } |
| 91 | + it { expect(@stdout_str).to match %r{Composite_namevar\[php-wibble\]: Nothing to manage: no ensure and the resource doesn't exist} } |
| 92 | + it { expect(@stdout_str).to match %r{Looking for \[\{:package=>"php", :manager=>"wibble"\}\]} } |
101 | 93 | it { expect(@status.exitstatus).to eq 0 } |
102 | 94 | end |
103 | 95 |
|
104 | 96 | context 'when creating a previously absent instance' do |
105 | 97 | let(:manifest) { 'composite_namevar { php-wibble: ensure=>\'present\' }' } |
106 | 98 |
|
107 | 99 | it { expect(@stdout_str).to match %r{Composite_namevar\[php-wibble\]/ensure: defined 'ensure' as 'present'} } |
108 | | - it { expect(@stdout_str).to match(/Looking for \[\{:package=>"php", :manager=>"wibble"\}\]/) } |
| 100 | + it { expect(@stdout_str).to match %r{Looking for \[\{:package=>"php", :manager=>"wibble"\}\]} } |
109 | 101 | it { expect(@status.exitstatus).to eq 2 } |
110 | 102 | end |
111 | 103 |
|
112 | 104 | context 'when removing a previously present instance' do |
113 | 105 | let(:manifest) { 'composite_namevar { php-yum: ensure=>\'absent\' }' } |
114 | 106 |
|
115 | 107 | it { expect(@stdout_str).to match %r{Composite_namevar\[php-yum\]/ensure: undefined 'ensure' from 'present'} } |
116 | | - it { expect(@stdout_str).to match(/Looking for \[\{:package=>"php", :manager=>"yum"\}\]/) } |
| 108 | + it { expect(@stdout_str).to match %r{Looking for \[\{:package=>"php", :manager=>"yum"\}\]} } |
117 | 109 | it { expect(@status.exitstatus).to eq 2 } |
118 | 110 | end |
119 | 111 |
|
120 | 112 | context 'when modifying an existing resource through an alternative title_pattern' do |
121 | 113 | let(:manifest) { 'composite_namevar { \'php/gem\': value=>\'c\' }' } |
122 | 114 |
|
123 | | - it { expect(@stdout_str).to match(/Current State: \{:title=>"php-gem", :package=>"php", :manager=>"gem", :ensure=>"present", :value=>"b"\}/) } |
124 | | - it { expect(@stdout_str).to match(/Target State: \{:package=>"php", :manager=>"gem", :value=>"c", :ensure=>"present"\}/) } |
125 | | - it { expect(@stdout_str).to match(/Looking for \[\{:package=>"php", :manager=>"gem"\}\]/) } |
| 115 | + it { expect(@stdout_str).to match %r{Current State: \{:title=>"php-gem", :package=>"php", :manager=>"gem", :ensure=>"present", :value=>"b"\}} } |
| 116 | + it { expect(@stdout_str).to match %r{Target State: \{:package=>"php", :manager=>"gem", :value=>"c", :ensure=>"present"\}} } |
| 117 | + it { expect(@stdout_str).to match %r{Looking for \[\{:package=>"php", :manager=>"gem"\}\]} } |
126 | 118 | it { expect(@status.exitstatus).to eq 2 } |
127 | 119 | end |
128 | 120 | end |
|
131 | 123 | context 'when managing a present instance' do |
132 | 124 | let(:manifest) { 'composite_namevar { "sometitle": package => "php", manager => "gem" }' } |
133 | 125 |
|
134 | | - it { expect(@stdout_str).to match(/Current State: \{:title=>"php-gem", :package=>"php", :manager=>"gem", :ensure=>"present", :value=>"b"\}/) } |
135 | | - it { expect(@stdout_str).to match(/Looking for \[\{:package=>"php", :manager=>"gem"\}\]/) } |
| 126 | + it { expect(@stdout_str).to match %r{Current State: \{:title=>"php-gem", :package=>"php", :manager=>"gem", :ensure=>"present", :value=>"b"\}} } |
| 127 | + it { expect(@stdout_str).to match %r{Looking for \[\{:package=>"php", :manager=>"gem"\}\]} } |
136 | 128 | it { expect(@status.exitstatus).to eq 0 } |
137 | 129 | end |
138 | 130 |
|
139 | 131 | context 'when managing an absent instance' do |
140 | 132 | let(:manifest) { 'composite_namevar { "sometitle": ensure => "absent", package => "php", manager => "wibble" }' } |
141 | 133 |
|
142 | | - it { expect(@stdout_str).to match(/Composite_namevar\[sometitle\]: Nothing to manage: no ensure and the resource doesn't exist/) } |
143 | | - it { expect(@stdout_str).to match(/Looking for \[\{:package=>"php", :manager=>"wibble"\}\]/) } |
| 134 | + it { expect(@stdout_str).to match %r{Composite_namevar\[sometitle\]: Nothing to manage: no ensure and the resource doesn't exist} } |
| 135 | + it { expect(@stdout_str).to match %r{Looking for \[\{:package=>"php", :manager=>"wibble"\}\]} } |
144 | 136 | it { expect(@status.exitstatus).to eq 0 } |
145 | 137 | end |
146 | 138 |
|
147 | 139 | context 'when creating a previously absent instance' do |
148 | 140 | let(:manifest) { 'composite_namevar { "sometitle": ensure => "present", package => "php", manager => "wibble" }' } |
149 | 141 |
|
150 | 142 | it { expect(@stdout_str).to match %r{Composite_namevar\[sometitle\]/ensure: defined 'ensure' as 'present'} } |
151 | | - it { expect(@stdout_str).to match(/Looking for \[\{:package=>"php", :manager=>"wibble"\}\]/) } |
| 143 | + it { expect(@stdout_str).to match %r{Looking for \[\{:package=>"php", :manager=>"wibble"\}\]} } |
152 | 144 | it { expect(@status.exitstatus).to eq 2 } |
153 | 145 | end |
154 | 146 |
|
155 | 147 | context 'when removing a previously present instance' do |
156 | 148 | let(:manifest) { 'composite_namevar { "sometitle": ensure => "absent", package => "php", manager => "yum" }' } |
157 | 149 |
|
158 | 150 | it { expect(@stdout_str).to match %r{Composite_namevar\[sometitle\]/ensure: undefined 'ensure' from 'present'} } |
159 | | - it { expect(@stdout_str).to match(/Looking for \[\{:package=>"php", :manager=>"yum"\}\]/) } |
| 151 | + it { expect(@stdout_str).to match %r{Looking for \[\{:package=>"php", :manager=>"yum"\}\]} } |
160 | 152 | it { expect(@status.exitstatus).to eq 2 } |
161 | 153 | end |
162 | 154 | end |
|
0 commit comments