Skip to content

Commit 2a22428

Browse files
committed
restoring several spec files to 1.9.0
1 parent ea3fe9d commit 2a22428

File tree

4 files changed

+75
-107
lines changed

4 files changed

+75
-107
lines changed

.rubocop_todo.yml

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2025-06-05 11:55:03 UTC using RuboCop version 1.70.0.
3+
# on 2025-06-05 12:20:38 UTC using RuboCop version 1.70.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -36,11 +36,12 @@ Layout/HashAlignment:
3636
Exclude:
3737
- 'spec/puppet/resource_api_spec.rb'
3838

39-
# Offense count: 2
39+
# Offense count: 4
4040
# This cop supports safe autocorrection (--autocorrect).
4141
Layout/HeredocIndentation:
4242
Exclude:
4343
- 'lib/puppet/resource_api.rb'
44+
- 'spec/acceptance/device_spec.rb'
4445

4546
# Offense count: 4
4647
# This cop supports safe autocorrection (--autocorrect).
@@ -57,21 +58,23 @@ Layout/LineContinuationLeadingSpace:
5758
Exclude:
5859
- 'lib/puppet/resource_api.rb'
5960

60-
# Offense count: 1
61+
# Offense count: 9
6162
# This cop supports safe autocorrection (--autocorrect).
6263
# Configuration parameters: EnforcedStyle.
6364
# SupportedStyles: space, no_space
6465
Layout/LineContinuationSpacing:
6566
Exclude:
6667
- 'lib/puppet/resource_api.rb'
68+
- 'spec/acceptance/device_spec.rb'
6769

68-
# Offense count: 1
70+
# Offense count: 3
6971
# This cop supports safe autocorrection (--autocorrect).
7072
# Configuration parameters: EnforcedStyle, IndentationWidth.
7173
# SupportedStyles: aligned, indented
7274
Layout/LineEndStringConcatenationIndentation:
7375
Exclude:
7476
- 'lib/puppet/resource_api.rb'
77+
- 'spec/acceptance/device_spec.rb'
7578

7679
# Offense count: 1
7780
# This cop supports safe autocorrection (--autocorrect).
@@ -134,7 +137,15 @@ RSpec/BeNil:
134137
Exclude:
135138
- 'spec/puppet/resource_api_spec.rb'
136139

137-
# Offense count: 25
140+
# Offense count: 1
141+
RSpec/BeforeAfterAll:
142+
Exclude:
143+
- 'spec/spec_helper.rb'
144+
- 'spec/rails_helper.rb'
145+
- 'spec/support/**/*.rb'
146+
- 'spec/acceptance/device_spec.rb'
147+
148+
# Offense count: 24
138149
# Configuration parameters: IgnoredMetadata.
139150
RSpec/DescribeClass:
140151
Enabled: false
@@ -152,13 +163,14 @@ RSpec/EmptyLineAfterExample:
152163
RSpec/ExampleLength:
153164
Max: 16
154165

155-
# Offense count: 46
166+
# Offense count: 48
156167
# This cop supports safe autocorrection (--autocorrect).
157168
# Configuration parameters: EnforcedStyle.
158169
# SupportedStyles: implicit, each, example
159170
RSpec/HookArgument:
160171
Exclude:
161172
- 'spec/acceptance/composite_namevar_spec.rb'
173+
- 'spec/acceptance/device_spec.rb'
162174
- 'spec/puppet/resource_api_spec.rb'
163175

164176
# Offense count: 1
@@ -182,7 +194,7 @@ RSpec/LeakyConstantDeclaration:
182194
- 'spec/puppet/resource_api/transport_spec.rb'
183195
- 'spec/puppet/resource_api_spec.rb'
184196

185-
# Offense count: 163
197+
# Offense count: 157
186198
RSpec/MultipleExpectations:
187199
Max: 11
188200

@@ -286,14 +298,16 @@ Style/RedundantRegexpEscape:
286298
Exclude:
287299
- 'spec/acceptance/composite_namevar_spec.rb'
288300

289-
# Offense count: 78
301+
# Offense count: 92
290302
# This cop supports safe autocorrection (--autocorrect).
291303
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
292304
# SupportedStyles: slashes, percent_r, mixed
293305
Style/RegexpLiteral:
294306
Exclude:
295307
- 'lib/puppet/resource_api.rb'
296308
- 'spec/acceptance/composite_namevar_spec.rb'
309+
- 'spec/acceptance/device_spec.rb'
310+
- 'spec/acceptance/simple_get_filter_spec.rb'
297311
- 'spec/puppet/resource_api_spec.rb'
298312

299313
# Offense count: 1
@@ -309,13 +323,14 @@ Style/SoleNestedConditional:
309323
Exclude:
310324
- 'lib/puppet/resource_api.rb'
311325

312-
# Offense count: 3
326+
# Offense count: 4
313327
# This cop supports unsafe autocorrection (--autocorrect-all).
314328
# Configuration parameters: Mode.
315329
Style/StringConcatenation:
316330
Exclude:
317331
- 'lib/puppet/resource_api.rb'
318332
- 'spec/acceptance/composite_namevar_spec.rb'
333+
- 'spec/acceptance/device_spec.rb'
319334

320335
# Offense count: 1
321336
# This cop supports safe autocorrection (--autocorrect).

spec/acceptance/device_spec.rb

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@
88
RSpec.describe 'exercising a device provider' do
99
let(:common_args) { '--verbose --trace --strict=error --modulepath spec/fixtures' }
1010
let(:default_type_values) do
11-
'string="meep" boolean=true integer=15 float=1.23 ensure=present variant_pattern=AE321EEF ' \
12-
'url="http://www.puppet.com" boolean_param=false integer_param=99 float_param=3.21 ' \
13-
'ensure_param=present variant_pattern_param=0xAE321EEF url_param="https://www.google.com"'
11+
'string="meep" boolean=true integer=15 float=1.23 ensure=present variant_pattern=AE321EEF '\
12+
'url="http://www.puppet.com" boolean_param=false integer_param=99 float_param=3.21 '\
13+
'ensure_param=present variant_pattern_param=0xAE321EEF url_param="https://www.google.com"'
14+
end
15+
16+
before(:all) do
17+
if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.3.0') && Gem::Version.new(Puppet::PUPPETVERSION) < Gem::Version.new('5.4.0')
18+
# work around https://tickets.puppetlabs.com/browse/PUP-8632 and https://tickets.puppetlabs.com/browse/PUP-9047
19+
FileUtils.mkdir_p(File.expand_path('~/.puppetlabs/opt/puppet/cache/devices/the_node/state'))
20+
end
1421
end
1522

1623
describe 'using `puppet resource`' do
@@ -25,11 +32,11 @@
2532

2633
it 'deals with canonicalized resources correctly' do
2734
stdout_str, status = Open3.capture2e("puppet resource #{common_args} device_provider wibble ensure=present #{default_type_values}")
28-
stdmatch = 'Error: /Device_provider\[wibble\]: Could not evaluate: device_provider\[wibble\]#get has not provided canonicalized values.\n' \
29-
'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n' \
35+
stdmatch = 'Error: /Device_provider\[wibble\]: Could not evaluate: device_provider\[wibble\]#get has not provided canonicalized values.\n'\
36+
'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n'\
3037
'Canonicalized values: \{:name=>"wibble", :ensure=>"present", :string=>"changed", :string_ro=>"fixed"\}'
31-
expect(stdout_str).to match(/#{stdmatch}/)
32-
expect(status).not_to be_success
38+
expect(stdout_str).to match %r{#{stdmatch}}
39+
expect(status).to be_success
3340
end
3441
end
3542

@@ -38,10 +45,10 @@
3845

3946
it 'deals with canonicalized resources correctly' do
4047
stdout_str, status = Open3.capture2e("puppet resource #{common_args} device_provider wibble ensure=present #{default_type_values}")
41-
stdmatch = 'Warning: device_provider\[wibble\]#get has not provided canonicalized values.\n' \
42-
'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n' \
48+
stdmatch = 'Warning: device_provider\[wibble\]#get has not provided canonicalized values.\n'\
49+
'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n'\
4350
'Canonicalized values: \{:name=>"wibble", :ensure=>"present", :string=>"changed", :string_ro=>"fixed"\}'
44-
expect(stdout_str).to match(/#{stdmatch}/)
51+
expect(stdout_str).to match %r{#{stdmatch}}
4552
expect(status).to be_success
4653
end
4754
end
@@ -54,7 +61,7 @@
5461
expected_values = 'device_provider { \'wibble\': \n\s+ensure => \'present\',\n\s+string => \'sample\',\n\#\s+string_ro => \'fixed\', # Read Only\n string_param => \'default value\',\n}'
5562
fiddle_deprecate_msg = "DL is deprecated, please use Fiddle\n"
5663
win32_deprecate_msg = ".*Struct layout is already defined for class Windows::ServiceStructs::SERVICE_STATUS_PROCESS.*\n"
57-
expect(stdout_str.strip).to match(/\A(#{fiddle_deprecate_msg}|#{win32_deprecate_msg})?#{expected_values}\Z/)
64+
expect(stdout_str.strip).to match %r{\A(#{fiddle_deprecate_msg}|#{win32_deprecate_msg})?#{expected_values}\Z}
5865
expect(status).to eq 0
5966
end
6067

@@ -63,48 +70,53 @@
6370
expected_values = 'device_provider: |2\n\s+wibble:\n\s+ensure: :present\n\s+string: sample\n\s+string_ro: fixed\n\s+string_param: default value'
6471
fiddle_deprecate_msg = "DL is deprecated, please use Fiddle\n"
6572
win32_deprecate_msg = ".*Struct layout is already defined for class Windows::ServiceStructs::SERVICE_STATUS_PROCESS.*\n"
66-
expect(stdout_str.strip).to match(/\A(#{fiddle_deprecate_msg}|#{win32_deprecate_msg})?#{expected_values}\Z/)
73+
expect(stdout_str.strip).to match %r{\A(#{fiddle_deprecate_msg}|#{win32_deprecate_msg})?#{expected_values}\Z}
6774
expect(status).to eq 0
6875
end
6976

7077
it 'deals with canonicalized resources correctly' do
7178
stdout_str, status = Open3.capture2e("puppet resource #{common_args} device_provider wibble ensure=present #{default_type_values}")
7279
stdmatch = 'Notice: /Device_provider\[wibble\]/string: string changed \'sample\' to \'changed\''
73-
expect(stdout_str).to match(/#{stdmatch}/)
80+
expect(stdout_str).to match %r{#{stdmatch}}
7481
expect(status).to be_success
7582
end
7683
end
7784
end
7885

7986
describe 'using `puppet device`' do
80-
let(:common_args) { "#{super()} --target the_node" }
87+
let(:common_args) { super() + ' --target the_node' }
8188
let(:device_conf) { Tempfile.new('device.conf') }
8289
let(:device_conf_content) do
83-
<<~DEVICE_CONF
84-
[the_node]
85-
type test_device
86-
url file://#{device_credentials.path}
87-
DEVICE_CONF
90+
<<DEVICE_CONF
91+
[the_node]
92+
type test_device
93+
url file://#{device_credentials.path}
94+
DEVICE_CONF
8895
end
8996
let(:device_credentials) { Tempfile.new('credentials.txt') }
9097
let(:device_credentials_content) do
91-
<<~DEVICE_CREDS
92-
{
93-
username: foo
94-
secret: wibble
95-
}
96-
DEVICE_CREDS
98+
<<DEVICE_CREDS
99+
{
100+
username: foo
101+
secret: wibble
102+
}
103+
DEVICE_CREDS
104+
end
105+
106+
def is_device_apply_supported?
107+
Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('5.3.6') && Gem::Version.new(Puppet::PUPPETVERSION) != Gem::Version.new('5.4.0')
97108
end
98109

99-
before do
110+
before(:each) do
111+
skip "No device --apply in puppet before v5.3.6 nor in v5.4.0 (v#{Puppet::PUPPETVERSION} is installed)" unless is_device_apply_supported?
100112
device_conf.write(device_conf_content)
101113
device_conf.close
102114

103115
device_credentials.write(device_credentials_content)
104116
device_credentials.close
105117
end
106118

107-
after do
119+
after(:each) do
108120
device_conf.unlink
109121
device_credentials.unlink
110122
end
@@ -122,9 +134,9 @@
122134
f.close
123135

124136
stdout_str, _status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
125-
expect(stdout_str).to match(/Compiled catalog for the_node/)
126-
expect(stdout_str).to match(/defined 'message' as 'foo'/)
127-
expect(stdout_str).not_to match(/Error:/)
137+
expect(stdout_str).to match %r{Compiled catalog for the_node}
138+
expect(stdout_str).to match %r{defined 'message' as 'foo'}
139+
expect(stdout_str).not_to match %r{Error:}
128140
end
129141
end
130142

@@ -134,7 +146,7 @@
134146
f.close
135147

136148
stdout_str, status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
137-
expect(stdout_str).not_to match(/Error:/)
149+
expect(stdout_str).not_to match %r{Error:}
138150
expect(status).to eq 0
139151
end
140152
end
@@ -143,13 +155,13 @@
143155
it 'applies the catalog successfully' do
144156
Tempfile.create('fact_set') do |f|
145157
f.write 'device_provider{ "foo":' \
146-
'ensure => "present", boolean => true, integer => 15, float => 1.23, variant_pattern => "0x1234ABCD", ' \
147-
'url => "http://www.google.com", boolean_param => false, integer_param => 99, float_param => 3.21, ' \
148-
'ensure_param => "present", variant_pattern_param => "9A2222ED", url_param => "http://www.puppet.com" }'
158+
'ensure => "present", boolean => true, integer => 15, float => 1.23, variant_pattern => "0x1234ABCD", '\
159+
'url => "http://www.google.com", boolean_param => false, integer_param => 99, float_param => 3.21, '\
160+
'ensure_param => "present", variant_pattern_param => "9A2222ED", url_param => "http://www.puppet.com" }'
149161
f.close
150162

151163
stdout_str, _status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")
152-
expect(stdout_str).not_to match(/Error:/)
164+
expect(stdout_str).not_to match %r{Error:}
153165
end
154166
end
155167
end

spec/acceptance/get_calls_spec.rb

Lines changed: 0 additions & 59 deletions
This file was deleted.

spec/acceptance/simple_get_filter_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
it 'does not receive names array' do
1414
stdout_str, status = Open3.capture2e("puppet resource #{common_args} test_simple_get_filter")
1515

16-
expect(stdout_str.strip).to match(/^test_simple_get_filter \{ 'wibble'/)
17-
expect(stdout_str.strip).to match(/^test_simple_get_filter \{ 'bar'/)
16+
expect(stdout_str.strip).to match %r{^test_simple_get_filter \{ 'wibble'}
17+
expect(stdout_str.strip).to match %r{^test_simple_get_filter \{ 'bar'}
1818
expect(status).to eq 0
1919
end
2020
end
@@ -23,7 +23,7 @@
2323
it '`puppet resource` uses `instances` and does the filtering' do
2424
stdout_str, status = Open3.capture2e("puppet resource #{common_args} test_simple_get_filter wibble")
2525

26-
expect(stdout_str.strip).to match(/test_string\s*=>\s*'wibble default'/)
26+
expect(stdout_str.strip).to match %r{test_string\s*=>\s*'wibble default'}
2727
expect(status).to eq 0
2828
end
2929
end
@@ -32,7 +32,7 @@
3232
it 'the `retrieve` function does the lookup' do
3333
stdout_str, status = Open3.capture2e("puppet resource #{common_args} test_simple_get_filter foo")
3434

35-
expect(stdout_str.strip).to match(/test_string\s*=>\s*'foo found'/)
35+
expect(stdout_str.strip).to match %r{test_string\s*=>\s*'foo found'}
3636
expect(status).to eq 0
3737
end
3838
end

0 commit comments

Comments
 (0)